none
Confusion Over Use of DefaultMemberAttribute RRS feed

  • Question

  • I am evaluating a commercial application partially by reading the documentation from a .chm file.  While doing so, I came across syntax that I am unfamiliar with and would like an interpretation from someone. The documentation expresses the use of a DefaultMemberAttribute, but I am not able to create working code from the documentation.

    The following code is a stub that I have created while doing my own interpretation of that the documentation means.  

        public abstract class PdfDestination
        {
            public PdfDestinationType Type { get; }
        }
    
        public class PdfNamedDestination : PdfDestination
        {
            public PdfDestination Destination { get; set; }
    
            public string Name { get; set; }
    
            public PdfNamedDestination()
            {
                
            }
    
            public PdfNamedDestination(string name)
            {
    
            }
        }
    
        [DefaultMember("Item")]
        public class PdfNamedDestinationCollection : Collection<PdfNamedDestination>
        {
            public new PdfNamedDestination[string name]; { get; }
        }

    According to the documentation, the class (last one listed above) called PdfNamedDestinationCollection has a DefaultMemberAttribute pointing to "Item", and the same class also has a property called "Item" which is defined by "public new PdfNamedDestination[string name]; { get; }".  That is, while in the documentation, if I click on the link for the property called "Item", it takes me to a property with the signature of "public new PdfNamedDestination[string name]; { get; }".

    I am not familiar with the syntax used to define the property, and Visual Studio complains about "Invalid expression term 'string'" and also complains that "The name 'get' does not exist in the current context".

    How have I misinterpreted the construction of the classes and the how have I misinterpreted the use of the property?


    Rob E.

    Friday, November 10, 2017 9:11 PM

Answers

  • Hello Rob,

    If the issues has been solved, you could close the thread by marking  as answer...

    The issue has been solved by contacting tech support who replied with the following code. The adorner, "new" and semicolon should be removed.  The app that automatically generated the documentation added the extraneous semicolon, and the developer is left to infer an interpretation of the rest from the documentation.

       public class PdfNamedDestinationCollection : Collection<PdfNamedDestination>
       {
            public PdfNamedDestination this[string name]
            {
                get;
            }
        }
    
    I am evaluating a trial version and didn't think Tech Support would be provided for an unpaid version.  Had I known that Tech Support would be so helpful, I would not have posted here, but, since I did, maybe this post will help someone with a similar problem by providing more information on indexers.
      


    Rob E.

    • Marked as answer by REvans611 Wednesday, November 15, 2017 5:52 PM
    Wednesday, November 15, 2017 5:51 PM

