本文整理汇总了C#中Type.FindMembers方法的典型用法代码示例。如果您正苦于以下问题:C# Type.FindMembers方法的具体用法?C# Type.FindMembers怎么用?C# Type.FindMembers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Type
的用法示例。
在下文中一共展示了Type.FindMembers方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindMethod
//CONFORMING
private static MethodInfo FindMethod(Type type, string methodName, Type[] typeArgs, Expression[] args, BindingFlags flags) {
MemberInfo[] members = type.FindMembers(MemberTypes.Method, flags, Type.FilterNameIgnoreCase, methodName);
if (members == null || members.Length == 0)
throw Error.MethodDoesNotExistOnType(methodName, type);
MethodInfo method;
var methodInfos = members.Map(t => (MethodInfo)t);
int count = FindBestMethod(methodInfos, typeArgs, args, out method);
if (count == 0)
throw Error.MethodWithArgsDoesNotExistOnType(methodName, type);
if (count > 1)
throw Error.MethodWithMoreThanOneMatch(methodName, type);
return method;
}
示例2: FindProperty
private static PropertyInfo FindProperty(Type type, string propertyName, Expression[] arguments, BindingFlags flags) {
MemberInfo[] members = type.FindMembers(MemberTypes.Property, flags, Type.FilterNameIgnoreCase, propertyName);
if (members == null || members.Length == 0)
return null;
PropertyInfo pi;
var propertyInfos = members.Map(t => (PropertyInfo)t);
int count = FindBestProperty(propertyInfos, arguments, out pi);
if (count == 0)
return null;
if (count > 1)
throw Error.PropertyWithMoreThanOneMatch(propertyName, type);
return pi;
}
示例3: ParseEnum
private static object ParseEnum(string name, Type type)
{
if (type.IsEnum)
{
MemberInfo[] memberInfos = type.FindMembers(MemberTypes.Field,
BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Static,
Type.FilterNameIgnoreCase, name);
if (memberInfos.Length != 0) return ((FieldInfo) memberInfos[0]).GetValue(null);
}
return null;
}
示例4: ParseEnum
static object ParseEnum(string name, Type type)
{
#if !(NETFX_CORE || DNXCORE50)
if (type.IsEnum)
{
MemberInfo[] memberInfos = type.FindMembers(MemberTypes.Field,
BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Static,
Type.FilterNameIgnoreCase, name);
if (memberInfos.Length != 0) return ((FieldInfo)memberInfos[0]).GetValue(null);
}
#else
if (type.IsEnum())
{
return Enum.Parse(type, name, true);
}
#endif
return null;
}