In .NET, can you use reflection to get all non-inherited methods of a class?

前端 未结 4 693
滥情空心
滥情空心 2021-02-18 15:51

Because of this issue here, I\'m trying to write a custom JsonConverter that handles cases where you subclass a list or a collection, then add extra properties to it. As such,

4条回答
  •  天涯浪人
    2021-02-18 16:06

    You have to select all members in MySubClass and keep only those where DeclaringType == MySubClass.

    With LINQ, something like that (overkill) :

    MemberInfo[] notInherited = GetType("MySubClass").GetMembers().Where(m => m.DeclaringType == GetType("MySubClass"));
    

    Or with GetMembers() overload :

    MemberInfo[] notInherited = GetType("MySubClass").GetMembers(BindingFlags.DeclaredOnly);
    

提交回复
热议问题