Beispiel #1
0
        internal static bool CanBindGet(object Instance, string MemberName, object[] Arguments, string[] ArgumentNames)
        {
            Symbols.Container baseReference = new Symbols.Container(Instance);
            BindingFlags      lookupFlags   = BindingFlags.GetProperty | BindingFlags.InvokeMethod;

            MemberInfo[] members = baseReference.GetMembers(ref MemberName, false);
            if ((members != null) && (members.Length != 0))
            {
                OverloadResolution.ResolutionFailure failure;
                if (members[0].MemberType == MemberTypes.Field)
                {
                    return(true);
                }
                Symbols.Method method = ResolveCall(baseReference, MemberName, members, Arguments, ArgumentNames, Symbols.NoTypeArguments, lookupFlags, false, ref failure);
                if (failure == OverloadResolution.ResolutionFailure.None)
                {
                    return(true);
                }
                if (((Arguments.Length > 0) && (members.Length == 1)) && IsZeroArgumentCall(members[0]))
                {
                    method = ResolveCall(baseReference, MemberName, members, Symbols.NoArguments, Symbols.NoArgumentNames, Symbols.NoTypeArguments, lookupFlags, false, ref failure);
                    if (failure == OverloadResolution.ResolutionFailure.None)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Beispiel #2
0
 private static Type GetWidestType(Type Type1, Type Type2)
 {
     if ((Type1 != null) && (Type2 != null))
     {
         if (!Type1.IsEnum && !Type2.IsEnum)
         {
             TypeCode typeCode = Symbols.GetTypeCode(Type1);
             TypeCode code2    = Symbols.GetTypeCode(Type2);
             if (Symbols.IsNumericType(typeCode) && Symbols.IsNumericType(code2))
             {
                 return(Symbols.MapTypeCodeToType(ConversionResolution.ForLoopWidestTypeCode[(int)typeCode][(int)code2]));
             }
         }
         Symbols.Method operatorMethod = null;
         switch (ConversionResolution.ClassifyConversion(Type2, Type1, ref operatorMethod))
         {
         case ConversionResolution.ConversionClass.Identity:
         case ConversionResolution.ConversionClass.Widening:
             return(Type2);
         }
         operatorMethod = null;
         if (ConversionResolution.ClassifyConversion(Type1, Type2, ref operatorMethod) == ConversionResolution.ConversionClass.Widening)
         {
             return(Type1);
         }
     }
     return(null);
 }
Beispiel #3
0
        internal static bool CanIndexSetComplex(object Instance, object[] Arguments, string[] ArgumentNames, bool OptimisticSet, bool RValueBase)
        {
            OverloadResolution.ResolutionFailure failure;
            Symbols.Container baseReference = new Symbols.Container(Instance);
            if (baseReference.IsArray)
            {
                return(ArgumentNames.Length == 0);
            }
            string       memberName  = "";
            BindingFlags setProperty = BindingFlags.SetProperty;

            MemberInfo[] members = baseReference.GetMembers(ref memberName, false);
            if ((members == null) || (members.Length == 0))
            {
                return(false);
            }
            Symbols.Method method = ResolveCall(baseReference, memberName, members, Arguments, ArgumentNames, Symbols.NoTypeArguments, setProperty, false, ref failure);
            if (failure != OverloadResolution.ResolutionFailure.None)
            {
                return(OptimisticSet);
            }
            if (RValueBase && baseReference.IsValueType)
            {
                return(false);
            }
            return(true);
        }
Beispiel #4
0
            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 (TargetInvocationException exception)
                {
                    throw exception.InnerException;
                }
                OverloadResolution.ReorderArgumentArray(TargetProcedure, parameters, Arguments, CopyBack, Flags);
                return(obj3);
            }
Beispiel #5
0
 internal static MethodInfo MatchesPropertyRequirements(Symbols.Method TargetProcedure, BindingFlags Flags)
 {
     if (Symbols.HasFlag(Flags, BindingFlags.SetProperty))
     {
         return(TargetProcedure.AsProperty().GetSetMethod());
     }
     return(TargetProcedure.AsProperty().GetGetMethod());
 }
Beispiel #6
0
 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 })));
 }
