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 null;
     }
     if (Symbols.HasFlag(InvocationFlags, BindingFlags.SetProperty) && (Arguments.Length < 1))
     {
         Failure = OverloadResolution.ResolutionFailure.InvalidArgument;
         if (ReportErrors)
         {
             throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue"));
         }
         return null;
     }
     MemberInfo[] members = BaseReference.GetMembers(ref MethodName, ReportErrors);
     if ((members == null) || (members.Length == 0))
     {
         Failure = OverloadResolution.ResolutionFailure.MissingMember;
         if (ReportErrors)
         {
             members = BaseReference.GetMembers(ref MethodName, true);
         }
         return null;
     }
     Symbols.Method targetProcedure = ResolveCall(BaseReference, MethodName, members, Arguments, ArgumentNames, TypeArguments, InvocationFlags, ReportErrors, ref Failure);
     if (Failure == OverloadResolution.ResolutionFailure.None)
     {
         return BaseReference.InvokeMethod(targetProcedure, Arguments, CopyBack, InvocationFlags);
     }
     return null;
 }
Ejemplo n.º 2
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(null);
     }
     if (Symbols.HasFlag(InvocationFlags, BindingFlags.SetProperty) && (Arguments.Length < 1))
     {
         Failure = OverloadResolution.ResolutionFailure.InvalidArgument;
         if (ReportErrors)
         {
             throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue"));
         }
         return(null);
     }
     MemberInfo[] members = BaseReference.GetMembers(ref MethodName, ReportErrors);
     if ((members == null) || (members.Length == 0))
     {
         Failure = OverloadResolution.ResolutionFailure.MissingMember;
         if (ReportErrors)
         {
             members = BaseReference.GetMembers(ref MethodName, true);
         }
         return(null);
     }
     Symbols.Method targetProcedure = ResolveCall(BaseReference, MethodName, members, Arguments, ArgumentNames, TypeArguments, InvocationFlags, ReportErrors, ref Failure);
     if (Failure == OverloadResolution.ResolutionFailure.None)
     {
         return(BaseReference.InvokeMethod(targetProcedure, Arguments, CopyBack, InvocationFlags));
     }
     return(null);
 }
Ejemplo n.º 3
0
 private static void InsertInOperatorListIfLessGenericThanExisting(Symbols.Method OperatorToInsert, List <Symbols.Method> OperatorList, ref bool GenericMembersExistInList)
 {
     if (Symbols.IsGeneric(OperatorToInsert.DeclaringType))
     {
         GenericMembersExistInList = true;
     }
     if (GenericMembersExistInList)
     {
         for (int i = OperatorList.Count - 1; i >= 0; i += -1)
         {
             Symbols.Method left    = OperatorList[i];
             Symbols.Method method2 = OverloadResolution.LeastGenericProcedure(left, OperatorToInsert);
             if (method2 == left)
             {
                 return;
             }
             if (method2 != null)
             {
                 OperatorList.Remove(left);
             }
         }
     }
     OperatorList.Add(OperatorToInsert);
 }
Ejemplo n.º 4
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", new string[] { MethodName, BaseReference.VBFriendlyName }));
                }
                return(null);
            }
            int    length   = Arguments.Length;
            object argument = 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[] { MethodName }));
                    }
                    return(null);
                }
                object[] sourceArray = Arguments;
                Arguments = new object[(length - 2) + 1];
                Array.Copy(sourceArray, Arguments, Arguments.Length);
                argument = sourceArray[length - 1];
            }
            Symbols.Method targetProcedure = OverloadResolution.ResolveOverloadedCall(MethodName, Members, Arguments, ArgumentNames, TypeArguments, LookupFlags, ReportErrors, ref Failure);
            if (Failure != OverloadResolution.ResolutionFailure.None)
            {
                return(null);
            }
            if (!targetProcedure.ArgumentsValidated && !OverloadResolution.CanMatchArguments(targetProcedure, Arguments, ArgumentNames, TypeArguments, false, null))
            {
                Failure = OverloadResolution.ResolutionFailure.InvalidArgument;
                if (!ReportErrors)
                {
                    return(null);
                }
                string        str  = "";
                List <string> list = new List <string>();
                bool          flag = OverloadResolution.CanMatchArguments(targetProcedure, Arguments, ArgumentNames, TypeArguments, false, list);
                foreach (string str2 in list)
                {
                    str = str + "\r\n    " + str2;
                }
                throw new InvalidCastException(Utils.GetResourceString("MatchArgumentFailure2", new string[] { targetProcedure.ToString(), str }));
            }
            if (targetProcedure.IsProperty)
            {
                if (MatchesPropertyRequirements(targetProcedure, LookupFlags) == null)
                {
                    Failure = OverloadResolution.ResolutionFailure.InvalidTarget;
                    if (ReportErrors)
                    {
                        throw ReportPropertyMismatch(targetProcedure, LookupFlags);
                    }
                    return(null);
                }
            }
            else if (Symbols.HasFlag(LookupFlags, BindingFlags.SetProperty))
            {
                Failure = OverloadResolution.ResolutionFailure.InvalidTarget;
                if (ReportErrors)
                {
                    throw new MissingMemberException(Utils.GetResourceString("MethodAssignment1", new string[] { targetProcedure.AsMethod().Name }));
                }
                return(null);
            }
            if (!Symbols.HasFlag(LookupFlags, BindingFlags.SetProperty))
            {
                return(targetProcedure);
            }
            ParameterInfo[] parameters = GetCallTarget(targetProcedure, LookupFlags).GetParameters();
            ParameterInfo   parameter  = parameters[parameters.Length - 1];
            bool            requiresNarrowingConversion = false;
            bool            allNarrowingIsFromObject    = false;

            if (OverloadResolution.CanPassToParameter(targetProcedure, argument, parameter, false, false, null, ref requiresNarrowingConversion, ref allNarrowingIsFromObject))
            {
                return(targetProcedure);
            }
            Failure = OverloadResolution.ResolutionFailure.InvalidArgument;
            if (!ReportErrors)
            {
                return(null);
            }
            string        str3   = "";
            List <string> errors = new List <string>();

            allNarrowingIsFromObject    = false;
            requiresNarrowingConversion = false;
            bool flag2 = OverloadResolution.CanPassToParameter(targetProcedure, argument, parameter, false, false, errors, ref allNarrowingIsFromObject, ref requiresNarrowingConversion);

            foreach (string str4 in errors)
            {
                str3 = str3 + "\r\n    " + str4;
            }
            throw new InvalidCastException(Utils.GetResourceString("MatchArgumentFailure2", new string[] { targetProcedure.ToString(), str3 }));
        }
