dimanche 8 avril 2018

C# Reflection distinguish between auto-properties and with-field properties

I'm trying to use reflection to search for the properties of a class and i need to be able to distinguish auto-properties from the properties that use a declared field.

Here is an example of code

public class MyClass {

private int field; 
public int AutoProp { get; set; } 

public int FieldProp 
    {
        get { return this.field; }
        set { this.field = value; }
    }
}

I have only managed to get a collection of PropertyInfo objects but i was unable to distinguish one from another

Type t = typeof(MyClass);

var props = t.GetProperties();

//var autoProps = ...
//var fieldProps = ...





Aucun commentaire:

Enregistrer un commentaire