Ejemplo n.º 1
0
        public static object LateCall(object Instance, Type Type, string MemberName, object[] Arguments, string[] ArgumentNames, Type[] TypeArguments, bool[] CopyBack, bool IgnoreReturn)
        {
            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)
            {
                return(LateBinding.InternalLateCall(Instance, Type, MemberName, Arguments, ArgumentNames, CopyBack, IgnoreReturn));
            }
            BindingFlags InvocationFlags = BindingFlags.InvokeMethod | BindingFlags.GetProperty;

            if (IgnoreReturn)
            {
                InvocationFlags |= BindingFlags.IgnoreReturn;
            }
            OverloadResolution.ResolutionFailure Failure = OverloadResolution.ResolutionFailure.None;
            return(NewLateBinding.CallMethod(BaseReference, MemberName, Arguments, ArgumentNames, TypeArguments, CopyBack, InvocationFlags, true, ref Failure));
        }
Ejemplo n.º 2
0
 public static bool LateCanEvaluate(object instance, Type type, string memberName, object[] arguments, bool allowFunctionEvaluation, bool allowPropertyEvaluation)
 {
     Symbols.Container container = type == null ? new Symbols.Container(instance) : new Symbols.Container(type);
     MemberInfo[]      members   = container.GetMembers(ref memberName, false);
     if (members.Length == 0)
     {
         return(true);
     }
     if (members[0].MemberType == MemberTypes.Field)
     {
         if (arguments.Length == 0 || new Symbols.Container(container.GetFieldValue((FieldInfo)members[0])).IsArray)
         {
             return(true);
         }
         return(allowPropertyEvaluation);
     }
     if (members[0].MemberType == MemberTypes.Method)
     {
         return(allowFunctionEvaluation);
     }
     if (members[0].MemberType == MemberTypes.Property)
     {
         return(allowPropertyEvaluation);
     }
     return(true);
 }
Ejemplo n.º 3
0
 internal static object InternalLateIndexGet(object Instance, object[] Arguments, string[] ArgumentNames, bool ReportErrors, ref OverloadResolution.ResolutionFailure Failure)
 {
     Failure = OverloadResolution.ResolutionFailure.None;
     if (Arguments == null)
     {
         Arguments = Symbols.NoArguments;
     }
     if (ArgumentNames == null)
     {
         ArgumentNames = Symbols.NoArgumentNames;
     }
     Symbols.Container BaseReference = new Symbols.Container(Instance);
     if (BaseReference.IsCOMObject)
     {
         return(LateBinding.LateIndexGet(Instance, Arguments, ArgumentNames));
     }
     if (!BaseReference.IsArray)
     {
         return(NewLateBinding.CallMethod(BaseReference, "", Arguments, ArgumentNames, Symbols.NoTypeArguments, (bool[])null, BindingFlags.InvokeMethod | BindingFlags.GetProperty, ReportErrors, ref Failure));
     }
     if (ArgumentNames.Length <= 0)
     {
         return(BaseReference.GetArrayValue(Arguments));
     }
     Failure = OverloadResolution.ResolutionFailure.InvalidArgument;
     if (ReportErrors)
     {
         throw new ArgumentException(Utils.GetResourceString("Argument_InvalidNamedArgs"));
     }
     return((object)null);
 }
Ejemplo n.º 4
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();
             }
         }
     }
 }
Ejemplo n.º 5
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);
 }
Ejemplo n.º 6
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;
Ejemplo n.º 7
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();
             }
         }
     }
 }
Ejemplo n.º 8
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();
        }