Beispiel #7
0
        private static object ObjectLateGet(object Instance, Type Type, string MemberName, object[] Arguments, string[] ArgumentNames, Type[] TypeArguments, bool[] CopyBack)
        {
            Symbols.Container container;
            OverloadResolution.ResolutionFailure failure;
            if (Type != null)
            {
                container = new Symbols.Container(Type);
            }
            else
            {
                container = new Symbols.Container(Instance);
            }
            BindingFlags lookupFlags = BindingFlags.GetProperty | BindingFlags.InvokeMethod;

            MemberInfo[] members = container.GetMembers(ref MemberName, true);
            if (members[0].MemberType == MemberTypes.Field)
            {
                if (TypeArguments.Length > 0)
                {
                    throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue"));
                }
                object fieldValue = container.GetFieldValue((FieldInfo)members[0]);
                if (Arguments.Length == 0)
                {
                    return(fieldValue);
                }
                return(LateIndexGet(fieldValue, Arguments, ArgumentNames, CopyBack));
            }
            if ((ArgumentNames.Length > Arguments.Length) || ((CopyBack != null) && (CopyBack.Length != Arguments.Length)))
            {
                throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue"));
            }
            Symbols.Method targetProcedure = ResolveCall(container, MemberName, members, Arguments, ArgumentNames, TypeArguments, lookupFlags, false, ref failure);
            if (failure == OverloadResolution.ResolutionFailure.None)
            {
                return(container.InvokeMethod(targetProcedure, Arguments, CopyBack, lookupFlags));
            }
            if (((Arguments.Length > 0) && (members.Length == 1)) && IsZeroArgumentCall(members[0]))
            {
                targetProcedure = ResolveCall(container, MemberName, members, Symbols.NoArguments, Symbols.NoArgumentNames, TypeArguments, lookupFlags, false, ref failure);
                if (failure == OverloadResolution.ResolutionFailure.None)
                {
                    object instance = container.InvokeMethod(targetProcedure, Symbols.NoArguments, null, lookupFlags);
                    if (instance == null)
                    {
                        throw new MissingMemberException(Utils.GetResourceString("IntermediateLateBoundNothingResult1", new string[] { targetProcedure.ToString(), container.VBFriendlyName }));
                    }
                    instance = InternalLateIndexGet(instance, Arguments, ArgumentNames, false, ref failure, CopyBack);
                    if (failure == OverloadResolution.ResolutionFailure.None)
                    {
                        return(instance);
                    }
                }
            }
            ResolveCall(container, MemberName, members, Arguments, ArgumentNames, TypeArguments, lookupFlags, true, ref failure);
            throw new InternalErrorException();
        }
Beispiel #8
0
 internal static void ObjectLateIndexSetComplex(object Instance, object[] Arguments, string[] ArgumentNames, bool OptimisticSet, bool RValueBase)
 {
     if (Arguments == null)
     {
         Arguments = Symbols.NoArguments;
     }
     if (ArgumentNames == null)
     {
         ArgumentNames = Symbols.NoArgumentNames;
     }
     Symbols.Container baseReference = new Symbols.Container(Instance);
     if (baseReference.IsArray)
     {
         if (ArgumentNames.Length > 0)
         {
             throw new ArgumentException(Utils.GetResourceString("Argument_InvalidNamedArgs"));
         }
         baseReference.SetArrayValue(Arguments);
     }
     else
     {
         if (ArgumentNames.Length > Arguments.Length)
         {
             throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue"));
         }
         if (Arguments.Length < 1)
         {
             throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue"));
         }
         string memberName = "";
         if (baseReference.IsCOMObject)
         {
             LateBinding.LateIndexSetComplex(Instance, Arguments, ArgumentNames, OptimisticSet, RValueBase);
         }
         else
         {
             OverloadResolution.ResolutionFailure failure;
             BindingFlags   setProperty     = BindingFlags.SetProperty;
             MemberInfo[]   members         = baseReference.GetMembers(ref memberName, true);
             Symbols.Method targetProcedure = ResolveCall(baseReference, memberName, members, Arguments, ArgumentNames, Symbols.NoTypeArguments, setProperty, false, ref failure);
             if (failure == OverloadResolution.ResolutionFailure.None)
             {
                 if (RValueBase && baseReference.IsValueType)
                 {
                     throw new Exception(Utils.GetResourceString("RValueBaseForValueType", new string[] { baseReference.VBFriendlyName, baseReference.VBFriendlyName }));
                 }
                 baseReference.InvokeMethod(targetProcedure, Arguments, null, setProperty);
             }
             else if (!OptimisticSet)
             {
                 ResolveCall(baseReference, memberName, members, Arguments, ArgumentNames, Symbols.NoTypeArguments, setProperty, true, ref failure);
                 throw new InternalErrorException();
             }
         }
     }
 }
