سؤال

I have a library written in VB. It has enums with the following:

Public Enum ModelRelationshipTypes
    <Description("For 1 to 0/1 -- i.e. FK is nullable. -- related object is singleton")> _
    IHaveZeroOrOne

    <Description("For 1 to 1  -- related object is singleton")> _
    IHaveOne

    <Description("For 0 to many  (i.e. FK is nullable)  - related object is collection (dictionary)")> _
    IHaveZeroOrMore

    <Description("For 1 to many  (i.e. FK is NOT nullable) - related object is collection (dictionary)")> _
    IHaveOneOrMore

    <Description("For many to many (for true many too many relationships, with a join table that has only FKs as a composite PK) (related object is dictionary)")> _
    IHaveMany
End Enum

However, when referencing this library in a different project (c# - but probably doesn't matter), the Object Browser doesn't provide the Description, looking like this:

enter image description here

What do I have to do to get the description to show up?

هل كانت مفيدة؟

المحلول

The DescriptonAttribute is a runtime attribute. You can attach some text to an Enum and get it later to expand/explain the meaning to users. For VS/Intellisence support you want to use triple ticks to create a summary block:

   Friend Enum MediaInfoItem As Integer

        ''' <summary>
        ''' File Name to be processed
        ''' </summary>
        ''' <remarks></remarks>
        <Description("File name")> FileName
        <Description("File Size")> FileSize
        <Description("Running Time")> Duration
        ...
   End Enum

Here, only FileName will have Intellisence information; the Description is retrieved with code. They will show up as Const, because they are. MediaInfoItem would display as an Enum.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top