本文整理汇总了C#中IKVM.Reflection.Type.GetMethods方法的典型用法代码示例。如果您正苦于以下问题:C# Type.GetMethods方法的具体用法?C# Type.GetMethods怎么用?C# Type.GetMethods使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IKVM.Reflection.Type
的用法示例。
在下文中一共展示了Type.GetMethods方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryCreate
public static ParseableSerializer TryCreate(Type type, TypeModel model)
{
if (type == null) throw new ArgumentNullException("type");
#if WINRT || PORTABLE || COREFX
MethodInfo method = null;
#if WINRT || COREFX
foreach (MethodInfo tmp in type.GetTypeInfo().GetDeclaredMethods("Parse"))
#else
foreach (MethodInfo tmp in type.GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly))
#endif
{
ParameterInfo[] p;
if (tmp.Name == "Parse" && tmp.IsPublic && tmp.IsStatic && tmp.DeclaringType == type && (p = tmp.GetParameters()) != null && p.Length == 1 && p[0].ParameterType == typeof(string))
{
method = tmp;
break;
}
}
#else
MethodInfo method = type.GetMethod("Parse",
BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly,
null, new Type[] { model.MapType(typeof(string)) }, null);
#endif
if (method != null && method.ReturnType == type)
{
if (Helpers.IsValueType(type))
{
MethodInfo toString = GetCustomToString(type);
if (toString == null || toString.ReturnType != model.MapType(typeof(string))) return null; // need custom ToString, fools
}
return new ParseableSerializer(method);
}
return null;
}
示例2: HasCast
private static bool HasCast(Type type, Type from, Type to, out MethodInfo op)
{
#if WINRT
System.Collections.Generic.List<MethodInfo> list = new System.Collections.Generic.List<MethodInfo>();
foreach (var item in type.GetRuntimeMethods())
{
if (item.IsStatic) list.Add(item);
}
MethodInfo[] found = list.ToArray();
#else
const BindingFlags flags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
MethodInfo[] found = type.GetMethods(flags);
#endif
for(int i = 0 ; i < found.Length ; i++)
{
MethodInfo m = found[i];
if ((m.Name != "op_Implicit" && m.Name != "op_Explicit") || m.ReturnType != to)
{
continue;
}
ParameterInfo[] paramTypes = m.GetParameters();
if(paramTypes.Length == 1 && paramTypes[0].ParameterType == from)
{
op = m;
return true;
}
}
op = null;
return false;
}
示例3: HasCast
private static bool HasCast(TypeModel model, Type type, Type from, Type to, out MethodInfo op)
{
#if WINRT
System.Collections.Generic.List<MethodInfo> list = new System.Collections.Generic.List<MethodInfo>();
foreach (var item in type.GetRuntimeMethods())
{
if (item.IsStatic) list.Add(item);
}
MethodInfo[] found = list.ToArray();
#else
const BindingFlags flags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
MethodInfo[] found = type.GetMethods(flags);
#endif
ParameterInfo[] paramTypes;
Type convertAttributeType = null;
for (int i = 0; i < found.Length; i++)
{
MethodInfo m = found[i];
if (m.ReturnType != to) continue;
paramTypes = m.GetParameters();
if(paramTypes.Length == 1 && paramTypes[0].ParameterType == from)
{
if (convertAttributeType == null)
{
convertAttributeType = model.MapType(typeof(ProtoConverterAttribute), false);
if (convertAttributeType == null)
{ // attribute isn't defined in the source assembly: stop looking
break;
}
}
if (m.IsDefined(convertAttributeType, true))
{
op = m;
return true;
}
}
}
for(int i = 0 ; i < found.Length ; i++)
{
MethodInfo m = found[i];
if ((m.Name != "op_Implicit" && m.Name != "op_Explicit") || m.ReturnType != to)
{
continue;
}
paramTypes = m.GetParameters();
if(paramTypes.Length == 1 && paramTypes[0].ParameterType == from)
{
op = m;
return true;
}
}
op = null;
return false;
}
示例4: GetInstanceMethod
internal static MethodInfo GetInstanceMethod(Type declaringType, string name, Type[] parameterTypes)
{
foreach (MethodInfo method in declaringType.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
{
if (method.Name == name && IsMatch(method.GetParameters(), parameterTypes)) return method;
}
return null;
}
示例5: GetStaticMethod
internal static MethodInfo GetStaticMethod(Type declaringType, string name)
{
foreach (MethodInfo method in declaringType.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
{
if (method.Name == name) return method;
}
return null;
}