Beispiel #9
0
 internal static MethodBase GetCallTarget(Symbols.Method TargetProcedure, BindingFlags Flags)
 {
     if (TargetProcedure.IsMethod)
     {
         return(TargetProcedure.AsMethod());
     }
     if (TargetProcedure.IsProperty)
     {
         return(MatchesPropertyRequirements(TargetProcedure, Flags));
     }
     return(null);
 }
Beispiel #10
0
            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);
            }
Beispiel #11
0
        internal static bool CanBindCall(object Instance, string MemberName, object[] Arguments, string[] ArgumentNames, bool IgnoreReturn)
        {
            OverloadResolution.ResolutionFailure failure;
            Symbols.Container baseReference = new Symbols.Container(Instance);
            BindingFlags      lookupFlags   = BindingFlags.GetProperty | BindingFlags.InvokeMethod;

            if (IgnoreReturn)
            {
                lookupFlags |= BindingFlags.IgnoreReturn;
            }
            MemberInfo[] members = baseReference.GetMembers(ref MemberName, false);
            if ((members == null) || (members.Length == 0))
            {
                return(false);
            }
            Symbols.Method method = ResolveCall(baseReference, MemberName, members, Arguments, ArgumentNames, Symbols.NoTypeArguments, lookupFlags, false, ref failure);
            return(failure == OverloadResolution.ResolutionFailure.None);
        }
Beispiel #12
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);
        }
Beispiel #13
0
        internal static bool CanBindSet(object Instance, string MemberName, object Value, bool OptimisticSet, bool RValueBase)
        {
            OverloadResolution.ResolutionFailure failure;
            Symbols.Container baseReference = new Symbols.Container(Instance);
            object[]          arguments     = new object[] { Value };
            MemberInfo[]      members       = baseReference.GetMembers(ref MemberName, false);
            if ((members == null) || (members.Length == 0))
            {
                return(false);
            }
            if (members[0].MemberType == MemberTypes.Field)
            {
                if (((arguments.Length == 1) && RValueBase) && baseReference.IsValueType)
                {
                    return(false);
                }
                return(true);
            }
            Symbols.Method method = ResolveCall(baseReference, MemberName, members, arguments, Symbols.NoArgumentNames, Symbols.NoTypeArguments, BindingFlags.SetProperty, false, ref failure);
            if (failure == OverloadResolution.ResolutionFailure.None)
            {
                if (RValueBase && baseReference.IsValueType)
                {
                    return(false);
                }
                return(true);
            }
            BindingFlags lookupFlags = BindingFlags.GetProperty | BindingFlags.InvokeMethod;

            if (failure == OverloadResolution.ResolutionFailure.MissingMember)
            {
                method = ResolveCall(baseReference, MemberName, members, Symbols.NoArguments, Symbols.NoArgumentNames, Symbols.NoTypeArguments, lookupFlags, false, ref failure);
                if (failure == OverloadResolution.ResolutionFailure.None)
                {
                    return(true);
                }
            }
            return(OptimisticSet);
        }
Beispiel #14
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);
 }
 private static void FindBestMatch(Type TargetType, Type SourceType, List <Symbols.Method> SearchList, List <Symbols.Method> ResultList, ref bool GenericMembersExistInList)
 {
     List <Symbols.Method> .Enumerator enumerator;
     try
     {
         enumerator = SearchList.GetEnumerator();
         while (enumerator.MoveNext())
         {
             Symbols.Method current       = enumerator.Current;
             MethodBase     base2         = current.AsMethod();
             Type           parameterType = base2.GetParameters()[0].ParameterType;
             Type           returnType    = ((MethodInfo)base2).ReturnType;
             if ((parameterType == SourceType) && (returnType == TargetType))
             {
                 InsertInOperatorListIfLessGenericThanExisting(current, ResultList, ref GenericMembersExistInList);
             }
         }
     }
     finally
     {
         enumerator.Dispose();
     }
 }
Beispiel #16
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);
 }
Beispiel #17
0
        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);
        }
Beispiel #18
0
            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;
            }
Beispiel #19
0
        internal static ConversionClass ClassifyUserDefinedConversion(Type TargetType, Type SourceType, ref Symbols.Method OperatorMethod)
        {
            ConversionClass class3 = 0;

            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);
        }
