How do I use reflection to get properties explicitly implementing an interface?

后端 未结 9 1019
[愿得一人]
[愿得一人] 2021-01-03 20:18

More specifically, if I have:

public class TempClass : TempInterface
{

    int TempInterface.TempProperty
    {
        get;
        set;
    }
    int Temp         


        
9条回答
  •  离开以前
    2021-01-03 20:44

    Jacob's code is missing a filter:

            var props = typeof(TempClass).GetInterfaces().Where(i => i.Name=="TempInterface").SelectMany(i => i.GetProperties());
            foreach (var prop in props)
                Console.WriteLine(prop);
    

提交回复
热议问题