Suppose I have a class named Data. Another class annotates one of its members, of type data, with some attribute. For example:
public class Example{
[DefaultNameAttribute("default name")]
public Data Name{get;set}
}
What I'm looking for is a way, from within the class Data, to retrieve that attribute and the data it contains. I want to be able to write the following code:
public class Data{
private string _name = null;
public string Name{
get{
if (_name != null) return _name;
return (getDefaultNameFromAnnotation(this));//this is the method I'm looking for
}
}
In other words, I want to be able to give a default value to a specific field using custom attributes specified outside my class.