mercredi 31 août 2016

Exclude interface implementation members through reflection

I have the following Interface, and implementation:

public interface INew
{
    string TestString { get; }
}

public class PurchaseOrder : INew
{
    public string OrderNo { get; set; }

    public string TestString
    {
        get { return "This is a test string"; }
    }
}

I am trying to reflect out the OrderNo part of the PurchaseOrder object, using the following code:

var props = p.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly | BindingFlags.FlattenHierarchy);
foreach (var prop in props)
{
    Console.WriteLine(prop.Name);
}

My output is returning the TestString property also. I have searched for ways to exclude implemented interface members but can only find items to include it. Can anybody show me how i can exclude such items?





Aucun commentaire:

Enregistrer un commentaire