Ejemplo n.º 5
0
        internal static string PropertyToString(PropertyInfo Prop)
        {
            ParameterInfo[] parameters;
            Type            returnType;
            string          str2      = "";
            PropertyKind    readWrite = PropertyKind.ReadWrite;
            MethodInfo      getMethod = Prop.GetGetMethod();

            if (getMethod != null)
            {
                if (Prop.GetSetMethod() != null)
                {
                    readWrite = PropertyKind.ReadWrite;
                }
                else
                {
                    readWrite = PropertyKind.ReadOnly;
                }
                parameters = getMethod.GetParameters();
                returnType = getMethod.ReturnType;
            }
            else
            {
                readWrite = PropertyKind.WriteOnly;
                getMethod = Prop.GetSetMethod();
                ParameterInfo[] sourceArray = getMethod.GetParameters();
                parameters = new ParameterInfo[(sourceArray.Length - 2) + 1];
                Array.Copy(sourceArray, parameters, parameters.Length);
                returnType = sourceArray[sourceArray.Length - 1].ParameterType;
            }
            str2 = str2 + "Public ";
            if ((getMethod.Attributes & MethodAttributes.Virtual) != MethodAttributes.ReuseSlot)
            {
                if (!Prop.DeclaringType.IsInterface)
                {
                    str2 = str2 + "Overrides ";
                }
            }
            else if (Symbols.IsShared(getMethod))
            {
                str2 = str2 + "Shared ";
            }
            switch (readWrite)
            {
            case PropertyKind.ReadOnly:
                str2 = str2 + "ReadOnly ";
                break;

            case PropertyKind.WriteOnly:
                str2 = str2 + "WriteOnly ";
                break;
            }
            str2 = str2 + "Property " + Prop.Name + "(";
            bool flag = true;

            foreach (ParameterInfo info2 in parameters)
            {
                if (!flag)
                {
                    str2 = str2 + ", ";
                }
                else
                {
                    flag = false;
                }
                str2 = str2 + ParameterToString(info2);
            }
            return(str2 + ") As " + VBFriendlyNameOfType(returnType, true));
        }
 internal static object InvokeUserDefinedOperator(Symbols.UserDefinedOperator Op, object[] Arguments)
 {
     CallSiteBinder binder;
     ExpressionType? nullable = IDOUtils.LinqOperator(Op);
     if (!nullable.HasValue)
     {
         return Operators.InvokeObjectUserDefinedOperator(Op, Arguments);
     }
     ExpressionType linqOp = (ExpressionType) nullable;
     if (Arguments.Length == 1)
     {
         binder = new VBUnaryOperatorBinder(Op, linqOp);
     }
     else
     {
         binder = new VBBinaryOperatorBinder(Op, linqOp);
     }
     object instance = Arguments[0];
     object[] arguments = (Arguments.Length == 1) ? Symbols.NoArguments : new object[] { Arguments[1] };
     return IDOUtils.CreateFuncCallSiteAndInvoke(binder, instance, arguments);
 }
 internal static Exception ReportPropertyMismatch(Symbols.Method TargetProcedure, BindingFlags Flags)
 {
     if (Symbols.HasFlag(Flags, BindingFlags.SetProperty))
     {
         return new MissingMemberException(Utils.GetResourceString("NoSetProperty1", new string[] { TargetProcedure.AsProperty().Name }));
     }
     return new MissingMemberException(Utils.GetResourceString("NoGetProperty1", new string[] { TargetProcedure.AsProperty().Name }));
 }
        internal static ExpressionType? LinqOperator(Symbols.UserDefinedOperator vbOperator)
        {
            ExpressionType? nullable2;
            switch (vbOperator)
            {
                case Symbols.UserDefinedOperator.Negate:
                    return 0x1c;

                case Symbols.UserDefinedOperator.Not:
                    return 0x22;

                case Symbols.UserDefinedOperator.UnaryPlus:
                    return 0x1d;

                case Symbols.UserDefinedOperator.Plus:
                    return 0;

                case Symbols.UserDefinedOperator.Minus:
                    return 0x2a;

                case Symbols.UserDefinedOperator.Multiply:
                    return 0x1a;

                case Symbols.UserDefinedOperator.Divide:
                    return 12;

                case Symbols.UserDefinedOperator.Power:
                    return 0x27;

                case Symbols.UserDefinedOperator.IntegralDivide:
                case Symbols.UserDefinedOperator.Concatenate:
                case Symbols.UserDefinedOperator.Like:
                    return nullable2;

                case Symbols.UserDefinedOperator.ShiftLeft:
                    return 0x13;

                case Symbols.UserDefinedOperator.ShiftRight:
                    return 0x29;

                case Symbols.UserDefinedOperator.Modulus:
                    return 0x19;

                case Symbols.UserDefinedOperator.Or:
                    return 0x24;

                case Symbols.UserDefinedOperator.Xor:
                    return 14;

                case Symbols.UserDefinedOperator.And:
                    return 2;

                case Symbols.UserDefinedOperator.Equal:
                    return 13;

                case Symbols.UserDefinedOperator.NotEqual:
                    return 0x23;

                case Symbols.UserDefinedOperator.Less:
                    return 20;

                case Symbols.UserDefinedOperator.LessEqual:
                    return 0x15;

                case Symbols.UserDefinedOperator.GreaterEqual:
                    return 0x10;

                case Symbols.UserDefinedOperator.Greater:
                    return 15;
            }
            return nullable2;
        }
 internal static bool InferTypeArgumentsFromArgument(Symbols.Method TargetProcedure, object Argument, ParameterInfo Parameter, bool IsExpandedParamArray, List<string> Errors)
 {
     if (Argument == null)
     {
         return true;
     }
     Type parameterType = Parameter.ParameterType;
     if (parameterType.IsByRef || IsExpandedParamArray)
     {
         parameterType = Symbols.GetElementType(parameterType);
     }
     if (InferTypeArgumentsFromArgument(GetArgumentTypeInContextOfParameterType(Argument, parameterType), parameterType, TargetProcedure.TypeArguments, TargetProcedure.AsMethod(), true))
     {
         return true;
     }
     if (Errors != null)
     {
         ReportError(Errors, "TypeInferenceFails1", Parameter.Name);
     }
     return false;
 }
 internal static MethodBase GetCallTarget(Symbols.Method TargetProcedure, BindingFlags Flags)
 {
     if (TargetProcedure.IsMethod)
     {
         return TargetProcedure.AsMethod();
     }
     if (TargetProcedure.IsProperty)
     {
         return MatchesPropertyRequirements(TargetProcedure, Flags);
     }
     return null;
 }
 private static bool DetectUnspecificity(Symbols.Method TargetProcedure, object[] Arguments, string[] ArgumentNames, Type[] TypeArguments, List<string> Errors)
 {
     ReportError(Errors, "NotMostSpecificOverload");
     return false;
 }
            private static Symbols.Method VerifyForLoopOperator(Symbols.UserDefinedOperator Op, object ForLoopArgument, Type ForLoopArgumentType)
            {
                Symbols.Method callableUserDefinedOperator = Operators.GetCallableUserDefinedOperator(Op, new object[] { ForLoopArgument, ForLoopArgument });
                if (callableUserDefinedOperator == null)
                {
                    throw new ArgumentException(Utils.GetResourceString("ForLoop_OperatorRequired2", new string[] { Utils.VBFriendlyNameOfType(ForLoopArgumentType, true), Symbols.OperatorNames[(int) Op] }));
                }
                MethodInfo info = callableUserDefinedOperator.AsMethod() as MethodInfo;
                ParameterInfo[] parameters = info.GetParameters();
                switch (Op)
                {
                    case Symbols.UserDefinedOperator.Plus:
                    case Symbols.UserDefinedOperator.Minus:
                        if (((parameters.Length != 2) || (parameters[0].ParameterType != ForLoopArgumentType)) || ((parameters[1].ParameterType != ForLoopArgumentType) || (info.ReturnType != ForLoopArgumentType)))
                        {
                            throw new ArgumentException(Utils.GetResourceString("ForLoop_UnacceptableOperator2", new string[] { callableUserDefinedOperator.ToString(), Utils.VBFriendlyNameOfType(ForLoopArgumentType, true) }));
                        }
                        return callableUserDefinedOperator;

                    case Symbols.UserDefinedOperator.Multiply:
                    case Symbols.UserDefinedOperator.Divide:
                    case Symbols.UserDefinedOperator.Power:
                    case Symbols.UserDefinedOperator.IntegralDivide:
                    case Symbols.UserDefinedOperator.Concatenate:
                    case Symbols.UserDefinedOperator.ShiftLeft:
                    case Symbols.UserDefinedOperator.ShiftRight:
                    case Symbols.UserDefinedOperator.Modulus:
                    case Symbols.UserDefinedOperator.Or:
                    case Symbols.UserDefinedOperator.Xor:
                    case Symbols.UserDefinedOperator.And:
                    case Symbols.UserDefinedOperator.Like:
                    case Symbols.UserDefinedOperator.Equal:
                    case Symbols.UserDefinedOperator.NotEqual:
                    case Symbols.UserDefinedOperator.Less:
                        return callableUserDefinedOperator;

                    case Symbols.UserDefinedOperator.LessEqual:
                    case Symbols.UserDefinedOperator.GreaterEqual:
                        if (((parameters.Length != 2) || (parameters[0].ParameterType != ForLoopArgumentType)) || (parameters[1].ParameterType != ForLoopArgumentType))
                        {
                            throw new ArgumentException(Utils.GetResourceString("ForLoop_UnacceptableRelOperator2", new string[] { callableUserDefinedOperator.ToString(), Utils.VBFriendlyNameOfType(ForLoopArgumentType, true) }));
                        }
                        return callableUserDefinedOperator;
                }
                return callableUserDefinedOperator;
            }
 internal static List<Symbols.Method> CollectOperators(Symbols.UserDefinedOperator Op, Type Type1, Type Type2, ref bool FoundType1Operators, ref bool FoundType2Operators)
 {
     List<Symbols.Method> list2;
     int num;
     int num2;
     bool flag = Type2 != null;
     if (!Symbols.IsRootObjectType(Type1) && Symbols.IsClassOrValueType(Type1))
     {
         Symbols.Container container = new Symbols.Container(Type1);
         num = 0;
         num2 = 0;
         list2 = OverloadResolution.CollectOverloadCandidates(container.LookupNamedMembers(Symbols.OperatorCLSNames[(int) Op]), null, Interaction.IIf<int>(Symbols.IsUnaryOperator(Op), 1, 2), null, null, true, null, ref num, ref num2);
         if (list2.Count > 0)
         {
             FoundType1Operators = true;
         }
     }
     else
     {
         list2 = new List<Symbols.Method>();
     }
     if ((flag && !Symbols.IsRootObjectType(Type2)) && Symbols.IsClassOrValueType(Type2))
     {
         Type baseType = Type1;
         while (baseType != null)
         {
             if (Symbols.IsOrInheritsFrom(Type2, baseType))
             {
                 break;
             }
             baseType = baseType.BaseType;
         }
         Symbols.Container container2 = new Symbols.Container(Type2);
         num2 = 0;
         num = 0;
         List<Symbols.Method> collection = OverloadResolution.CollectOverloadCandidates(container2.LookupNamedMembers(Symbols.OperatorCLSNames[(int) Op]), null, Interaction.IIf<int>(Symbols.IsUnaryOperator(Op), 1, 2), null, null, true, baseType, ref num2, ref num);
         if (collection.Count > 0)
         {
             FoundType2Operators = true;
         }
         list2.AddRange(collection);
     }
     return list2;
 }
 internal static Symbols.Method GetCallableUserDefinedOperator(Symbols.UserDefinedOperator Op, params object[] Arguments)
 {
     Symbols.Method targetProcedure = ResolveUserDefinedOperator(Op, Arguments, false);
     if (((targetProcedure != null) && !targetProcedure.ArgumentsValidated) && !OverloadResolution.CanMatchArguments(targetProcedure, Arguments, Symbols.NoArgumentNames, Symbols.NoTypeArguments, false, null))
     {
         return null;
     }
     return targetProcedure;
 }
 internal bool Lookup(Type TargetType, Type SourceType, ref ConversionResolution.ConversionClass Classification, ref Symbols.Method OperatorMethod)
 {
     int first = this.m_First;
     for (int i = 0; i < this.m_Count; i++)
     {
         if ((TargetType == this.m_List[first].TargetType) && (SourceType == this.m_List[first].SourceType))
         {
             Classification = this.m_List[first].Classification;
             OperatorMethod = this.m_List[first].OperatorMethod;
             this.MoveToFront(first);
             return true;
         }
         first = this.m_List[first].Next;
     }
     Classification = ConversionResolution.ConversionClass.Bad;
     OperatorMethod = null;
     return false;
 }
 internal void Insert(Type TargetType, Type SourceType, ConversionResolution.ConversionClass Classification, Symbols.Method OperatorMethod)
 {
     if (this.m_Count < this.m_Size)
     {
         this.m_Count++;
     }
     int last = this.m_Last;
     this.m_First = last;
     this.m_Last = this.m_List[this.m_Last].Previous;
     this.m_List[last].TargetType = TargetType;
     this.m_List[last].SourceType = SourceType;
     this.m_List[last].Classification = Classification;
     this.m_List[last].OperatorMethod = OperatorMethod;
 }
 internal object InvokeMethod(Symbols.Method TargetProcedure, object[] Arguments, bool[] CopyBack, BindingFlags Flags)
 {
     object obj3;
     MethodBase callTarget = NewLateBinding.GetCallTarget(TargetProcedure, Flags);
     object[] parameters = NewLateBinding.ConstructCallArguments(TargetProcedure, Arguments, Flags);
     if ((this.m_Instance == null) && !Symbols.IsShared(callTarget))
     {
         throw new NullReferenceException(Utils.GetResourceString("NullReference_InstanceReqToAccessMember1", new string[] { TargetProcedure.ToString() }));
     }
     if (Symbols.IsNonPublicRuntimeMember(callTarget))
     {
         throw new MissingMemberException();
     }
     try
     {
         obj3 = callTarget.Invoke(this.m_Instance, parameters);
     }
     catch when (?)
     {
         TargetInvocationException exception;
         throw exception.InnerException;
     }
     OverloadResolution.ReorderArgumentArray(TargetProcedure, parameters, Arguments, CopyBack, Flags);
     return obj3;
 }
