Suppose I have an attribute capable to be set to a System.Object say:
[AttributeUsage(AttributeTargets.Property)]
class MyAttrAttribute : Attribute {
public object ThisOne { get; set; }
}
I’d like to get the same result of this (that doesn’t compile):
class AttrTarget {
[MyAttr(ThisOne = new MyClass())]
public MyClass Thing { get; set; }
}
There’s a way to achieve the same result without using reflection?
The
DefaultValueattribute for example has aType, Stringconstructor. This can be used to create an instance e.g. for desired time span or a desired color:So maybe this kind of creating attribute values helps you to get an idea on how to solve your problem.