named parameter type constraints

后端 未结 5 2052

I am designing a custom attribute class.

public class MyAttr: Attribute
{
    public ValueRange ValRange { get; set; }
}

Then I am attempti

5条回答
  •  天命终不由人
    2020-12-07 02:51

    Attribute parameters must be values of the following types (quoting the article):

    • 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

    Edit: Changed "compile-time constant" to "value", since types and arrays are not constants (thanks to the commenter who pointed this out (and subsequently deleted his comment for some reason...))

提交回复
热议问题