本文整理汇总了C#中IKVM.Reflection.Type.GetRuntimeMethods方法的典型用法代码示例。如果您正苦于以下问题:C# Type.GetRuntimeMethods方法的具体用法?C# Type.GetRuntimeMethods怎么用?C# Type.GetRuntimeMethods使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IKVM.Reflection.Type
的用法示例。
在下文中一共展示了Type.GetRuntimeMethods方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: 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;
}