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); }
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(); } } } }
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(); }