I have a class with constants. I have some string, which can be same as name of one of that constants or not.
So class with constants ConstClass
has some public const
like const1, const2, const3...
public static class ConstClass
{
public const string Const1 = "Const1";
public const string Const2 = "Const2";
public const string Const3 = "Const3";
}
To check if class contains const
by name i have tried next :
var field = (typeof (ConstClass)).GetField(customStr);
if (field != null){
return field.GetValue(obj) // obj doesn't exists for me
}
Don't know if it's realy correct way to do that, but now i don't know how to get value, cause .GetValue
method need obj of type ConstClass
(ConstClass is static)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…