none
Linq - Dump Object Formatting Control RRS feed

  • Question

  • Hi

    (Linq Novice here)

    When use object.Dump(10) and say one of the structures was

            public class GroupMembership
            {
                public string GroupName { get; set; }
                public string GroupSid { get; set; }
                public List<VersionControlPermission> VersionControlPermissions { get; set; }
            }

    How can i override the formatting ? e.g. The GroupSid, i don't want this printed ?
    The List, instead of every item i just want to check if the List has just "read" only permissions and print "Read" or "Read / Write". The list can have up to 10 entries, i want to simplify the output.

    Or do i need to have a parallel class which i use in the object.dump ? e,.g.
    Get GroupMembership, then set values in parallel GroupMembershipDump

            public class GroupMembershipDump
            {
                public string GroupName { get; set; }
                public string GroupMemberPerm { get; set; }
            }

    Then add this object into the main object, instead of the original...

    Thanks in advance

    Thursday, January 24, 2013 3:59 AM

Answers

  • Hi Greg,

    The extension method Dump() isn't part of the .NET Framework. I couldn't locate source code for it but I believe I get the idea of what it does. You have a few possible options:

    1. If you don't have the source code for the Dump() method to be able to modify it, or don't want to bother then simply copy the data into another class with the structure you want, as you've stated.
    2. Create an attribute to flag members you don't want dumped (eg. DumpIgnoreAttribute), similar to the XmlIgnoreAttribute, then implement the necessary logic in the Dump() method to ignore those members flagged with the attribute.
    3. Implement an "IDumpable" or similar interface with a "string GetDump()" method, then add the necessary logic to the Dump() method to check if the object to be dumped implements the interface and then return the output of the GetDump() method.

    Regards,

    Tyler

    Sunday, January 27, 2013 1:58 AM

All replies

  • Hi,

    I am not sure if the object.Dump(10) is this: http://blogs.msdn.com/b/ericwhite/archive/2008/08/14/object-dumper-an-invaluable-tool-for-writing-code-in-the-functional-programming-style.aspx

    If so, I think the way this method output is depend on this method. Thus, I think if you want to change the default way, you have to change the object structure.

    Or the object.Dump(10) is related to C++ native?

    Friday, January 25, 2013 7:35 AM
  • See the sample code at the end of http://geekswithblogs.net/TarunArora/archive/2011/09/30/tfs-sdk-get-groups-users-permissions-using-tfs-api-with.aspx

    I don't know what the 10 does, not important, it is the Dump which uses reflection.

    C# allows you to create your own TOString() functionality to describe an object

    I am assuming linq does as well ?

    Greg

    Friday, January 25, 2013 11:33 AM
  • Hi Greg,

    The extension method Dump() isn't part of the .NET Framework. I couldn't locate source code for it but I believe I get the idea of what it does. You have a few possible options:

    1. If you don't have the source code for the Dump() method to be able to modify it, or don't want to bother then simply copy the data into another class with the structure you want, as you've stated.
    2. Create an attribute to flag members you don't want dumped (eg. DumpIgnoreAttribute), similar to the XmlIgnoreAttribute, then implement the necessary logic in the Dump() method to ignore those members flagged with the attribute.
    3. Implement an "IDumpable" or similar interface with a "string GetDump()" method, then add the necessary logic to the Dump() method to check if the object to be dumped implements the interface and then return the output of the GetDump() method.

    Regards,

    Tyler

    Sunday, January 27, 2013 1:58 AM
  • Thanks for the input

    For now i will use my plan b, just duplicate classes with members suited for the dump, and later give what you say a try

    Monday, January 28, 2013 4:02 AM