Ejemplo n.º 18
0
 internal static ConversionClass ClassifyPredefinedCLRConversion(Type TargetType, Type SourceType)
 {
     if (TargetType == SourceType)
     {
         return(ConversionClass.Identity);
     }
     if (Symbols.IsRootObjectType(TargetType) || Symbols.IsOrInheritsFrom(SourceType, TargetType))
     {
         return(ConversionClass.Widening);
     }
     if (Symbols.IsRootObjectType(SourceType) || Symbols.IsOrInheritsFrom(TargetType, SourceType))
     {
         return(ConversionClass.Narrowing);
     }
     if (Symbols.IsInterface(SourceType))
     {
         if ((Symbols.IsClass(TargetType) || Symbols.IsArrayType(TargetType)) || Symbols.IsGenericParameter(TargetType))
         {
             return(ConversionClass.Narrowing);
         }
         if (Symbols.IsInterface(TargetType))
         {
             return(ConversionClass.Narrowing);
         }
         if (!Symbols.IsValueType(TargetType))
         {
             return(ConversionClass.Narrowing);
         }
         if (Symbols.Implements(TargetType, SourceType))
         {
             return(ConversionClass.Narrowing);
         }
         return(ConversionClass.None);
     }
     if (Symbols.IsInterface(TargetType))
     {
         if (Symbols.IsArrayType(SourceType))
         {
             return(ClassifyCLRArrayToInterfaceConversion(TargetType, SourceType));
         }
         if (Symbols.IsValueType(SourceType))
         {
             if (Symbols.Implements(SourceType, TargetType))
             {
                 return(ConversionClass.Widening);
             }
             return(ConversionClass.None);
         }
         if (Symbols.IsClass(SourceType))
         {
             if (Symbols.Implements(SourceType, TargetType))
             {
                 return(ConversionClass.Widening);
             }
             return(ConversionClass.Narrowing);
         }
     }
     if (Symbols.IsEnum(SourceType) || Symbols.IsEnum(TargetType))
     {
         if (Symbols.GetTypeCode(SourceType) != Symbols.GetTypeCode(TargetType))
         {
             return(ConversionClass.None);
         }
         if (Symbols.IsEnum(TargetType))
         {
             return(ConversionClass.Narrowing);
         }
         return(ConversionClass.Widening);
     }
     if (Symbols.IsGenericParameter(SourceType))
     {
         if (!Symbols.IsClassOrInterface(TargetType))
         {
             return(ConversionClass.None);
         }
         foreach (Type type2 in Symbols.GetInterfaceConstraints(SourceType))
         {
             switch (ClassifyPredefinedConversion(TargetType, type2))
             {
             case ConversionClass.Widening:
             case ConversionClass.Identity:
                 return(ConversionClass.Widening);
             }
         }
         Type classConstraint = Symbols.GetClassConstraint(SourceType);
         if (classConstraint != null)
         {
             switch (ClassifyPredefinedConversion(TargetType, classConstraint))
             {
             case ConversionClass.Widening:
             case ConversionClass.Identity:
                 return(ConversionClass.Widening);
             }
         }
         return(Interaction.IIf <ConversionClass>(Symbols.IsInterface(TargetType), ConversionClass.Narrowing, ConversionClass.None));
     }
     if (Symbols.IsGenericParameter(TargetType))
     {
         Type derived = Symbols.GetClassConstraint(TargetType);
         if ((derived != null) && Symbols.IsOrInheritsFrom(derived, SourceType))
         {
             return(ConversionClass.Narrowing);
         }
         return(ConversionClass.None);
     }
     if ((Symbols.IsArrayType(SourceType) && Symbols.IsArrayType(TargetType)) && (SourceType.GetArrayRank() == TargetType.GetArrayRank()))
     {
         return(ClassifyCLRConversionForArrayElementTypes(TargetType.GetElementType(), SourceType.GetElementType()));
     }
     return(ConversionClass.None);
 }
 internal static bool CanMatchArguments(Symbols.Method TargetProcedure, object[] Arguments, string[] ArgumentNames, Type[] TypeArguments, bool RejectNarrowingConversions, List<string> Errors)
 {
     bool flag2 = Errors != null;
     TargetProcedure.ArgumentsValidated = true;
     if (TargetProcedure.IsMethod && Symbols.IsRawGeneric(TargetProcedure.AsMethod()))
     {
         if (TypeArguments.Length == 0)
         {
             TypeArguments = new Type[(TargetProcedure.TypeParameters.Length - 1) + 1];
             TargetProcedure.TypeArguments = TypeArguments;
             if (!InferTypeArguments(TargetProcedure, Arguments, ArgumentNames, TypeArguments, Errors))
             {
                 return false;
             }
         }
         else
         {
             TargetProcedure.TypeArguments = TypeArguments;
         }
         if (!InstantiateGenericMethod(TargetProcedure, TypeArguments, Errors))
         {
             return false;
         }
     }
     ParameterInfo[] parameters = TargetProcedure.Parameters;
     int length = ArgumentNames.Length;
     int index = 0;
     while (length < Arguments.Length)
     {
         if (index == TargetProcedure.ParamArrayIndex)
         {
             break;
         }
         if (!CanPassToParameter(TargetProcedure, Arguments[length], parameters[index], false, RejectNarrowingConversions, Errors, ref TargetProcedure.RequiresNarrowingConversion, ref TargetProcedure.AllNarrowingIsFromObject) && !flag2)
         {
             return false;
         }
         length++;
         index++;
     }
     if (TargetProcedure.HasParamArray)
     {
         if (!TargetProcedure.ParamArrayExpanded)
         {
             if ((Arguments.Length - length) != 1)
             {
                 return false;
             }
             if (!CanPassToParamArray(TargetProcedure, Arguments[length], parameters[index]))
             {
                 if (flag2)
                 {
                     ReportError(Errors, "ArgumentMismatch3", parameters[index].Name, GetArgumentTypeInContextOfParameterType(Arguments[length], parameters[index].ParameterType), parameters[index].ParameterType);
                 }
                 return false;
             }
         }
         else if ((length != (Arguments.Length - 1)) || (Arguments[length] != null))
         {
             while (length < Arguments.Length)
             {
                 if (!CanPassToParameter(TargetProcedure, Arguments[length], parameters[index], true, RejectNarrowingConversions, Errors, ref TargetProcedure.RequiresNarrowingConversion, ref TargetProcedure.AllNarrowingIsFromObject) && !flag2)
                 {
                     return false;
                 }
                 length++;
             }
         }
         else
         {
             return false;
         }
         index++;
     }
     bool[] flagArray = null;
     if ((ArgumentNames.Length > 0) || (index < parameters.Length))
     {
         flagArray = CreateMatchTable(parameters.Length, index - 1);
     }
     if (ArgumentNames.Length > 0)
     {
         int[] numArray = new int[(ArgumentNames.Length - 1) + 1];
         for (length = 0; length < ArgumentNames.Length; length++)
         {
             if (!FindParameterByName(parameters, ArgumentNames[length], ref index))
             {
                 if (!flag2)
                 {
                     return false;
                 }
                 ReportError(Errors, "NamedParamNotFound2", ArgumentNames[length], TargetProcedure);
             }
             else if (index == TargetProcedure.ParamArrayIndex)
             {
                 if (!flag2)
                 {
                     return false;
                 }
                 ReportError(Errors, "NamedParamArrayArgument1", ArgumentNames[length]);
             }
             else if (flagArray[index])
             {
                 if (!flag2)
                 {
                     return false;
                 }
                 ReportError(Errors, "NamedArgUsedTwice2", ArgumentNames[length], TargetProcedure);
             }
             else
             {
                 if (!CanPassToParameter(TargetProcedure, Arguments[length], parameters[index], false, RejectNarrowingConversions, Errors, ref TargetProcedure.RequiresNarrowingConversion, ref TargetProcedure.AllNarrowingIsFromObject) && !flag2)
                 {
                     return false;
                 }
                 flagArray[index] = true;
                 numArray[length] = index;
             }
         }
         TargetProcedure.NamedArgumentMapping = numArray;
     }
     if (flagArray != null)
     {
         int num4 = flagArray.Length - 1;
         for (int i = 0; i <= num4; i++)
         {
             if (!flagArray[i] && !parameters[i].IsOptional)
             {
                 if (!flag2)
                 {
                     return false;
                 }
                 ReportError(Errors, "OmittedArgument1", parameters[i].Name);
             }
         }
     }
     if ((Errors != null) && (Errors.Count > 0))
     {
         return false;
     }
     return true;
 }
 private static Exception GetNoValidOperatorException(Symbols.UserDefinedOperator Op, object Operand)
 {
     return new InvalidCastException(Utils.GetResourceString("UnaryOperand2", new string[] { Symbols.OperatorNames[(int) Op], Utils.VBFriendlyName(Operand) }));
 }
 private static bool InferTypeArguments(Symbols.Method TargetProcedure, object[] Arguments, string[] ArgumentNames, Type[] TypeArguments, List<string> Errors)
 {
     bool flag2 = Errors != null;
     ParameterInfo[] rawParameters = TargetProcedure.RawParameters;
     int length = ArgumentNames.Length;
     int index = 0;
     while (length < Arguments.Length)
     {
         if (index == TargetProcedure.ParamArrayIndex)
         {
             break;
         }
         if (!InferTypeArgumentsFromArgument(TargetProcedure, Arguments[length], rawParameters[index], false, Errors) && !flag2)
         {
             return false;
         }
         length++;
         index++;
     }
     if (TargetProcedure.HasParamArray)
     {
         if (TargetProcedure.ParamArrayExpanded)
         {
             while (length < Arguments.Length)
             {
                 if (!InferTypeArgumentsFromArgument(TargetProcedure, Arguments[length], rawParameters[index], true, Errors) && !flag2)
                 {
                     return false;
                 }
                 length++;
             }
         }
         else
         {
             if ((Arguments.Length - length) != 1)
             {
                 return true;
             }
             if (!InferTypeArgumentsFromArgument(TargetProcedure, Arguments[length], rawParameters[index], false, Errors))
             {
                 return false;
             }
         }
         index++;
     }
     if (ArgumentNames.Length > 0)
     {
         for (length = 0; length < ArgumentNames.Length; length++)
         {
             if ((FindParameterByName(rawParameters, ArgumentNames[length], ref index) && (index != TargetProcedure.ParamArrayIndex)) && (!InferTypeArgumentsFromArgument(TargetProcedure, Arguments[length], rawParameters[index], false, Errors) && !flag2))
             {
                 return false;
             }
         }
     }
     if ((Errors != null) && (Errors.Count > 0))
     {
         return false;
     }
     return true;
 }
 private static void InsertInOperatorListIfLessGenericThanExisting(Symbols.Method OperatorToInsert, List<Symbols.Method> OperatorList, ref bool GenericMembersExistInList)
 {
     if (Symbols.IsGeneric(OperatorToInsert.DeclaringType))
     {
         GenericMembersExistInList = true;
     }
     if (GenericMembersExistInList)
     {
         for (int i = OperatorList.Count - 1; i >= 0; i += -1)
         {
             Symbols.Method left = OperatorList[i];
             Symbols.Method method2 = OverloadResolution.LeastGenericProcedure(left, OperatorToInsert);
             if (method2 == left)
             {
                 return;
             }
             if (method2 != null)
             {
                 OperatorList.Remove(left);
             }
         }
     }
     OperatorList.Add(OperatorToInsert);
 }
 private static Exception GetNoValidOperatorException(Symbols.UserDefinedOperator Op, object Left, object Right)
 {
     string resourceString;
     string str2;
     if (Left == null)
     {
         resourceString = "'Nothing'";
     }
     else
     {
         string str3 = Left as string;
         if (str3 != null)
         {
             resourceString = Utils.GetResourceString("NoValidOperator_StringType1", new string[] { Strings.Left(str3, 0x20) });
         }
         else
         {
             resourceString = Utils.GetResourceString("NoValidOperator_NonStringType1", new string[] { Utils.VBFriendlyName(Left) });
         }
     }
     if (Right == null)
     {
         str2 = "'Nothing'";
     }
     else
     {
         string str = Right as string;
         if (str != null)
         {
             str2 = Utils.GetResourceString("NoValidOperator_StringType1", new string[] { Strings.Left(str, 0x20) });
         }
         else
         {
             str2 = Utils.GetResourceString("NoValidOperator_NonStringType1", new string[] { Utils.VBFriendlyName(Right) });
         }
     }
     return new InvalidCastException(Utils.GetResourceString("BinaryOperands3", new string[] { Symbols.OperatorNames[(int) Op], resourceString, str2 }));
 }
