named parameter type constraints

后端 未结 5 2049

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:44

    Attributes can only receive compile-time-constants as parameters (e.g. 3, "hello", typeof(MyClass), "path to a resource defining whatever non constant data you need").

    The last example (passing a type) I gave may help you design a workaround (pass a type implementing an interface with the method you need).

提交回复
热议问题