Exemplo n.º 1
0
 private static object CallMethod(Symbols.Container BaseReference, string MethodName, object[] Arguments, string[] ArgumentNames, Type[] TypeArguments, bool[] CopyBack, BindingFlags InvocationFlags, bool ReportErrors, ref OverloadResolution.ResolutionFailure Failure)
 {
     Failure = OverloadResolution.ResolutionFailure.None;
     if (ArgumentNames.Length > Arguments.Length || CopyBack != null && CopyBack.Length != Arguments.Length)
     {
         Failure = OverloadResolution.ResolutionFailure.InvalidArgument;
         if (ReportErrors)
         {
             throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue"));
         }
         return((object)null);
     }
     if (Symbols.HasFlag(InvocationFlags, BindingFlags.SetProperty) && Arguments.Length < 1)
     {
         Failure = OverloadResolution.ResolutionFailure.InvalidArgument;
         if (ReportErrors)
         {
             throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue"));
         }
         return((object)null);
     }
     MemberInfo[] members = BaseReference.GetMembers(ref MethodName, ReportErrors);
     if (members == null || members.Length == 0)
     {
         Failure = OverloadResolution.ResolutionFailure.MissingMember;
         if (ReportErrors)
         {
             BaseReference.GetMembers(ref MethodName, true);
         }
         return((object)null);
     }
     Symbols.Method TargetProcedure = NewLateBinding.ResolveCall(BaseReference, MethodName, members, Arguments, ArgumentNames, TypeArguments, InvocationFlags, ReportErrors, ref Failure);
     if (Failure == OverloadResolution.ResolutionFailure.None)
     {
         return(BaseReference.InvokeMethod(TargetProcedure, Arguments, CopyBack, InvocationFlags));
     }
     return((object)null);
 }
Exemplo n.º 2
0
 internal MemberInfo[] LookupNamedMembers(string MemberName)
 {
     MemberInfo[] Members;
     if (Symbols.IsGenericParameter(this.m_Type))
     {
         Type classConstraint = Symbols.GetClassConstraint(this.m_Type);
         Members = classConstraint == null ? (MemberInfo[])null : classConstraint.GetMember(MemberName, BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy);
     }
     else
     {
         Members = this.m_IReflect.GetMember(MemberName, BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy);
     }
     MemberInfo[] memberInfoArray = Symbols.Container.FilterInvalidMembers(Members);
     if (memberInfoArray == null)
     {
         memberInfoArray = Symbols.Container.NoMembers;
     }
     else if (memberInfoArray.Length > 1)
     {
         Array.Sort((Array)memberInfoArray, (IComparer)Symbols.Container.InheritanceSorter.Instance);
     }
     return(memberInfoArray);
 }
Exemplo n.º 3
0
 internal static bool RefersToGenericParameter(Type ReferringType, MethodBase Method)
 {
     if (!Symbols.IsRawGeneric(Method))
     {
         return(false);
     }
     if (ReferringType.IsByRef)
     {
         ReferringType = Symbols.GetElementType(ReferringType);
     }
     if (Symbols.IsGenericParameter(ReferringType))
     {
         if (Symbols.AreGenericMethodDefsEqual(ReferringType.DeclaringMethod, Method))
         {
             return(true);
         }
     }
     else if (Symbols.IsGeneric(ReferringType))
     {
         Type[] typeArguments = Symbols.GetTypeArguments(ReferringType);
         int    index         = 0;
         while (index < typeArguments.Length)
         {
             if (Symbols.RefersToGenericParameter(typeArguments[index], Method))
             {
                 return(true);
             }
             checked { ++index; }
         }
     }
     else if (Symbols.IsArrayType(ReferringType))
     {
         return(Symbols.RefersToGenericParameter(ReferringType.GetElementType(), Method));
     }
     return(false);
 }
