named parameter type constraints

后端 未结 5 2044

I am designing a custom attribute class.

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

Then I am attempti

5条回答
  •  失恋的感觉
    2020-12-07 03:06

    Attribute parameter values need to be resolvable at compile time (i.e constants).

    See Attribute Parameter Types on MSDN:

    Values passed to attributes must be known to the compiler at compile time.

    If you can create a ValueRange that is a constant, you can use it.

提交回复
热议问题