Beispiel #1
0
            internal object InvokeMethod(Symbols.Method TargetProcedure, object[] Arguments, bool[] CopyBack, BindingFlags Flags)
            {
                MethodBase callTarget = NewLateBinding.GetCallTarget(TargetProcedure, Flags);

                object[] objArray = NewLateBinding.ConstructCallArguments(TargetProcedure, Arguments, Flags);
                if (this.m_Instance == null && !Symbols.IsShared((MemberInfo)callTarget))
                {
                    throw new NullReferenceException(Utils.GetResourceString("NullReference_InstanceReqToAccessMember1", new string[1]
                    {
                        TargetProcedure.ToString()
                    }));
                }
                if (Symbols.IsNonPublicRuntimeMember((MemberInfo)callTarget))
                {
                    throw new MissingMemberException();
                }
                object obj;

                try
                {
                    obj = callTarget.Invoke(this.m_Instance, objArray);
                }
                catch (TargetInvocationException ex) when(ex.InnerException != null)
                {
                    throw ex.InnerException;
                }
                OverloadResolution.ReorderArgumentArray(TargetProcedure, objArray, Arguments, CopyBack, Flags);
                return(obj);
            }
Beispiel #2
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 #3
0
 public static void LateIndexSetComplex(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
         {
             BindingFlags bindingFlags = BindingFlags.SetProperty;
             MemberInfo[] members      = BaseReference.GetMembers(ref MemberName, true);
             OverloadResolution.ResolutionFailure Failure = OverloadResolution.ResolutionFailure.None;
             Symbols.Method TargetProcedure = NewLateBinding.ResolveCall(BaseReference, MemberName, members, Arguments, ArgumentNames, Symbols.NoTypeArguments, bindingFlags, false, ref Failure);
             if (Failure == OverloadResolution.ResolutionFailure.None)
             {
                 if (RValueBase && BaseReference.IsValueType)
                 {
                     throw new Exception(Utils.GetResourceString("RValueBaseForValueType", BaseReference.VBFriendlyName, BaseReference.VBFriendlyName));
                 }
                 BaseReference.InvokeMethod(TargetProcedure, Arguments, (bool[])null, bindingFlags);
             }
             else if (!OptimisticSet)
             {
                 NewLateBinding.ResolveCall(BaseReference, MemberName, members, Arguments, ArgumentNames, Symbols.NoTypeArguments, bindingFlags, true, ref Failure);
                 throw new InternalErrorException();
             }
         }
     }
 }