Ejemplo n.º 24
0
            private static MemberInfo[] FilterInvalidMembers(MemberInfo[] Members)
            {
                if ((Members == null) || (Members.Length == 0))
                {
                    return(null);
                }
                int num2  = 0;
                int index = 0;
                int num4  = Members.Length - 1;

                for (index = 0; index <= num4; index++)
                {
                    PropertyInfo    info3;
                    ParameterInfo[] destinationArray = null;
                    Type            returnType       = null;
                    switch (Members[index].MemberType)
                    {
                    case MemberTypes.Constructor:
                    case MemberTypes.Method:
                    {
                        MethodInfo info = (MethodInfo)Members[index];
                        destinationArray = info.GetParameters();
                        returnType       = info.ReturnType;
                        goto Label_00F9;
                    }

                    case MemberTypes.Field:
                        returnType = ((FieldInfo)Members[index]).FieldType;
                        goto Label_00F9;

                    case MemberTypes.Property:
                    {
                        info3 = (PropertyInfo)Members[index];
                        MethodInfo getMethod = info3.GetGetMethod();
                        if (getMethod == null)
                        {
                            break;
                        }
                        destinationArray = getMethod.GetParameters();
                        goto Label_00DF;
                    }

                    default:
                        goto Label_00F9;
                    }
                    ParameterInfo[] parameters = info3.GetSetMethod().GetParameters();
                    destinationArray = new ParameterInfo[(parameters.Length - 2) + 1];
                    Array.Copy(parameters, destinationArray, destinationArray.Length);
Label_00DF:
                    returnType = info3.PropertyType;
Label_00F9:
                    if (Symbols.AreParametersAndReturnTypesValid(destinationArray, returnType))
                    {
                        num2++;
                    }
                    else
                    {
                        Members[index] = null;
                    }
                }
                if (num2 == Members.Length)
                {
                    return(Members);
                }
                if (num2 <= 0)
                {
                    return(null);
                }
                MemberInfo[] infoArray4 = new MemberInfo[(num2 - 1) + 1];
                int          num3       = 0;
                int          num5       = Members.Length - 1;

                for (index = 0; index <= num5; index++)
                {
                    if (Members[index] != null)
                    {
                        infoArray4[num3] = Members[index];
                        num3++;
                    }
                }
                return(infoArray4);
            }
 internal static object InvokeObjectUserDefinedOperator(Symbols.UserDefinedOperator Op, object[] Arguments)
 {
     Symbols.Method operatorMethod = ResolveUserDefinedOperator(Op, Arguments, true);
     if (operatorMethod != null)
     {
         return InvokeUserDefinedOperator(operatorMethod, false, Arguments);
     }
     if (Arguments.Length > 1)
     {
         throw GetNoValidOperatorException(Op, Arguments[0], Arguments[1]);
     }
     throw GetNoValidOperatorException(Op, Arguments[0]);
 }
 internal static object[] ConstructCallArguments(Symbols.Method TargetProcedure, object[] Arguments, BindingFlags LookupFlags)
 {
     ParameterInfo[] parameters = GetCallTarget(TargetProcedure, LookupFlags).GetParameters();
     object[] matchedArguments = new object[(parameters.Length - 1) + 1];
     int length = Arguments.Length;
     object argument = null;
     if (Symbols.HasFlag(LookupFlags, BindingFlags.SetProperty))
     {
         object[] sourceArray = Arguments;
         Arguments = new object[(length - 2) + 1];
         Array.Copy(sourceArray, Arguments, Arguments.Length);
         argument = sourceArray[length - 1];
     }
     OverloadResolution.MatchArguments(TargetProcedure, Arguments, matchedArguments);
     if (Symbols.HasFlag(LookupFlags, BindingFlags.SetProperty))
     {
         ParameterInfo parameter = parameters[parameters.Length - 1];
         matchedArguments[parameters.Length - 1] = OverloadResolution.PassToParameter(argument, parameter, parameter.ParameterType);
     }
     return matchedArguments;
 }
 internal static object InvokeUserDefinedOperator(Symbols.UserDefinedOperator Op, params object[] Arguments)
 {
     if (IDOUtils.TryCastToIDMOP(Arguments[0]) != null)
     {
         return IDOBinder.InvokeUserDefinedOperator(Op, Arguments);
     }
     return InvokeObjectUserDefinedOperator(Op, Arguments);
 }
 internal static MethodInfo MatchesPropertyRequirements(Symbols.Method TargetProcedure, BindingFlags Flags)
 {
     if (Symbols.HasFlag(Flags, BindingFlags.SetProperty))
     {
         return TargetProcedure.AsProperty().GetSetMethod();
     }
     return TargetProcedure.AsProperty().GetGetMethod();
 }
 internal static object InvokeUserDefinedOperator(Symbols.Method OperatorMethod, bool ForceArgumentValidation, params object[] Arguments)
 {
     if ((!OperatorMethod.ArgumentsValidated || ForceArgumentValidation) && !OverloadResolution.CanMatchArguments(OperatorMethod, Arguments, Symbols.NoArgumentNames, Symbols.NoTypeArguments, false, null))
     {
         string str = "";
         List<string> errors = new List<string>();
         bool flag = OverloadResolution.CanMatchArguments(OperatorMethod, Arguments, Symbols.NoArgumentNames, Symbols.NoTypeArguments, false, errors);
         foreach (string str2 in errors)
         {
             str = str + "\r\n    " + str2;
         }
         throw new InvalidCastException(Utils.GetResourceString("MatchArgumentFailure2", new string[] { OperatorMethod.ToString(), str }));
     }
     Symbols.Container container = new Symbols.Container(OperatorMethod.DeclaringType);
     return container.InvokeMethod(OperatorMethod, Arguments, null, BindingFlags.InvokeMethod);
 }
 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", new string[] { MethodName, BaseReference.VBFriendlyName }));
         }
         return null;
     }
     int length = Arguments.Length;
     object argument = 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[] { MethodName }));
             }
             return null;
         }
         object[] sourceArray = Arguments;
         Arguments = new object[(length - 2) + 1];
         Array.Copy(sourceArray, Arguments, Arguments.Length);
         argument = sourceArray[length - 1];
     }
     Symbols.Method targetProcedure = OverloadResolution.ResolveOverloadedCall(MethodName, Members, Arguments, ArgumentNames, TypeArguments, LookupFlags, ReportErrors, ref Failure);
     if (Failure != OverloadResolution.ResolutionFailure.None)
     {
         return null;
     }
     if (!targetProcedure.ArgumentsValidated && !OverloadResolution.CanMatchArguments(targetProcedure, Arguments, ArgumentNames, TypeArguments, false, null))
     {
         Failure = OverloadResolution.ResolutionFailure.InvalidArgument;
         if (!ReportErrors)
         {
             return null;
         }
         string str = "";
         List<string> list = new List<string>();
         bool flag = OverloadResolution.CanMatchArguments(targetProcedure, Arguments, ArgumentNames, TypeArguments, false, list);
         foreach (string str2 in list)
         {
             str = str + "\r\n    " + str2;
         }
         throw new InvalidCastException(Utils.GetResourceString("MatchArgumentFailure2", new string[] { targetProcedure.ToString(), str }));
     }
     if (targetProcedure.IsProperty)
     {
         if (MatchesPropertyRequirements(targetProcedure, LookupFlags) == null)
         {
             Failure = OverloadResolution.ResolutionFailure.InvalidTarget;
             if (ReportErrors)
             {
                 throw ReportPropertyMismatch(targetProcedure, LookupFlags);
             }
             return null;
         }
     }
     else if (Symbols.HasFlag(LookupFlags, BindingFlags.SetProperty))
     {
         Failure = OverloadResolution.ResolutionFailure.InvalidTarget;
         if (ReportErrors)
         {
             throw new MissingMemberException(Utils.GetResourceString("MethodAssignment1", new string[] { targetProcedure.AsMethod().Name }));
         }
         return null;
     }
     if (!Symbols.HasFlag(LookupFlags, BindingFlags.SetProperty))
     {
         return targetProcedure;
     }
     ParameterInfo[] parameters = GetCallTarget(targetProcedure, LookupFlags).GetParameters();
     ParameterInfo parameter = parameters[parameters.Length - 1];
     bool requiresNarrowingConversion = false;
     bool allNarrowingIsFromObject = false;
     if (OverloadResolution.CanPassToParameter(targetProcedure, argument, parameter, false, false, null, ref requiresNarrowingConversion, ref allNarrowingIsFromObject))
     {
         return targetProcedure;
     }
     Failure = OverloadResolution.ResolutionFailure.InvalidArgument;
     if (!ReportErrors)
     {
         return null;
     }
     string str3 = "";
     List<string> errors = new List<string>();
     allNarrowingIsFromObject = false;
     requiresNarrowingConversion = false;
     bool flag2 = OverloadResolution.CanPassToParameter(targetProcedure, argument, parameter, false, false, errors, ref allNarrowingIsFromObject, ref requiresNarrowingConversion);
     foreach (string str4 in errors)
     {
         str3 = str3 + "\r\n    " + str4;
     }
     throw new InvalidCastException(Utils.GetResourceString("MatchArgumentFailure2", new string[] { targetProcedure.ToString(), str3 }));
 }
 internal static Symbols.Method ResolveUserDefinedOperator(Symbols.UserDefinedOperator Op, object[] Arguments, bool ReportErrors)
 {
     bool flag;
     bool flag2;
     Type type;
     Arguments = (object[]) Arguments.Clone();
     Type type2 = null;
     if (Arguments[0] == null)
     {
         type2 = Arguments[1].GetType();
         type = type2;
         Arguments[0] = new Symbols.TypedNothing(type);
     }
     else
     {
         type = Arguments[0].GetType();
         if (Arguments.Length > 1)
         {
             if (Arguments[1] != null)
             {
                 type2 = Arguments[1].GetType();
             }
             else
             {
                 type2 = type;
                 Arguments[1] = new Symbols.TypedNothing(type2);
             }
         }
     }
     List<Symbols.Method> candidates = CollectOperators(Op, type, type2, ref flag, ref flag2);
     if (candidates.Count > 0)
     {
         OverloadResolution.ResolutionFailure failure;
         return OverloadResolution.ResolveOverloadedCall(Symbols.OperatorNames[(int) Op], candidates, Arguments, Symbols.NoArgumentNames, Symbols.NoTypeArguments, BindingFlags.InvokeMethod, ReportErrors, ref failure);
     }
     return null;
 }
