I have a class
which has a property that has an attribute on it:
public class MyClass
{
[CustomAttribute]
public CustomObject Data { get; set; }
}
The CustomAttribute
has a parameter who's value I'd like to be able to be set at various points in code with a compile-time constant.
My question is: Is it possible to do something like shown below
public class MyClass
{
// --- Based on the below code, Parameter should be 123
[CustomAttribute(Parameter = HelperAttribute.Value)]
public CustomObject Data { get; set; }
}
// ...
// --- Create a new instance of MyClass, and use the value
// --- 123 for Data's CustomAttribute Parameter.
[HelperAttribute(Value = 123)]
public MyClass Obj { get; set; }
Note: I am aware that I can't do the reflection part at compile time. I'm curious if there's a way to do it that's built into C#.