I have a class with a readonly property that gets the value of a field.
class Example
{
private readonly int _field;
public int Property => _field;
// constructor setting _field etc.
}
Can I use reflection to verify that a given property gets the value of a given field, given only the Type
i.e. without checking any of the actual values?
Something like:
public static bool ReadonlyPropertyGetsField(Type type, PropertyInfo property, FieldInfo field)
{
// Checks property get method always gets value of field
}
I had tried getting all fields and properties of the class but couldn't see a way to actually check a property getter gets a given field's value.
Aucun commentaire:
Enregistrer un commentaire