I've been trying to experiment with reflection and I have a question.
Lets say I have a class, and in this class I have a property initilized with the new feature of c# 6.0
Class MyClass()
{
public string SomeProperty{ get; set; } = "SomeValue";
}
Is there any way of getting this value, with reflection, without initilizating the class?
I know I could do this;
var foo= new MyClass();
var value = foo.GetType().GetProperty("SomeProperty").GetValue(foo);
But what I want to do is something similiar to this ;
typeof(MyClass).GetProperty("SomeProperty").GetValue();
I know I could use a field to get the value. But it needs to be a property.
Thank you.
Aucun commentaire:
Enregistrer un commentaire