Exemplo n.º 4
0
            private static MemberInfo[] FilterInvalidMembers(MemberInfo[] Members)
            {
                if (Members == null || Members.Length == 0)
                {
                    return((MemberInfo[])null);
                }
                int num1   = 0;
                int num2   = 0;
                int num3   = checked (Members.Length - 1);
                int index1 = num2;

                while (index1 <= num3)
                {
                    ParameterInfo[] Parameters = (ParameterInfo[])null;
                    Type            ReturnType = (Type)null;
                    switch (Members[index1].MemberType)
                    {
                    case MemberTypes.Constructor:
                    case MemberTypes.Method:
                        MethodInfo member1 = (MethodInfo)Members[index1];
                        Parameters = member1.GetParameters();
                        ReturnType = member1.ReturnType;
                        break;

                    case MemberTypes.Field:
                        ReturnType = ((FieldInfo)Members[index1]).FieldType;
                        break;

                    case MemberTypes.Property:
                        PropertyInfo member2   = (PropertyInfo)Members[index1];
                        MethodInfo   getMethod = member2.GetGetMethod();
                        if (getMethod != null)
                        {
                            Parameters = getMethod.GetParameters();
                        }
                        else
                        {
                            ParameterInfo[] parameters = member2.GetSetMethod().GetParameters();
                            Parameters = new ParameterInfo[checked (parameters.Length - 2 + 1)];
                            Array.Copy((Array)parameters, (Array)Parameters, Parameters.Length);
                        }
                        ReturnType = member2.PropertyType;
                        break;
                    }
                    if (Symbols.AreParametersAndReturnTypesValid(Parameters, ReturnType))
                    {
                        checked { ++num1; }
                    }
                    else
                    {
                        Members[index1] = (MemberInfo)null;
                    }
                    checked { ++index1; }
                }
                if (num1 == Members.Length)
                {
                    return(Members);
                }
                if (num1 <= 0)
                {
                    return((MemberInfo[])null);
                }
                MemberInfo[] memberInfoArray = new MemberInfo[checked (num1 - 1 + 1)];
                int          index2          = 0;
                int          num4            = 0;
                int          num5            = checked (Members.Length - 1);
                int          index3          = num4;

                while (index3 <= num5)
                {
                    if (Members[index3] != null)
                    {
                        memberInfoArray[index2] = Members[index3];
                        checked { ++index2; }
                    }
                    checked { ++index3; }
                }
                return(memberInfoArray);
            }
Exemplo n.º 5
0
 internal static bool IsParamArray(ParameterInfo Parameter)
 {
     return(Symbols.IsArrayType(Parameter.ParameterType) && Parameter.IsDefined(typeof(ParamArrayAttribute), false));
 }
Exemplo n.º 6
0
 internal static int IndexIn(Type PossibleGenericParameter, MethodBase GenericMethodDef)
 {
     if (Symbols.IsGenericParameter(PossibleGenericParameter) && PossibleGenericParameter.DeclaringMethod != null && Symbols.AreGenericMethodDefsEqual(PossibleGenericParameter.DeclaringMethod, GenericMethodDef))
     {
         return(PossibleGenericParameter.GenericParameterPosition);
     }
     return(-1);
 }
Exemplo n.º 7
0
 internal static bool IsOrInheritsFrom(Type Derived, Type Base)
 {
     if (Derived == Base)
     {
         return(true);
     }
     if (Derived.IsGenericParameter)
     {
         if (Symbols.IsClass(Base) && (uint)(Derived.GenericParameterAttributes & GenericParameterAttributes.NotNullableValueTypeConstraint) > 0U && Symbols.IsOrInheritsFrom(typeof(ValueType), Base))
         {
             return(true);
         }
         Type[] parameterConstraints = Derived.GetGenericParameterConstraints();
         int    index = 0;
         while (index < parameterConstraints.Length)
         {
             if (Symbols.IsOrInheritsFrom(parameterConstraints[index], Base))
             {
                 return(true);
             }
             checked { ++index; }
         }
     }
     else if (Symbols.IsInterface(Derived))
     {
         if (Symbols.IsInterface(Base))
         {
             Type[] interfaces = Derived.GetInterfaces();
             int    index      = 0;
             while (index < interfaces.Length)
             {
                 if (interfaces[index] == Base)
                 {
                     return(true);
                 }
                 checked { ++index; }
             }
         }
     }
     else if (Symbols.IsClass(Base) && Symbols.IsClassOrValueType(Derived))
     {
         return(Derived.IsSubclassOf(Base));
     }
     return(false);
 }
Exemplo n.º 8
0
 internal static bool IsReferenceType(Type Type)
 {
     return(Symbols.IsClass(Type) || Symbols.IsInterface(Type));
 }
Exemplo n.º 9
0
 internal static bool IsClassOrValueType(Type Type)
 {
     return(Symbols.IsValueType(Type) || Symbols.IsClass(Type));
 }
Exemplo n.º 10
0
 internal static bool IsClass(Type Type)
 {
     return(Type.IsClass || Symbols.IsRootEnumType(Type));
 }