Ejemplo n.º 32
0
        public static string MethodToString(MethodBase Method)
        {
            bool   flag;
            Type   typ = null;
            string str = "";

            if (Method.MemberType == MemberTypes.Method)
            {
                typ = ((MethodInfo)Method).ReturnType;
            }
            if (Method.IsPublic)
            {
                str = str + "Public ";
            }
            else if (Method.IsPrivate)
            {
                str = str + "Private ";
            }
            else if (Method.IsAssembly)
            {
                str = str + "Friend ";
            }
            if ((Method.Attributes & MethodAttributes.Virtual) != MethodAttributes.ReuseSlot)
            {
                if (!Method.DeclaringType.IsInterface)
                {
                    str = str + "Overrides ";
                }
            }
            else if (Symbols.IsShared(Method))
            {
                str = str + "Shared ";
            }
            Symbols.UserDefinedOperator uNDEF = Symbols.UserDefinedOperator.UNDEF;
            if (Symbols.IsUserDefinedOperator(Method))
            {
                uNDEF = Symbols.MapToUserDefinedOperator(Method);
            }
            if (uNDEF != Symbols.UserDefinedOperator.UNDEF)
            {
                if (uNDEF == Symbols.UserDefinedOperator.Narrow)
                {
                    str = str + "Narrowing ";
                }
                else if (uNDEF == Symbols.UserDefinedOperator.Widen)
                {
                    str = str + "Widening ";
                }
                str = str + "Operator ";
            }
            else if ((typ == null) || (typ == VoidType))
            {
                str = str + "Sub ";
            }
            else
            {
                str = str + "Function ";
            }
            if (uNDEF != Symbols.UserDefinedOperator.UNDEF)
            {
                str = str + Symbols.OperatorNames[(int)uNDEF];
            }
            else if (Method.MemberType == MemberTypes.Constructor)
            {
                str = str + "New";
            }
            else
            {
                str = str + Method.Name;
            }
            if (Symbols.IsGeneric(Method))
            {
                str  = str + "(Of ";
                flag = true;
                foreach (Type type2 in Symbols.GetTypeParameters(Method))
                {
                    if (!flag)
                    {
                        str = str + ", ";
                    }
                    else
                    {
                        flag = false;
                    }
                    str = str + VBFriendlyNameOfType(type2, false);
                }
                str = str + ")";
            }
            str  = str + "(";
            flag = true;
            foreach (ParameterInfo info in Method.GetParameters())
            {
                if (!flag)
                {
                    str = str + ", ";
                }
                else
                {
                    flag = false;
                }
                str = str + ParameterToString(info);
            }
            str = str + ")";
            if ((typ == null) || (typ == VoidType))
            {
                return(str);
            }
            return(str + " As " + VBFriendlyNameOfType(typ, true));
        }
