您可以查询已定义的访问器,然后排除这些访问器:
var propertyAccessors = type.GetProperties(BindingFlags.Static | BindingFlags.Public)
.SelectMany(p => p.GetAccessors())
.Cast<MemberInfo>();
var eventAccessors = type.GetEvents(BindingFlags.Static | BindingFlags.Public)
.SelectMany(e => new[] {
e.GetAddMethod(true),
e.GetRemoveMethod(true)
})
.Cast<MemberInfo>();
var accessors = propertyAccessors.Concat(eventAccessors);
var memberList = type.GetMembers(BindingFlags.Static | BindingFlags.Public)
.Except(accessors);
您也许可以过滤掉那些没有特殊名称的方法(如MethodBase.IsSpecialName
.
var memberList = type.GetMembers(BindingFlags.Static | BindingFlags.Public)
.Where(m => {
var method = m as MethodBase;
return method == null || !method.IsSpecialName;
});