Beispiel #4
0
 internal static Exception ReportPropertyMismatch(Symbols.Method TargetProcedure, BindingFlags Flags)
 {
     if (Symbols.HasFlag(Flags, BindingFlags.SetProperty))
     {
         return((Exception) new MissingMemberException(Utils.GetResourceString("NoSetProperty1", new string[1]
         {
             TargetProcedure.AsProperty().Name
         })));
     }
     return((Exception) new MissingMemberException(Utils.GetResourceString("NoGetProperty1", new string[1]
     {
         TargetProcedure.AsProperty().Name
     })));
 }
            private static Type GetWidestType(Type Type1, Type Type2)
            {
                if (Type1 == null || Type2 == null)
                {
                    return((Type)null);
                }
                if (!Type1.IsEnum && !Type2.IsEnum)
                {
                    TypeCode typeCode1 = Symbols.GetTypeCode(Type1);
                    TypeCode typeCode2 = Symbols.GetTypeCode(Type2);
                    if (Symbols.IsNumericType(typeCode1) && Symbols.IsNumericType(typeCode2))
                    {
                        return(Symbols.MapTypeCodeToType(ConversionResolution.ForLoopWidestTypeCode[(int)typeCode1][(int)typeCode2]));
                    }
                }
                Type TargetType1 = Type2;
                Type SourceType1 = Type1;

                Symbols.Method     method1 = (Symbols.Method)null;
                ref Symbols.Method local1  = ref method1;
Beispiel #6
0
 private static object CallMethod(Symbols.Container BaseReference, string MethodName, object[] Arguments, string[] ArgumentNames, Type[] TypeArguments, bool[] CopyBack, BindingFlags InvocationFlags, bool ReportErrors, ref OverloadResolution.ResolutionFailure Failure)
 {
     Failure = OverloadResolution.ResolutionFailure.None;
     if (ArgumentNames.Length > Arguments.Length || CopyBack != null && CopyBack.Length != Arguments.Length)
     {
         Failure = OverloadResolution.ResolutionFailure.InvalidArgument;
         if (ReportErrors)
         {
             throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue"));
         }
         return((object)null);
     }
     if (Symbols.HasFlag(InvocationFlags, BindingFlags.SetProperty) && Arguments.Length < 1)
     {
         Failure = OverloadResolution.ResolutionFailure.InvalidArgument;
         if (ReportErrors)
         {
             throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue"));
         }
         return((object)null);
     }
     MemberInfo[] members = BaseReference.GetMembers(ref MethodName, ReportErrors);
     if (members == null || members.Length == 0)
     {
         Failure = OverloadResolution.ResolutionFailure.MissingMember;
         if (ReportErrors)
         {
             BaseReference.GetMembers(ref MethodName, true);
         }
         return((object)null);
     }
     Symbols.Method TargetProcedure = NewLateBinding.ResolveCall(BaseReference, MethodName, members, Arguments, ArgumentNames, TypeArguments, InvocationFlags, ReportErrors, ref Failure);
     if (Failure == OverloadResolution.ResolutionFailure.None)
     {
         return(BaseReference.InvokeMethod(TargetProcedure, Arguments, CopyBack, InvocationFlags));
     }
     return((object)null);
 }
Beispiel #7
0
            internal bool Lookup(Type TargetType, Type SourceType, ref ConversionResolution.ConversionClass Classification, ref Symbols.Method OperatorMethod)
            {
                int index = this.m_First;
                int num   = 0;

                while (num < this.m_Count)
                {
                    if (TargetType == this.m_List[index].TargetType && SourceType == this.m_List[index].SourceType)
                    {
                        Classification = this.m_List[index].Classification;
                        OperatorMethod = this.m_List[index].OperatorMethod;
                        this.MoveToFront(index);
                        return(true);
                    }
                    index = this.m_List[index].Next;
                    checked { ++num; }
                }
                Classification = ConversionResolution.ConversionClass.Bad;
                OperatorMethod = (Symbols.Method)null;
                return(false);
            }
Beispiel #8
0
            internal void Insert(Type TargetType, Type SourceType, ConversionResolution.ConversionClass Classification, Symbols.Method OperatorMethod)
            {
                if (this.m_Count < this.m_Size)
                {
                    checked { ++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 #9
0
        internal static Symbols.Method ResolveCall(Symbols.Container BaseReference, string MethodName, MemberInfo[] Members, object[] Arguments, string[] ArgumentNames, Type[] TypeArguments, BindingFlags LookupFlags, bool ReportErrors, ref OverloadResolution.ResolutionFailure Failure)
        {
            Failure = OverloadResolution.ResolutionFailure.None;
            if (Members[0].MemberType != MemberTypes.Method && Members[0].MemberType != MemberTypes.Property)
            {
                Failure = OverloadResolution.ResolutionFailure.InvalidTarget;
                if (ReportErrors)
                {
                    throw new ArgumentException(Utils.GetResourceString("ExpressionNotProcedure", MethodName, BaseReference.VBFriendlyName));
                }
                return((Symbols.Method)null);
            }
            int    length = Arguments.Length;
            object obj1   = (object)null;

            if (Symbols.HasFlag(LookupFlags, BindingFlags.SetProperty))
            {
                if (Arguments.Length == 0)
                {
                    Failure = OverloadResolution.ResolutionFailure.InvalidArgument;
                    if (ReportErrors)
                    {
                        throw new InvalidCastException(Utils.GetResourceString("PropertySetMissingArgument1", new string[1]
                        {
                            MethodName
                        }));
                    }
                    return((Symbols.Method)null);
                }
                object[] objArray = Arguments;
                Arguments = new object[checked (length - 2 + 1)];
                Array.Copy((Array)objArray, (Array)Arguments, Arguments.Length);
                obj1 = objArray[checked (length - 1)];
            }
            Symbols.Method TargetProcedure1 = OverloadResolution.ResolveOverloadedCall(MethodName, Members, Arguments, ArgumentNames, TypeArguments, LookupFlags, ReportErrors, ref Failure);
            if (Failure != OverloadResolution.ResolutionFailure.None)
            {
                return((Symbols.Method)null);
            }
            if (!TargetProcedure1.ArgumentsValidated && !OverloadResolution.CanMatchArguments(TargetProcedure1, Arguments, ArgumentNames, TypeArguments, false, (List <string>)null))
            {
                Failure = OverloadResolution.ResolutionFailure.InvalidArgument;
                if (ReportErrors)
                {
                    string        str    = "";
                    List <string> Errors = new List <string>();
                    OverloadResolution.CanMatchArguments(TargetProcedure1, Arguments, ArgumentNames, TypeArguments, false, Errors);
                    List <string> .Enumerator enumerator = Ported.VisualBasic.CompilerServices.OverloadResolution.InitEnumerator <string>();
                    try
                    {
                        enumerator = Errors.GetEnumerator();
                        while (enumerator.MoveNext())
                        {
                            string current = enumerator.Current;
                            str = str + "\r\n    " + current;
                        }
                    }
                    finally
                    {
                        enumerator.Dispose();
                    }
                    throw new InvalidCastException(Utils.GetResourceString("MatchArgumentFailure2", TargetProcedure1.ToString(), str));
                }
                return((Symbols.Method)null);
            }
            if (TargetProcedure1.IsProperty)
            {
                if (NewLateBinding.MatchesPropertyRequirements(TargetProcedure1, LookupFlags) == null)
                {
                    Failure = OverloadResolution.ResolutionFailure.InvalidTarget;
                    if (ReportErrors)
                    {
                        throw NewLateBinding.ReportPropertyMismatch(TargetProcedure1, LookupFlags);
                    }
                    return((Symbols.Method)null);
                }
            }
            else if (Symbols.HasFlag(LookupFlags, BindingFlags.SetProperty))
            {
                Failure = OverloadResolution.ResolutionFailure.InvalidTarget;
                if (ReportErrors)
                {
                    throw new MissingMemberException(Utils.GetResourceString("MethodAssignment1", new string[1]
                    {
                        TargetProcedure1.AsMethod().Name
                    }));
                }
                return((Symbols.Method)null);
            }
            if (Symbols.HasFlag(LookupFlags, BindingFlags.SetProperty))
            {
                ParameterInfo[] parameters       = NewLateBinding.GetCallTarget(TargetProcedure1, LookupFlags).GetParameters();
                ParameterInfo   parameterInfo    = parameters[checked (parameters.Length - 1)];
                Symbols.Method  TargetProcedure2 = TargetProcedure1;
                object          obj2             = obj1;
                ParameterInfo   Parameter1       = parameterInfo;
                int             num1             = 0;
                int             num2             = 0;
                // ISSUE: variable of the null type
                object   local1 = null;
                bool     flag1  = false;
                ref bool local2 = ref flag1;
                bool     flag2  = false;
                ref bool local3 = ref flag2;
Beispiel #10
0
 public static void LateSet(object Instance, Type Type, string MemberName, object[] Arguments, string[] ArgumentNames, Type[] TypeArguments, bool OptimisticSet, bool RValueBase, CallType CallType)
 {
     if (Arguments == null)
     {
         Arguments = Symbols.NoArguments;
     }
     if (ArgumentNames == null)
     {
         ArgumentNames = Symbols.NoArgumentNames;
     }
     if (TypeArguments == null)
     {
         TypeArguments = Symbols.NoTypeArguments;
     }
     Symbols.Container BaseReference = Type == null ? new Symbols.Container(Instance) : new Symbols.Container(Type);
     if (BaseReference.IsCOMObject)
     {
         try
         {
             LateBinding.InternalLateSet(Instance, ref Type, MemberName, Arguments, ArgumentNames, OptimisticSet, CallType);
             if (RValueBase && Type.IsValueType)
             {
                 throw new Exception(Utils.GetResourceString("RValueBaseForValueType", Utils.VBFriendlyName(Type, Instance), Utils.VBFriendlyName(Type, Instance)));
             }
         }
         catch (MissingMemberException ex) when(OptimisticSet)
         {
         }
     }
     else
     {
         MemberInfo[] members = BaseReference.GetMembers(ref MemberName, true);
         if (members[0].MemberType == MemberTypes.Field)
         {
             if (TypeArguments.Length > 0)
             {
                 throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue"));
             }
             if (Arguments.Length == 1)
             {
                 if (RValueBase && BaseReference.IsValueType)
                 {
                     throw new Exception(Utils.GetResourceString("RValueBaseForValueType", BaseReference.VBFriendlyName, BaseReference.VBFriendlyName));
                 }
                 BaseReference.SetFieldValue((FieldInfo)members[0], Arguments[0]);
             }
             else
             {
                 NewLateBinding.LateIndexSetComplex(BaseReference.GetFieldValue((FieldInfo)members[0]), Arguments, ArgumentNames, OptimisticSet, true);
             }
         }
         else
         {
             BindingFlags bindingFlags1 = BindingFlags.SetProperty;
             if (ArgumentNames.Length > Arguments.Length)
             {
                 throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue"));
             }
             OverloadResolution.ResolutionFailure Failure = OverloadResolution.ResolutionFailure.None;
             if (TypeArguments.Length == 0)
             {
                 Symbols.Method TargetProcedure = NewLateBinding.ResolveCall(BaseReference, MemberName, members, Arguments, ArgumentNames, Symbols.NoTypeArguments, bindingFlags1, false, ref Failure);
                 if (Failure == OverloadResolution.ResolutionFailure.None)
                 {
                     if (RValueBase && BaseReference.IsValueType)
                     {
                         throw new Exception(Utils.GetResourceString("RValueBaseForValueType", BaseReference.VBFriendlyName, BaseReference.VBFriendlyName));
                     }
                     BaseReference.InvokeMethod(TargetProcedure, Arguments, (bool[])null, bindingFlags1);
                     return;
                 }
             }
             BindingFlags bindingFlags2 = BindingFlags.InvokeMethod | BindingFlags.GetProperty;
             if (Failure == OverloadResolution.ResolutionFailure.None || Failure == OverloadResolution.ResolutionFailure.MissingMember)
             {
                 Symbols.Method TargetProcedure = NewLateBinding.ResolveCall(BaseReference, MemberName, members, Symbols.NoArguments, Symbols.NoArgumentNames, TypeArguments, bindingFlags2, false, ref Failure);
                 if (Failure == OverloadResolution.ResolutionFailure.None)
                 {
                     object Instance1 = BaseReference.InvokeMethod(TargetProcedure, Symbols.NoArguments, (bool[])null, bindingFlags2);
                     if (Instance1 == null)
                     {
                         throw new MissingMemberException(Utils.GetResourceString("IntermediateLateBoundNothingResult1", TargetProcedure.ToString(), BaseReference.VBFriendlyName));
                     }
                     NewLateBinding.LateIndexSetComplex(Instance1, Arguments, ArgumentNames, OptimisticSet, true);
                     return;
                 }
             }
             if (!OptimisticSet)
             {
                 if (TypeArguments.Length == 0)
                 {
                     NewLateBinding.ResolveCall(BaseReference, MemberName, members, Arguments, ArgumentNames, TypeArguments, bindingFlags1, true, ref Failure);
                 }
                 else
                 {
                     NewLateBinding.ResolveCall(BaseReference, MemberName, members, Symbols.NoArguments, Symbols.NoArgumentNames, TypeArguments, bindingFlags2, true, ref Failure);
                 }
                 throw new InternalErrorException();
             }
         }
     }
 }
Beispiel #11
0
        public static object LateGet(object Instance, Type Type, string MemberName, object[] Arguments, string[] ArgumentNames, Type[] TypeArguments, bool[] CopyBack)
        {
            if (Arguments == null)
            {
                Arguments = Symbols.NoArguments;
            }
            if (ArgumentNames == null)
            {
                ArgumentNames = Symbols.NoArgumentNames;
            }
            if (TypeArguments == null)
            {
                TypeArguments = Symbols.NoTypeArguments;
            }
            Symbols.Container BaseReference = Type == null ? new Symbols.Container(Instance) : new Symbols.Container(Type);
            BindingFlags      bindingFlags  = BindingFlags.InvokeMethod | BindingFlags.GetProperty;

            if (BaseReference.IsCOMObject)
            {
                return(LateBinding.LateGet(Instance, Type, MemberName, Arguments, ArgumentNames, CopyBack));
            }
            MemberInfo[] members = BaseReference.GetMembers(ref MemberName, true);
            if (members[0].MemberType == MemberTypes.Field)
            {
                if (TypeArguments.Length > 0)
                {
                    throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue"));
                }
                object fieldValue = BaseReference.GetFieldValue((FieldInfo)members[0]);
                if (Arguments.Length == 0)
                {
                    return(fieldValue);
                }
                return(NewLateBinding.LateIndexGet(fieldValue, Arguments, ArgumentNames));
            }
            if (ArgumentNames.Length > Arguments.Length || CopyBack != null && CopyBack.Length != Arguments.Length)
            {
                throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue"));
            }
            OverloadResolution.ResolutionFailure Failure = OverloadResolution.ResolutionFailure.None;
            Symbols.Method TargetProcedure1 = NewLateBinding.ResolveCall(BaseReference, MemberName, members, Arguments, ArgumentNames, TypeArguments, bindingFlags, false, ref Failure);
            if (Failure == OverloadResolution.ResolutionFailure.None)
            {
                return(BaseReference.InvokeMethod(TargetProcedure1, Arguments, CopyBack, bindingFlags));
            }
            if (Arguments.Length > 0)
            {
                Symbols.Method TargetProcedure2 = NewLateBinding.ResolveCall(BaseReference, MemberName, members, Symbols.NoArguments, Symbols.NoArgumentNames, TypeArguments, bindingFlags, false, ref Failure);
                if (Failure == OverloadResolution.ResolutionFailure.None)
                {
                    object Instance1 = BaseReference.InvokeMethod(TargetProcedure2, Symbols.NoArguments, (bool[])null, bindingFlags);
                    if (Instance1 == null)
                    {
                        throw new MissingMemberException(Utils.GetResourceString("IntermediateLateBoundNothingResult1", TargetProcedure2.ToString(), BaseReference.VBFriendlyName));
                    }
                    object obj = NewLateBinding.InternalLateIndexGet(Instance1, Arguments, ArgumentNames, false, ref Failure);
                    if (Failure == OverloadResolution.ResolutionFailure.None)
                    {
                        return(obj);
                    }
                }
            }
            NewLateBinding.ResolveCall(BaseReference, MemberName, members, Arguments, ArgumentNames, TypeArguments, bindingFlags, true, ref Failure);
            throw new InternalErrorException();
        }