Ejemplo n.º 33
0
            public static bool ForNextCheckObj(object Counter, object LoopObj, ref object CounterResult)
            {
                if (LoopObj == null)
                {
                    throw ExceptionUtils.VbMakeException(0x5c);
                }
                if (Counter == null)
                {
                    throw new NullReferenceException(Utils.GetResourceString("Argument_InvalidNullValue1", new string[] { "Counter" }));
                }
                ObjectFlowControl.ForLoopControl loopFor = (ObjectFlowControl.ForLoopControl)LoopObj;
                bool flag2 = false;

                if (!loopFor.UseUserDefinedOperators)
                {
                    TypeCode typeCode = ((IConvertible)Counter).GetTypeCode();
                    if ((typeCode != loopFor.WidestTypeCode) || (typeCode == TypeCode.String))
                    {
                        if (typeCode == TypeCode.Object)
                        {
                            throw new ArgumentException(Utils.GetResourceString("ForLoop_CommonType2", new string[] { Utils.VBFriendlyName(Symbols.MapTypeCodeToType(typeCode)), Utils.VBFriendlyName(loopFor.WidestType) }));
                        }
                        TypeCode code2 = Symbols.GetTypeCode(GetWidestType(Symbols.MapTypeCodeToType(typeCode), loopFor.WidestType));
                        if (code2 == TypeCode.String)
                        {
                            code2 = TypeCode.Double;
                        }
                        loopFor.WidestTypeCode = code2;
                        loopFor.WidestType     = Symbols.MapTypeCodeToType(code2);
                        flag2 = true;
                    }
                }
                if (flag2 || loopFor.UseUserDefinedOperators)
                {
                    Counter = ConvertLoopElement("Start", Counter, Counter.GetType(), loopFor.WidestType);
                    if (!loopFor.UseUserDefinedOperators)
                    {
                        loopFor.Limit     = ConvertLoopElement("Limit", loopFor.Limit, loopFor.Limit.GetType(), loopFor.WidestType);
                        loopFor.StepValue = ConvertLoopElement("Step", loopFor.StepValue, loopFor.StepValue.GetType(), loopFor.WidestType);
                    }
                }
                if (!loopFor.UseUserDefinedOperators)
                {
                    loopFor.Counter = Operators.AddObject(Counter, loopFor.StepValue);
                    TypeCode code3 = ((IConvertible)loopFor.Counter).GetTypeCode();
                    if (loopFor.EnumType != null)
                    {
                        CounterResult = Enum.ToObject(loopFor.EnumType, loopFor.Counter);
                    }
                    else
                    {
                        CounterResult = loopFor.Counter;
                    }
                    if (code3 != loopFor.WidestTypeCode)
                    {
                        loopFor.Limit     = Conversions.ChangeType(loopFor.Limit, Symbols.MapTypeCodeToType(code3));
                        loopFor.StepValue = Conversions.ChangeType(loopFor.StepValue, Symbols.MapTypeCodeToType(code3));
                        return(false);
                    }
                }
                else
                {
                    loopFor.Counter = Operators.InvokeUserDefinedOperator(loopFor.OperatorPlus, true, new object[] { Counter, loopFor.StepValue });
                    if (loopFor.Counter.GetType() != loopFor.WidestType)
                    {
                        loopFor.Counter = ConvertLoopElement("Start", loopFor.Counter, loopFor.Counter.GetType(), loopFor.WidestType);
                    }
                    CounterResult = loopFor.Counter;
                }
                return(CheckContinueLoop(loopFor));
            }
