Exemplo n.º 1
0
        private static MethodInfo FindExplicitConverstion(Type sourceType, Type targetType)
        {
            if (sourceType == targetType)
            {
                return((MethodInfo)null);
            }
            List <MethodInfo> list = new List <MethodInfo>();

            for (Type type = sourceType; type != (Type)null; type = type.BaseType)
            {
                list.AddRange((IEnumerable <MethodInfo>)type.GetMethods(BindingFlags.Static | BindingFlags.Public));
            }
            for (Type type = targetType; type != (Type)null; type = type.BaseType)
            {
                list.AddRange((IEnumerable <MethodInfo>)type.GetMethods(BindingFlags.Static | BindingFlags.Public));
            }
            foreach (MethodInfo methodInfo in list)
            {
                if (methodInfo.Name == "op_Explicit" && methodInfo.ReturnType == targetType && Utilities.IsAssignableFrom(methodInfo.GetParameters()[0].ParameterType, sourceType))
                {
                    return(methodInfo);
                }
            }
            return((MethodInfo)null);
        }