All replies

  • Hello,

     Perhaps this link will help you, read the Remarks section.

     

     https://msdn.microsoft.com/en-us/library/system.reflection.defaultmemberattribute(v=vs.110).aspx

     Hope this helps :)

    Friday, November 10, 2017 10:48 PM
  •  Perhaps this link will help you, read the Remarks section.

    Thanks for the reply, but I have already read that several times, and it still leaves me confused.  However, my question is really about the syntax of the property "public new PdfNamedDestination[string name]; { get; } " and how it might relate to "Item".

    Rob E.

    Friday, November 10, 2017 11:02 PM
  • Hello,

     I am not sure if I can explain well enough but will try.  Attributes are

    specific characteristic of an object.  The compiler will set attributes as

    defined by the language syntax.  However, you also can define custom

    attributes. 

     

     Please read the information and try some code examples in debug, link below;

     https://msdn.microsoft.com/en-us/library/z0w1kczw%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

     

     I recommend reading all the text and follow up reading with links below;

     

     https://msdn.microsoft.com/en-us/library/ms173183%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

     

     https://msdn.microsoft.com/en-us/library/sw480ze8(v=vs.110).aspx

     

     https://msdn.microsoft.com/en-us/library/z919e8tw(v=vs.110).aspx

     

    Hope this helps :)

    Saturday, November 11, 2017 12:29 AM
  • Nothing in those links explains "public new PdfNamedDestination[string name]; { get; }".

    Rob E.

    Saturday, November 11, 2017 2:45 AM
  • Hello,

     The "get" is an accessor. Please read MSDN Ref link below;

     https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/get

     Thanks :)

    Saturday, November 11, 2017 7:11 AM
  • Hello,

     The "get" is an accessor. Please read MSDN Ref link below;

     https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/get

     Thanks :)

    I would guess I have coded more than a few "gets" in my career. :-)

    How would you explain a property coded as "public new PdfNamedDestination[string name]; " followed by the "{get;}"?

    I can change it by removing "string name" and the semicolon to "public new PdfNamedDestination[] MyProperty { get; }" and VS likes it just fine except that when hovering over the "new", VS says it is redundant because MyProperty hides nothing.  That semicolon in the middle means that there are two statements: 1) a new up of PdfNamedDestination; 2) a {get;} of something.

    I was hoping that someone on MSDN Forums had run across this notation in documentation before an could enlighten me, but now I think I have to somehow contact the author of the documentation and see if the author can educate me.


    Rob E.

    Saturday, November 11, 2017 3:08 PM
  • Hello,

     Sorry, can you upload the Docs to OneDrive and share

    so I may read what you are using.

     Thanks :)

    Saturday, November 11, 2017 3:40 PM
  • Hello,

     Sorry, can you upload the Docs to OneDrive and share

    so I may read what you are using.

     Thanks :)

    Chm File


    Rob E.

    Saturday, November 11, 2017 4:03 PM
  • Hello,

     

     Now I have a better idea about your post. As the posted

    code was incomplete. I did figure you had a project for

    PDF but did not know from what Dev.

     I am wondering why you want to know how their PDF

    class, internal code that is, does what it is doing?

     Sorry, but I can only help with MSDN C# syntax and not

    3rd Party libraries.

     

     But, I did provide many links about C# syntax for you and

    sorry that I can not explain it any better than MSDN Docs.

     

     Oh, as for the use of "new" without an identifier, thats called

    Anomynous and only the compiler generate the base ref. You

    have seen this before I am sure.

     

     Anonymous Types Link

    https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/anonymous-types

     

     Anonymous Functions Link

    https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/anonymous-functions

     

     Anonymous Methods Link

    https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/anonymous-methods

     Please look at the examples from all the links above, should

    be helpful.

     

     Thanks :)

    Saturday, November 11, 2017 6:04 PM
  • I am wondering why you want to know how their PDF

    class, internal code that is, does what it is doing?

    I am looking through the docs to determine if I want to purchase the library and ran across something new for me and decided to learn more about it.  I am a very curious programmer; but aren't we all?


    Rob E.

    Saturday, November 11, 2017 6:11 PM
  • Hello,

     Yes! We programmers are a curious bunch. :)  Sorry that my help

    was not helpful.  I did not download and install the Demo because

    I have no need.  I am sure that some want to extract or rebuild PDFs.

    The PDF Toolkit looks good and only glanced over the viewer.

     I did try your snippet and I think that { get; } is incorrect, at least on

    VS C# 2012 for me. Must be something new with 2015/17 versions.

     I can only hope this forum will help or you get a concise answer from

    Developers at XfiniumPDF site.

     

     Good Luck :)

    Saturday, November 11, 2017 10:37 PM
  • Thanks for your input, User3DX!

    Rob E.

    Saturday, November 11, 2017 10:49 PM
  • Hello Rob,

    If the issues has been solved, you could close the thread by marking  as answer, This can be beneficial to other community members reading this thread. Thanks a lot.

    Sincerely,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, November 15, 2017 10:22 AM
    Moderator
  • Hello Rob,

    If the issues has been solved, you could close the thread by marking  as answer...

    The issue has been solved by contacting tech support who replied with the following code. The adorner, "new" and semicolon should be removed.  The app that automatically generated the documentation added the extraneous semicolon, and the developer is left to infer an interpretation of the rest from the documentation.

       public class PdfNamedDestinationCollection : Collection<PdfNamedDestination>
       {
            public PdfNamedDestination this[string name]
            {
                get;
            }
        }
    
    I am evaluating a trial version and didn't think Tech Support would be provided for an unpaid version.  Had I known that Tech Support would be so helpful, I would not have posted here, but, since I did, maybe this post will help someone with a similar problem by providing more information on indexers.
      


    Rob E.

    • Marked as answer by REvans611 Wednesday, November 15, 2017 5:52 PM
    Wednesday, November 15, 2017 5:51 PM