Ejemplo n.º 34
0
        internal static string VBFriendlyNameOfType(Type typ, [Optional, DefaultParameterValue(false)] bool FullName)
        {
            string   name;
            TypeCode typeCode;
            string   arraySuffixAndElementType = GetArraySuffixAndElementType(ref typ);

            if (typ.IsEnum)
            {
                typeCode = TypeCode.Object;
            }
            else
            {
                typeCode = Type.GetTypeCode(typ);
            }
            switch (typeCode)
            {
            case TypeCode.DBNull:
                name = "DBNull";
                break;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            default:
                if (Symbols.IsGenericParameter(typ))
                {
                    name = typ.Name;
                }
                else
                {
                    string fullName;
                    string str6 = null;
                    string genericArgsSuffix = GetGenericArgsSuffix(typ);
                    if (FullName)
                    {
                        if (typ.DeclaringType != null)
                        {
                            str6     = VBFriendlyNameOfType(typ.DeclaringType, true);
                            fullName = typ.Name;
                        }
                        else
                        {
                            fullName = typ.FullName;
                        }
                    }
                    else
                    {
                        fullName = typ.Name;
                    }
                    if (genericArgsSuffix != null)
                    {
                        int length = fullName.LastIndexOf('`');
                        if (length != -1)
                        {
                            fullName = fullName.Substring(0, length);
                        }
                        name = fullName + genericArgsSuffix;
                    }
                    else
                    {
                        name = fullName;
                    }
                    if (str6 != null)
                    {
                        name = str6 + "." + name;
                    }
                }
                break;
            }
            if (arraySuffixAndElementType != null)
            {
                name = name + arraySuffixAndElementType;
            }
            return(name);
        }
Ejemplo n.º 35
0
            public static bool ForLoopInitObj(object Counter, object Start, object Limit, object StepValue, ref object LoopForResult, ref object CounterResult)
            {
                if (Start == null)
                {
                    throw new ArgumentException(Utils.GetResourceString("Argument_InvalidNullValue1", new string[] { "Start" }));
                }
                if (Limit == null)
                {
                    throw new ArgumentException(Utils.GetResourceString("Argument_InvalidNullValue1", new string[] { "Limit" }));
                }
                if (StepValue == null)
                {
                    throw new ArgumentException(Utils.GetResourceString("Argument_InvalidNullValue1", new string[] { "Step" }));
                }
                Type type3 = Start.GetType();
                Type type2 = Limit.GetType();
                Type type4 = StepValue.GetType();
                Type type5 = GetWidestType(type4, type3, type2);

                if (type5 == null)
                {
                    throw new ArgumentException(Utils.GetResourceString("ForLoop_CommonType3", new string[] { Utils.VBFriendlyName(type3), Utils.VBFriendlyName(type2), Utils.VBFriendlyName(StepValue) }));
                }
                ObjectFlowControl.ForLoopControl loopFor = new ObjectFlowControl.ForLoopControl();
                TypeCode typeCode = Symbols.GetTypeCode(type5);

                switch (typeCode)
                {
                case TypeCode.Object:
                    loopFor.UseUserDefinedOperators = true;
                    break;

                case TypeCode.String:
                    typeCode = TypeCode.Double;
                    break;
                }
                TypeCode code2 = Type.GetTypeCode(type3);
                TypeCode code  = Type.GetTypeCode(type2);
                TypeCode code3 = Type.GetTypeCode(type4);
                Type     type  = null;

                if ((code2 == typeCode) && type3.IsEnum)
                {
                    type = type3;
                }
                if ((code == typeCode) && type2.IsEnum)
                {
                    if ((type != null) && (type != type2))
                    {
                        type = null;
                        goto Label_015E;
                    }
                    type = type2;
                }
                if ((code3 == typeCode) && type4.IsEnum)
                {
                    if ((type != null) && (type != type4))
                    {
                        type = null;
                    }
                    else
                    {
                        type = type4;
                    }
                }
Label_015E:
                loopFor.EnumType = type;
                if (!loopFor.UseUserDefinedOperators)
                {
                    loopFor.WidestType = Symbols.MapTypeCodeToType(typeCode);
                }
                else
                {
                    loopFor.WidestType = type5;
                }
                loopFor.WidestTypeCode = typeCode;
                loopFor.Counter        = ConvertLoopElement("Start", Start, type3, loopFor.WidestType);
                loopFor.Limit          = ConvertLoopElement("Limit", Limit, type2, loopFor.WidestType);
                loopFor.StepValue      = ConvertLoopElement("Step", StepValue, type4, loopFor.WidestType);
                if (loopFor.UseUserDefinedOperators)
                {
                    loopFor.OperatorPlus = VerifyForLoopOperator(Symbols.UserDefinedOperator.Plus, loopFor.Counter, loopFor.WidestType);
                    VerifyForLoopOperator(Symbols.UserDefinedOperator.Minus, loopFor.Counter, loopFor.WidestType);
                    loopFor.OperatorLessEqual    = VerifyForLoopOperator(Symbols.UserDefinedOperator.LessEqual, loopFor.Counter, loopFor.WidestType);
                    loopFor.OperatorGreaterEqual = VerifyForLoopOperator(Symbols.UserDefinedOperator.GreaterEqual, loopFor.Counter, loopFor.WidestType);
                }
                loopFor.PositiveStep = Operators.ConditionalCompareObjectGreaterEqual(loopFor.StepValue, Operators.SubtractObject(loopFor.StepValue, loopFor.StepValue), false);
                LoopForResult        = loopFor;
                if (loopFor.EnumType != null)
                {
                    CounterResult = Enum.ToObject(loopFor.EnumType, loopFor.Counter);
                }
                else
                {
                    CounterResult = loopFor.Counter;
                }
                return(CheckContinueLoop(loopFor));
            }
 public VBUnaryOperatorBinder(Symbols.UserDefinedOperator Op, ExpressionType LinqOp) : base(LinqOp)
 {
     this._Op = Op;
 }
 internal static ConversionClass ClassifyConversion(Type TargetType, Type SourceType, ref Symbols.Method OperatorMethod)
 {
     ConversionClass class3 = ClassifyPredefinedConversion(TargetType, SourceType);
     if ((((class3 != ConversionClass.None) || Symbols.IsInterface(SourceType)) || Symbols.IsInterface(TargetType)) || (!Symbols.IsClassOrValueType(SourceType) && !Symbols.IsClassOrValueType(TargetType)))
     {
         return class3;
     }
     if (Symbols.IsIntrinsicType(SourceType) && Symbols.IsIntrinsicType(TargetType))
     {
         return class3;
     }
     return ClassifyUserDefinedConversion(TargetType, SourceType, ref OperatorMethod);
 }