Exemplo n.º 11
0
 internal static bool IsIntrinsicType(Type Type)
 {
     return(Symbols.IsIntrinsicType(Symbols.GetTypeCode(Type)) && !Symbols.IsEnum(Type));
 }
Exemplo n.º 12
0
 internal static bool IsNumericType(Type Type)
 {
     return(Symbols.IsNumericType(Symbols.GetTypeCode(Type)));
 }
Exemplo n.º 13
0
        internal static string VBFriendlyNameOfType(Type typ, bool FullName = false)
        {
            string suffixAndElementType = Utils.GetArraySuffixAndElementType(ref typ);
            string str1;

            switch (!typ.IsEnum ? Type.GetTypeCode(typ) : TypeCode.Object)
            {
            case TypeCode.DBNull:
                str1 = "DBNull";
                break;

            case TypeCode.Boolean:
                str1 = "Boolean";
                break;

            case TypeCode.Char:
                str1 = "Char";
                break;

            case TypeCode.SByte:
                str1 = "SByte";
                break;

            case TypeCode.Byte:
                str1 = "Byte";
                break;

            case TypeCode.Int16:
                str1 = "Short";
                break;

            case TypeCode.UInt16:
                str1 = "UShort";
                break;

            case TypeCode.Int32:
                str1 = "Integer";
                break;

            case TypeCode.UInt32:
                str1 = "UInteger";
                break;

            case TypeCode.Int64:
                str1 = "Long";
                break;

            case TypeCode.UInt64:
                str1 = "ULong";
                break;

            case TypeCode.Single:
                str1 = "Single";
                break;

            case TypeCode.Double:
                str1 = "Double";
                break;

            case TypeCode.Decimal:
                str1 = "Decimal";
                break;

            case TypeCode.DateTime:
                str1 = "Date";
                break;

            case TypeCode.String:
                str1 = "String";
                break;

            default:
                if (Symbols.IsGenericParameter(typ))
                {
                    str1 = typ.Name;
                    break;
                }
                string str2 = (string)null;
                string genericArgsSuffix = Utils.GetGenericArgsSuffix(typ);
                string str3;
                if (FullName)
                {
                    if (typ.IsNested)
                    {
                        str2 = Utils.VBFriendlyNameOfType(typ.DeclaringType, true);
                        str3 = typ.Name;
                    }
                    else
                    {
                        str3 = typ.FullName;
                    }
                }
                else
                {
                    str3 = typ.Name;
                }
                if (genericArgsSuffix != null)
                {
                    int length = str3.LastIndexOf('`');
                    if (length != -1)
                    {
                        str3 = str3.Substring(0, length);
                    }
                    str1 = str3 + genericArgsSuffix;
                }
                else
                {
                    str1 = str3;
                }
                if (str2 != null)
                {
                    str1 = str2 + "." + str1;
                    break;
                }
                break;
            }
            if (suffixAndElementType != null)
            {
                str1 += suffixAndElementType;
            }
            return(str1);
        }
Exemplo n.º 14
0
        internal static string PropertyToString(PropertyInfo Prop)
        {
            string     str1       = "";
            MethodInfo methodInfo = Prop.GetGetMethod();

            Utils.PropertyKind propertyKind;
            ParameterInfo[]    parameterInfoArray1;
            Type typ;

            if (methodInfo != null)
            {
                propertyKind        = Prop.GetSetMethod() == null ? Utils.PropertyKind.ReadOnly : Utils.PropertyKind.ReadWrite;
                parameterInfoArray1 = methodInfo.GetParameters();
                typ = methodInfo.ReturnType;
            }
            else
            {
                propertyKind = Utils.PropertyKind.WriteOnly;
                methodInfo   = Prop.GetSetMethod();
                ParameterInfo[] parameters = methodInfo.GetParameters();
                parameterInfoArray1 = new ParameterInfo[checked (parameters.Length - 2 + 1)];
                Array.Copy((Array)parameters, (Array)parameterInfoArray1, parameterInfoArray1.Length);
                typ = parameters[checked (parameters.Length - 1)].ParameterType;
            }
            string str2 = str1 + "Public ";

            if ((methodInfo.Attributes & MethodAttributes.Virtual) != MethodAttributes.PrivateScope)
            {
                if (!Prop.DeclaringType.IsInterface)
                {
                    str2 += "Overrides ";
                }
            }
            else if (Symbols.IsShared((MemberInfo)methodInfo))
            {
                str2 += "Shared ";
            }
            if (propertyKind == Utils.PropertyKind.ReadOnly)
            {
                str2 += "ReadOnly ";
            }
            if (propertyKind == Utils.PropertyKind.WriteOnly)
            {
                str2 += "WriteOnly ";
            }
            string str3 = str2 + "Property " + Prop.Name + "(";
            bool   flag = true;

            ParameterInfo[] parameterInfoArray2 = parameterInfoArray1;
            int             index = 0;

            while (index < parameterInfoArray2.Length)
            {
                ParameterInfo Parameter = parameterInfoArray2[index];
                if (!flag)
                {
                    str3 += ", ";
                }
                else
                {
                    flag = false;
                }
                str3 += Utils.ParameterToString(Parameter);
                checked { ++index; }
            }
            return(str3 + ") As " + Utils.VBFriendlyNameOfType(typ, true));
        }
