Exemple #1
0
        public static object LateGet(object Instance, Type Type, string MemberName, object[] Arguments, string[] ArgumentNames, Type[] TypeArguments, bool[] CopyBack)
        {
            Symbols.Container container;
            if (Arguments == null)
            {
                Arguments = Symbols.NoArguments;
            }
            if (ArgumentNames == null)
            {
                ArgumentNames = Symbols.NoArgumentNames;
            }
            if (TypeArguments == null)
            {
                TypeArguments = Symbols.NoTypeArguments;
            }
            if (Type != null)
            {
                container = new Symbols.Container(Type);
            }
            else
            {
                container = new Symbols.Container(Instance);
            }
            if (container.IsCOMObject)
            {
                return(LateBinding.LateGet(Instance, Type, MemberName, Arguments, ArgumentNames, CopyBack));
            }
            IDynamicMetaObjectProvider instance = IDOUtils.TryCastToIDMOP(Instance);

            if ((instance != null) && (TypeArguments == Symbols.NoTypeArguments))
            {
                return(IDOBinder.IDOGet(instance, MemberName, Arguments, ArgumentNames, CopyBack));
            }
            return(ObjectLateGet(Instance, Type, MemberName, Arguments, ArgumentNames, TypeArguments, CopyBack));
        }
Exemple #2
0
 private static object InternalLateIndexGet(object Instance, object[] Arguments, string[] ArgumentNames, bool ReportErrors, ref OverloadResolution.ResolutionFailure Failure, bool[] CopyBack)
 {
     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(CallMethod(baseReference, "", Arguments, ArgumentNames, Symbols.NoTypeArguments, CopyBack, BindingFlags.GetProperty | BindingFlags.InvokeMethod, ReportErrors, ref Failure));
     }
     if (ArgumentNames.Length > 0)
     {
         Failure = OverloadResolution.ResolutionFailure.InvalidArgument;
         if (ReportErrors)
         {
             throw new ArgumentException(Utils.GetResourceString("Argument_InvalidNamedArgs"));
         }
         return(null);
     }
     ResetCopyback(CopyBack);
     return(baseReference.GetArrayValue(Arguments));
 }
Exemple #3
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();
             }
         }
     }
 }
Exemple #4
0
 public static void LateSet(object Instance, Type Type, string MemberName, object[] Arguments, string[] ArgumentNames, Type[] TypeArguments, bool OptimisticSet, bool RValueBase, CallType CallType)
 {
     Symbols.Container container;
     if (Arguments == null)
     {
         Arguments = Symbols.NoArguments;
     }
     if (ArgumentNames == null)
     {
         ArgumentNames = Symbols.NoArgumentNames;
     }
     if (TypeArguments == null)
     {
         TypeArguments = Symbols.NoTypeArguments;
     }
     if (Type != null)
     {
         container = new Symbols.Container(Type);
     }
     else
     {
         container = new Symbols.Container(Instance);
     }
     if (container.IsCOMObject)
     {
         try
         {
             LateBinding.InternalLateSet(Instance, ref Type, MemberName, Arguments, ArgumentNames, OptimisticSet, CallType);
             if (RValueBase && Type.IsValueType)
             {
                 throw new Exception(Utils.GetResourceString("RValueBaseForValueType", new string[] { Utils.VBFriendlyName(Type, Instance), Utils.VBFriendlyName(Type, Instance) }));
             }
         }
         catch when(?)
         {
         }
     }
     else
     {
         MemberInfo[] members = container.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 && container.IsValueType)
                 {
                     throw new Exception(Utils.GetResourceString("RValueBaseForValueType", new string[] { container.VBFriendlyName, container.VBFriendlyName }));
                 }
                 container.SetFieldValue((FieldInfo)members[0], Arguments[0]);
             }
             else
             {
                 LateIndexSetComplex(container.GetFieldValue((FieldInfo)members[0]), Arguments, ArgumentNames, OptimisticSet, true);
             }
         }
         else
         {
             OverloadResolution.ResolutionFailure failure;
             Symbols.Method method;
             BindingFlags   setProperty = BindingFlags.SetProperty;
             if (ArgumentNames.Length > Arguments.Length)
             {
                 throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue"));
             }
             if (TypeArguments.Length == 0)
             {
                 method = ResolveCall(container, MemberName, members, Arguments, ArgumentNames, Symbols.NoTypeArguments, setProperty, false, ref failure);
                 if (failure == OverloadResolution.ResolutionFailure.None)
                 {
                     if (RValueBase && container.IsValueType)
                     {
                         throw new Exception(Utils.GetResourceString("RValueBaseForValueType", new string[] { container.VBFriendlyName, container.VBFriendlyName }));
                     }
                     container.InvokeMethod(method, Arguments, null, setProperty);
                     return;
                 }
             }
             BindingFlags lookupFlags = BindingFlags.GetProperty | BindingFlags.InvokeMethod;
             switch (failure)
             {
             case OverloadResolution.ResolutionFailure.None:
             case OverloadResolution.ResolutionFailure.MissingMember:
                 method = ResolveCall(container, MemberName, members, Symbols.NoArguments, Symbols.NoArgumentNames, TypeArguments, lookupFlags, false, ref failure);
                 if (failure == OverloadResolution.ResolutionFailure.None)
                 {
                     object instance = container.InvokeMethod(method, Symbols.NoArguments, null, lookupFlags);
                     if (instance == null)
                     {
                         throw new MissingMemberException(Utils.GetResourceString("IntermediateLateBoundNothingResult1", new string[] { method.ToString(), container.VBFriendlyName }));
                     }
                     LateIndexSetComplex(instance, Arguments, ArgumentNames, OptimisticSet, true);
                     return;
                 }
                 break;
             }
             if (!OptimisticSet)
             {
                 if (TypeArguments.Length == 0)
                 {
                     ResolveCall(container, MemberName, members, Arguments, ArgumentNames, TypeArguments, setProperty, true, ref failure);
                 }
                 else
                 {
                     ResolveCall(container, MemberName, members, Symbols.NoArguments, Symbols.NoArgumentNames, TypeArguments, lookupFlags, true, ref failure);
                 }
                 throw new InternalErrorException();
             }
         }
     }
 }