Ejemplo n.º 38
0
        internal static ConversionClass ClassifyConversion(Type TargetType, Type SourceType, ref Symbols.Method OperatorMethod)
        {
            ConversionClass class3 = ClassifyPredefinedConversion(TargetType, SourceType);

            if ((((class3 != ConversionClass.None) || Symbols.IsInterface(SourceType)) || Symbols.IsInterface(TargetType)) || (!Symbols.IsClassOrValueType(SourceType) && !Symbols.IsClassOrValueType(TargetType)))
            {
                return(class3);
            }
            if (Symbols.IsIntrinsicType(SourceType) && Symbols.IsIntrinsicType(TargetType))
            {
                return(class3);
            }
            return(ClassifyUserDefinedConversion(TargetType, SourceType, ref OperatorMethod));
        }
 internal static ConversionClass ClassifyUserDefinedConversion(Type TargetType, Type SourceType, ref Symbols.Method OperatorMethod)
 {
     ConversionClass class3;
     OperatorCaches.FixedList conversionCache = OperatorCaches.ConversionCache;
     lock (conversionCache)
     {
         if (OperatorCaches.UnconvertibleTypeCache.Lookup(TargetType) && OperatorCaches.UnconvertibleTypeCache.Lookup(SourceType))
         {
             return ConversionClass.None;
         }
         if (OperatorCaches.ConversionCache.Lookup(TargetType, SourceType, ref class3, ref OperatorMethod))
         {
             return class3;
         }
     }
     bool foundTargetTypeOperators = false;
     bool foundSourceTypeOperators = false;
     class3 = DoClassifyUserDefinedConversion(TargetType, SourceType, ref OperatorMethod, ref foundTargetTypeOperators, ref foundSourceTypeOperators);
     OperatorCaches.FixedList list2 = OperatorCaches.ConversionCache;
     lock (list2)
     {
         if (!foundTargetTypeOperators)
         {
             OperatorCaches.UnconvertibleTypeCache.Insert(TargetType);
         }
         if (!foundSourceTypeOperators)
         {
             OperatorCaches.UnconvertibleTypeCache.Insert(SourceType);
         }
         if (!foundTargetTypeOperators && !foundSourceTypeOperators)
         {
             return class3;
         }
         OperatorCaches.ConversionCache.Insert(TargetType, SourceType, class3, OperatorMethod);
     }
     return class3;
 }
Ejemplo n.º 40
0
        internal static ConversionClass ClassifyPredefinedConversion(Type TargetType, Type SourceType)
        {
            if (TargetType == SourceType)
            {
                return(ConversionClass.Identity);
            }
            TypeCode typeCode = Symbols.GetTypeCode(SourceType);
            TypeCode code2    = Symbols.GetTypeCode(TargetType);

            if (Symbols.IsIntrinsicType(typeCode) && Symbols.IsIntrinsicType(code2))
            {
                if ((Symbols.IsEnum(TargetType) && Symbols.IsIntegralType(typeCode)) && Symbols.IsIntegralType(code2))
                {
                    return(ConversionClass.Narrowing);
                }
                if ((typeCode == code2) && Symbols.IsEnum(SourceType))
                {
                    return(ConversionClass.Widening);
                }
                return(ClassifyIntrinsicConversion(code2, typeCode));
            }
            if (Symbols.IsCharArrayRankOne(SourceType) && Symbols.IsStringType(TargetType))
            {
                return(ConversionClass.Widening);
            }
            if (Symbols.IsCharArrayRankOne(TargetType) && Symbols.IsStringType(SourceType))
            {
                return(ConversionClass.Narrowing);
            }
            return(ClassifyPredefinedCLRConversion(TargetType, SourceType));
        }
 private static ConversionClass DoClassifyUserDefinedConversion(Type TargetType, Type SourceType, ref Symbols.Method OperatorMethod, ref bool FoundTargetTypeOperators, ref bool FoundSourceTypeOperators)
 {
     OperatorMethod = null;
     List<Symbols.Method> operatorSet = CollectConversionOperators(TargetType, SourceType, ref FoundTargetTypeOperators, ref FoundSourceTypeOperators);
     if (operatorSet.Count == 0)
     {
         return ConversionClass.None;
     }
     bool resolutionIsAmbiguous = false;
     List<Symbols.Method> list = ResolveConversion(TargetType, SourceType, operatorSet, true, ref resolutionIsAmbiguous);
     if (list.Count == 1)
     {
         OperatorMethod = list[0];
         OperatorMethod.ArgumentsValidated = true;
         return ConversionClass.Widening;
     }
     if ((list.Count == 0) && !resolutionIsAmbiguous)
     {
         list = ResolveConversion(TargetType, SourceType, operatorSet, false, ref resolutionIsAmbiguous);
         if (list.Count == 1)
         {
             OperatorMethod = list[0];
             OperatorMethod.ArgumentsValidated = true;
             return ConversionClass.Narrowing;
         }
         if (list.Count == 0)
         {
             return ConversionClass.None;
         }
     }
     return ConversionClass.Ambiguous;
 }
Ejemplo n.º 42
0
        private static List <Symbols.Method> ResolveConversion(Type TargetType, Type SourceType, List <Symbols.Method> OperatorSet, bool WideningOnly, ref bool ResolutionIsAmbiguous)
        {
            ResolutionIsAmbiguous = false;
            Type sourceType = null;
            Type targetType = null;
            bool genericMembersExistInList     = false;
            List <Symbols.Method> operatorList = new List <Symbols.Method>(OperatorSet.Count);
            List <Symbols.Method> searchList   = new List <Symbols.Method>(OperatorSet.Count);
            List <Type>           types        = new List <Type>(OperatorSet.Count);
            List <Type>           list7        = new List <Type>(OperatorSet.Count);
            List <Type>           list5        = null;
            List <Type>           list6        = null;

            if (!WideningOnly)
            {
                list5 = new List <Type>(OperatorSet.Count);
                list6 = new List <Type>(OperatorSet.Count);
            }
            foreach (Symbols.Method method in OperatorSet)
            {
                MethodBase base2 = method.AsMethod();
                if (WideningOnly && Symbols.IsNarrowingConversionOperator(base2))
                {
                    break;
                }
                Type parameterType = base2.GetParameters()[0].ParameterType;
                Type returnType    = ((MethodInfo)base2).ReturnType;
                if ((!Symbols.IsGeneric(base2) && !Symbols.IsGeneric(base2.DeclaringType)) || (ClassifyPredefinedConversion(returnType, parameterType) == ConversionClass.None))
                {
                    if ((parameterType == SourceType) && (returnType == TargetType))
                    {
                        InsertInOperatorListIfLessGenericThanExisting(method, operatorList, ref genericMembersExistInList);
                        continue;
                    }
                    if (operatorList.Count == 0)
                    {
                        if (Encompasses(parameterType, SourceType) && Encompasses(TargetType, returnType))
                        {
                            searchList.Add(method);
                            if (parameterType == SourceType)
                            {
                                sourceType = parameterType;
                            }
                            else
                            {
                                types.Add(parameterType);
                            }
                            if (returnType == TargetType)
                            {
                                targetType = returnType;
                            }
                            else
                            {
                                list7.Add(returnType);
                            }
                            continue;
                        }
                        if ((!WideningOnly && Encompasses(parameterType, SourceType)) && NotEncompasses(TargetType, returnType))
                        {
                            searchList.Add(method);
                            if (parameterType == SourceType)
                            {
                                sourceType = parameterType;
                            }
                            else
                            {
                                types.Add(parameterType);
                            }
                            if (returnType == TargetType)
                            {
                                targetType = returnType;
                            }
                            else
                            {
                                list6.Add(returnType);
                            }
                            continue;
                        }
                        if ((!WideningOnly && NotEncompasses(parameterType, SourceType)) && NotEncompasses(TargetType, returnType))
                        {
                            searchList.Add(method);
                            if (parameterType == SourceType)
                            {
                                sourceType = parameterType;
                            }
                            else
                            {
                                list5.Add(parameterType);
                            }
                            if (returnType == TargetType)
                            {
                                targetType = returnType;
                            }
                            else
                            {
                                list6.Add(returnType);
                            }
                        }
                    }
                }
            }
            if ((operatorList.Count == 0) && (searchList.Count > 0))
            {
                if (sourceType == null)
                {
                    if (types.Count > 0)
                    {
                        sourceType = MostEncompassed(types);
                    }
                    else
                    {
                        sourceType = MostEncompassing(list5);
                    }
                }
                if (targetType == null)
                {
                    if (list7.Count > 0)
                    {
                        targetType = MostEncompassing(list7);
                    }
                    else
                    {
                        targetType = MostEncompassed(list6);
                    }
                }
                if ((sourceType == null) || (targetType == null))
                {
                    ResolutionIsAmbiguous = true;
                    return(new List <Symbols.Method>());
                }
                FindBestMatch(targetType, sourceType, searchList, operatorList, ref genericMembersExistInList);
            }
            if (operatorList.Count > 1)
            {
                ResolutionIsAmbiguous = true;
            }
            return(operatorList);
        }
 private static bool DetectArgumentNarrowing(Symbols.Method TargetProcedure, object[] Arguments, string[] ArgumentNames, Type[] TypeArguments, List<string> Errors)
 {
     return CanMatchArguments(TargetProcedure, Arguments, ArgumentNames, TypeArguments, true, Errors);
 }