Esempio n. 1
0
 public static NewType[] GetClassesToTypes(Type[] classes)
 {
     NewType[] types = new NewType[classes.Length];
     for (int a = classes.Length; a-- > 0;)
     {
         Type clazz = classes[a];
         if (clazz == null)
         {
             continue;
         }
         types[a] = NewType.GetType(clazz);
     }
     return(types);
 }
Esempio n. 2
0
        public override bool Equals(Object obj)
        {
            if (Object.ReferenceEquals(obj, this))
            {
                return(true);
            }
            if (!(obj is NewType))
            {
                return(false);
            }
            NewType other = (NewType)obj;

            return(internalName.Equals(other.internalName));
        }
Esempio n. 3
0
 public MethodKeyOfType(NewType returnType, String methodName, NewType[] parameterTypes)
 {
     this.returnType     = returnType;
     this.methodName     = methodName;
     this.parameterTypes = parameterTypes;
 }
Esempio n. 4
0
        public static MethodInfo GetDeclaredMethod(bool tryOnly, Type type, NewType returnType, String methodName, NewType[] parameters)
        {
            foreach (MethodInfo method in GetDeclaredMethodsInHierarchy(type))
            {
                if (!method.Name.Equals(methodName))
                {
                    continue;
                }
                if (returnType != null && !NewType.GetType(method.ReturnType).Equals(returnType))
                {
                    continue;
                }
                if (parameters == null)
                {
                    return(method);
                }
                ParameterInfo[] currentParameters = method.GetParameters();
                if (currentParameters.Length != parameters.Length)
                {
                    continue;
                }
                bool sameParameters = true;
                for (int a = currentParameters.Length; a-- > 0;)
                {
                    if (parameters[a] != null && !NewType.GetType(currentParameters[a].ParameterType).Equals(parameters[a]))
                    {
                        sameParameters = false;
                        break;
                    }
                }
                if (sameParameters)
                {
                    return(method);
                }
            }
            if (tryOnly)
            {
                return(null);
            }
            String propertyName = methodName;

            if (methodName.ToLowerInvariant().StartsWith("set") ||
                methodName.ToLowerInvariant().StartsWith("get"))
            {
                propertyName = StringBuilderUtil.UpperCaseFirst(methodName.Substring(3));
            }
            PropertyInfo propertyInfo;
            BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy;

            if (returnType != null)
            {
                try
                {
                    propertyInfo = type.GetProperty(propertyName, flags, null, returnType.Type, Type.EmptyTypes, new ParameterModifier[0]);
                }
                catch (Exception)
                {
                    throw;
                }
            }
            else
            {
                propertyInfo = type.GetProperty(propertyName, flags);
            }
            if (propertyInfo != null)
            {
                if (methodName.ToLowerInvariant().StartsWith("set") && propertyInfo.GetSetMethod() != null)
                {
                    return(propertyInfo.GetSetMethod());
                }
                else if (propertyInfo.GetGetMethod() != null)
                {
                    return(propertyInfo.GetGetMethod());
                }
            }
            throw new ArgumentException("No matching method found: " + methodName);
        }
Esempio n. 5
0
 public static MethodInfo GetDeclaredMethod(bool tryOnly, Type type, Type returnType, String methodName, params Type[] parameters)
 {
     return(GetDeclaredMethod(tryOnly, type, returnType != null ? NewType.GetType(returnType) : null, methodName, TypeUtil.GetClassesToTypes(parameters)));
 }