Exemplo n.º 15
0
        /// <summary>Returns a Visual Basic method signature.</summary>
        /// <param name="Method">A <see cref="T:System.Reflection.MethodBase" /> object to return a Visual Basic method signature for.</param>
        /// <returns>The Visual Basic method signature for the supplied <see cref="T:System.Reflection.MethodBase" /> object.</returns>
        public static string MethodToString(MethodBase Method)
        {
            Type   typ1 = (Type)null;
            string str1 = "";

            if (Method.MemberType == MemberTypes.Method)
            {
                typ1 = ((MethodInfo)Method).ReturnType;
            }
            if (Method.IsPublic)
            {
                str1 += "Public ";
            }
            else if (Method.IsPrivate)
            {
                str1 += "Private ";
            }
            else if (Method.IsAssembly)
            {
                str1 += "Friend ";
            }
            if ((Method.Attributes & MethodAttributes.Virtual) != MethodAttributes.PrivateScope)
            {
                if (!Method.DeclaringType.IsInterface)
                {
                    str1 += "Overrides ";
                }
            }
            else if (Symbols.IsShared((MemberInfo)Method))
            {
                str1 += "Shared ";
            }
            Symbols.UserDefinedOperator userDefinedOperator = Symbols.UserDefinedOperator.UNDEF;
            if (Symbols.IsUserDefinedOperator(Method))
            {
                userDefinedOperator = Symbols.MapToUserDefinedOperator(Method);
            }
            string str2;

            switch (userDefinedOperator)
            {
            case Symbols.UserDefinedOperator.UNDEF:
                str2 = typ1 == null || typ1 == Utils.VoidType ? str1 + "Sub " : str1 + "Function ";
                break;

            case Symbols.UserDefinedOperator.Narrow:
                str1 += "Narrowing ";
                goto default;

            case Symbols.UserDefinedOperator.Widen:
                str1 += "Widening ";
                goto default;

            default:
                str2 = str1 + "Operator ";
                break;
            }
            string str3 = userDefinedOperator == Symbols.UserDefinedOperator.UNDEF ? (Method.MemberType != MemberTypes.Constructor ? str2 + Method.Name : str2 + "New") : str2 + Symbols.OperatorNames[(int)userDefinedOperator];

            if (Symbols.IsGeneric(Method))
            {
                string str4           = str3 + "(Of ";
                bool   flag           = true;
                Type[] typeParameters = Symbols.GetTypeParameters((MemberInfo)Method);
                int    index          = 0;
                while (index < typeParameters.Length)
                {
                    Type typ2 = typeParameters[index];
                    if (!flag)
                    {
                        str4 += ", ";
                    }
                    else
                    {
                        flag = false;
                    }
                    str4 += Utils.VBFriendlyNameOfType(typ2, false);
                    checked { ++index; }
                }
                str3 = str4 + ")";
            }
            string str5  = str3 + "(";
            bool   flag1 = true;

            ParameterInfo[] parameters = Method.GetParameters();
            int             index1     = 0;

            while (index1 < parameters.Length)
            {
                ParameterInfo Parameter = parameters[index1];
                if (!flag1)
                {
                    str5 += ", ";
                }
                else
                {
                    flag1 = false;
                }
                str5 += Utils.ParameterToString(Parameter);
                checked { ++index1; }
            }
            string str6 = str5 + ")";

            if (typ1 != null && typ1 != Utils.VoidType)
            {
                str6 = str6 + " As " + Utils.VBFriendlyNameOfType(typ1, true);
            }
            return(str6);
        }
