C# 4.0. I have a slow property with an attribute. I want to read this attribute without calling the getter:
[Range(0.0f, 1000.0f)]
public float X
{
get
{
return SlowFunctionX();
}
}
This is what I have now:
public static T GetRangeMin<T>(T value)
{
var attribute = value.GetType()
.GetField(value.ToString())
.GetCustomAttributes(typeof(RangeAttribute), false)
.SingleOrDefault() as RangeAttribute;
return (T)attribute.Minimum;
}
var min = GetRangeMin<double>(X); // Will call the getter of X :(
Q: How can I read this attribute without calling the getter of X
?