none
Custom types in attribute RRS feed

  • Question

  • Hi,

    is it possible to add more System types to the list available for attribute? actually I can see only Boolean, Integer, String and UnlimitedNatural, plus user-defined ones. I would like to add c# types like System.Guid


    Thank you
    • Moved by Esther FanMicrosoft employee Tuesday, March 16, 2010 6:53 PM (From:Visual Studio 2010 Architectural Discovery & Modeling Tools)
    • Moved by Figo Fei Friday, March 19, 2010 2:13 AM (From:Visual C# Language)
    Tuesday, March 16, 2010 12:38 PM

Answers

  • Hi fleed,

    The answer is no to System.Guid struct.
    Because we need the parameter fixed at the compile-time while struct is a runtime object cannot be a constant.

    The instance of an attribute class is constructed by the compiler when the compiler detects an attribute applied to the target, and initializes public fields and properties that have been specified. After that, the instance of the attribute is serialized to the target's metadata table entry.All these are done by the compiler and there is not a way to get any runtime variable.

    Thanks.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by fleed Thursday, March 18, 2010 5:39 AM
    • Edited by Figo Fei Thursday, March 18, 2010 6:20 AM phrase
    Thursday, March 18, 2010 3:48 AM

All replies

  • Hi fleed,

    The answer is no to System.Guid struct.
    Because we need the parameter fixed at the compile-time while struct is a runtime object cannot be a constant.

    The instance of an attribute class is constructed by the compiler when the compiler detects an attribute applied to the target, and initializes public fields and properties that have been specified. After that, the instance of the attribute is serialized to the target's metadata table entry.All these are done by the compiler and there is not a way to get any runtime variable.

    Thanks.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by fleed Thursday, March 18, 2010 5:39 AM
    • Edited by Figo Fei Thursday, March 18, 2010 6:20 AM phrase
    Thursday, March 18, 2010 3:48 AM
  • Thank you for your explanation.
    So, if I would like to assign C# types to attributes, I should create a custom profile and add a custom "PropertyType" to an attribute, shouldn't I?
    Thursday, March 18, 2010 5:39 AM
  • Hi fleed,

    Attribute parameters are restricted to constant values of the following types:

    • Simple types (bool, byte, char, short, int, long, float, and double)
    • string
    • System.Type
    • enums
    • object (The argument to an attribute parameter of type object must be a constant value of one of the above types.)
    • One-dimensional arrays of any of the above types

    Thanks.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, March 18, 2010 6:24 AM
  • Can we move this question back to the Visual Studio 2010 Architecture forum? These answers are not applicable to UML modeling which is what the original question was about.
    Oleg
    Thursday, March 18, 2010 4:32 PM