Exemplo n.º 16
0
        internal static Symbols.Method ResolveCall(Symbols.Container BaseReference, string MethodName, MemberInfo[] Members, object[] Arguments, string[] ArgumentNames, Type[] TypeArguments, BindingFlags LookupFlags, bool ReportErrors, ref OverloadResolution.ResolutionFailure Failure)
        {
            Failure = OverloadResolution.ResolutionFailure.None;
            if (Members[0].MemberType != MemberTypes.Method && Members[0].MemberType != MemberTypes.Property)
            {
                Failure = OverloadResolution.ResolutionFailure.InvalidTarget;
                if (ReportErrors)
                {
                    throw new ArgumentException(Utils.GetResourceString("ExpressionNotProcedure", MethodName, BaseReference.VBFriendlyName));
                }
                return((Symbols.Method)null);
            }
            int    length = Arguments.Length;
            object obj1   = (object)null;

            if (Symbols.HasFlag(LookupFlags, BindingFlags.SetProperty))
            {
                if (Arguments.Length == 0)
                {
                    Failure = OverloadResolution.ResolutionFailure.InvalidArgument;
                    if (ReportErrors)
                    {
                        throw new InvalidCastException(Utils.GetResourceString("PropertySetMissingArgument1", new string[1]
                        {
                            MethodName
                        }));
                    }
                    return((Symbols.Method)null);
                }
                object[] objArray = Arguments;
                Arguments = new object[checked (length - 2 + 1)];
                Array.Copy((Array)objArray, (Array)Arguments, Arguments.Length);
                obj1 = objArray[checked (length - 1)];
            }
            Symbols.Method TargetProcedure1 = OverloadResolution.ResolveOverloadedCall(MethodName, Members, Arguments, ArgumentNames, TypeArguments, LookupFlags, ReportErrors, ref Failure);
            if (Failure != OverloadResolution.ResolutionFailure.None)
            {
                return((Symbols.Method)null);
            }
            if (!TargetProcedure1.ArgumentsValidated && !OverloadResolution.CanMatchArguments(TargetProcedure1, Arguments, ArgumentNames, TypeArguments, false, (List <string>)null))
            {
                Failure = OverloadResolution.ResolutionFailure.InvalidArgument;
                if (ReportErrors)
                {
                    string        str    = "";
                    List <string> Errors = new List <string>();
                    OverloadResolution.CanMatchArguments(TargetProcedure1, Arguments, ArgumentNames, TypeArguments, false, Errors);
                    List <string> .Enumerator enumerator = Ported.VisualBasic.CompilerServices.OverloadResolution.InitEnumerator <string>();
                    try
                    {
                        enumerator = Errors.GetEnumerator();
                        while (enumerator.MoveNext())
                        {
                            string current = enumerator.Current;
                            str = str + "\r\n    " + current;
                        }
                    }
                    finally
                    {
                        enumerator.Dispose();
                    }
                    throw new InvalidCastException(Utils.GetResourceString("MatchArgumentFailure2", TargetProcedure1.ToString(), str));
                }
                return((Symbols.Method)null);
            }
            if (TargetProcedure1.IsProperty)
            {
                if (NewLateBinding.MatchesPropertyRequirements(TargetProcedure1, LookupFlags) == null)
                {
                    Failure = OverloadResolution.ResolutionFailure.InvalidTarget;
                    if (ReportErrors)
                    {
                        throw NewLateBinding.ReportPropertyMismatch(TargetProcedure1, LookupFlags);
                    }
                    return((Symbols.Method)null);
                }
            }
            else if (Symbols.HasFlag(LookupFlags, BindingFlags.SetProperty))
            {
                Failure = OverloadResolution.ResolutionFailure.InvalidTarget;
                if (ReportErrors)
                {
                    throw new MissingMemberException(Utils.GetResourceString("MethodAssignment1", new string[1]
                    {
                        TargetProcedure1.AsMethod().Name
                    }));
                }
                return((Symbols.Method)null);
            }
            if (Symbols.HasFlag(LookupFlags, BindingFlags.SetProperty))
            {
                ParameterInfo[] parameters       = NewLateBinding.GetCallTarget(TargetProcedure1, LookupFlags).GetParameters();
                ParameterInfo   parameterInfo    = parameters[checked (parameters.Length - 1)];
                Symbols.Method  TargetProcedure2 = TargetProcedure1;
                object          obj2             = obj1;
                ParameterInfo   Parameter1       = parameterInfo;
                int             num1             = 0;
                int             num2             = 0;
                // ISSUE: variable of the null type
                object   local1 = null;
                bool     flag1  = false;
                ref bool local2 = ref flag1;
                bool     flag2  = false;
                ref bool local3 = ref flag2;