Beispiel #20
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));
        }
Beispiel #21
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 }));
        }
 private static void InsertIfMethodAvailable(MemberInfo NewCandidate, ParameterInfo[] NewCandidateSignature, int NewCandidateParamArrayIndex, bool ExpandNewCandidateParamArray, object[] Arguments, int ArgumentCount, string[] ArgumentNames, Type[] TypeArguments, bool CollectOnlyOperators, List<Symbols.Method> Candidates)
 {
     Symbols.Method candidate = null;
     if (!CollectOnlyOperators)
     {
         MethodBase method = NewCandidate as MethodBase;
         bool flag = false;
         if ((NewCandidate.MemberType == MemberTypes.Method) && Symbols.IsRawGeneric(method))
         {
             candidate = new Symbols.Method(method, NewCandidateSignature, NewCandidateParamArrayIndex, ExpandNewCandidateParamArray);
             RejectUncallableProcedure(candidate, Arguments, ArgumentNames, TypeArguments);
             NewCandidate = candidate.AsMethod();
             NewCandidateSignature = candidate.Parameters;
         }
         if (((NewCandidate != null) && (NewCandidate.MemberType == MemberTypes.Method)) && Symbols.IsRawGeneric(NewCandidate as MethodBase))
         {
             flag = true;
         }
         int num5 = Candidates.Count - 1;
         for (int i = 0; i <= num5; i++)
         {
             Symbols.Method method2 = Candidates[i];
             if (method2 != null)
             {
                 MethodBase base3;
                 ParameterInfo[] parameters = method2.Parameters;
                 if (method2.IsMethod)
                 {
                     base3 = method2.AsMethod();
                 }
                 else
                 {
                     base3 = null;
                 }
                 if (NewCandidate != method2)
                 {
                     int index = 0;
                     int num = 0;
                     int num6 = ArgumentCount;
                     for (int j = 1; j <= num6; j++)
                     {
                         bool bothLose = false;
                         bool leftWins = false;
                         bool rightWins = false;
                         CompareParameterSpecificity(null, NewCandidateSignature[index], method, ExpandNewCandidateParamArray, parameters[num], base3, method2.ParamArrayExpanded, ref leftWins, ref rightWins, ref bothLose);
                         if (!((bothLose | leftWins) | rightWins))
                         {
                             if ((index != NewCandidateParamArrayIndex) || !ExpandNewCandidateParamArray)
                             {
                                 index++;
                             }
                             if ((num != method2.ParamArrayIndex) || !method2.ParamArrayExpanded)
                             {
                                 num++;
                             }
                         }
                     }
                     if (!IsExactSignatureMatch(NewCandidateSignature, Symbols.GetTypeParameters(NewCandidate).Length, method2.Parameters, method2.TypeParameters.Length))
                     {
                         if (!flag && ((base3 == null) || !Symbols.IsRawGeneric(base3)))
                         {
                             if (ExpandNewCandidateParamArray || !method2.ParamArrayExpanded)
                             {
                                 if (ExpandNewCandidateParamArray && !method2.ParamArrayExpanded)
                                 {
                                     return;
                                 }
                                 if (ExpandNewCandidateParamArray || method2.ParamArrayExpanded)
                                 {
                                     if (index <= num)
                                     {
                                         if (num > index)
                                         {
                                             return;
                                         }
                                     }
                                     else
                                     {
                                         Candidates[i] = null;
                                     }
                                 }
                             }
                             else
                             {
                                 Candidates[i] = null;
                             }
                         }
                     }
                     else
                     {
                         if (NewCandidate.DeclaringType == method2.DeclaringType)
                         {
                             break;
                         }
                         if ((flag || (base3 == null)) || !Symbols.IsRawGeneric(base3))
                         {
                             return;
                         }
                     }
                 }
             }
         }
     }
     if (candidate != null)
     {
         Candidates.Add(candidate);
     }
     else if (NewCandidate.MemberType == MemberTypes.Property)
     {
         Candidates.Add(new Symbols.Method((PropertyInfo) NewCandidate, NewCandidateSignature, NewCandidateParamArrayIndex, ExpandNewCandidateParamArray));
     }
     else
     {
         Candidates.Add(new Symbols.Method((MethodBase) NewCandidate, NewCandidateSignature, NewCandidateParamArrayIndex, ExpandNewCandidateParamArray));
     }
 }
Beispiel #23
0
            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);
            }