本文整理汇总了C#中IReflect.InvokeMember方法的典型用法代码示例。如果您正苦于以下问题:C# IReflect.InvokeMember方法的具体用法?C# IReflect.InvokeMember怎么用?C# IReflect.InvokeMember使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IReflect
的用法示例。
在下文中一共展示了IReflect.InvokeMember方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CallCOMObject
private static object CallCOMObject(IReflect ir, string name, object ob, Binder binder, object[] arguments, ParameterModifier[] modifiers, CultureInfo culture, string[] namedParameters, bool construct, bool brackets, VsaEngine engine)
{
object obj3;
try
{
try
{
Change64bitIntegersToDouble(arguments);
BindingFlags invokeAttr = BindingFlags.OptionalParamBinding | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance;
if (construct)
{
return ir.InvokeMember(name, invokeAttr | BindingFlags.CreateInstance, binder, ob, arguments, modifiers, culture, namedParameters);
}
if (brackets)
{
try
{
return ir.InvokeMember(name, (invokeAttr | BindingFlags.GetProperty) | BindingFlags.GetField, binder, ob, arguments, modifiers, culture, namedParameters);
}
catch (TargetInvocationException)
{
object val = ir.InvokeMember(name, (invokeAttr | BindingFlags.GetProperty) | BindingFlags.GetField, binder, ob, new object[0], modifiers, culture, new string[0]);
return CallValue(val, arguments, construct, brackets, engine, val, binder, culture, namedParameters);
}
}
int num = (arguments == null) ? 0 : arguments.Length;
if (((namedParameters != null) && (namedParameters.Length > 0)) && (namedParameters[0].Equals("[DISPID=-613]") || namedParameters[0].Equals("this")))
{
num--;
}
invokeAttr |= (num > 0) ? (BindingFlags.GetProperty | BindingFlags.InvokeMethod) : BindingFlags.InvokeMethod;
obj3 = ir.InvokeMember(name, invokeAttr, binder, ob, arguments, modifiers, culture, namedParameters);
}
catch (MissingMemberException)
{
if (!brackets)
{
throw new JScriptException(JSError.FunctionExpected);
}
obj3 = null;
}
catch (COMException exception)
{
int errorCode = exception.ErrorCode;
switch (errorCode)
{
case -2147352570:
case -2147352573:
if (!brackets)
{
throw new JScriptException(JSError.FunctionExpected);
}
return null;
}
if ((errorCode & 0xffff0000L) == 0x800a0000L)
{
string source = exception.Source;
if ((source != null) && (source.IndexOf("JScript") != -1))
{
throw new JScriptException(exception, null);
}
}
throw exception;
}
}
catch (JScriptException exception2)
{
if ((exception2.Number & 0xffff) == 0x138a)
{
MemberInfo[] member = typeof(object).GetMember(name, BindingFlags.Public | BindingFlags.Instance);
if ((member != null) && (member.Length > 0))
{
return CallOneOfTheMembers(member, arguments, construct, ob, binder, culture, namedParameters, engine);
}
}
throw exception2;
}
return obj3;
}
示例2: InvokeMemberOnIReflect
internal static object InvokeMemberOnIReflect(IReflect objIReflect, MemberInfo member, BindingFlags flags, object target, object[] args)
{
VBBinder binder = new VBBinder(null);
binder.CacheMember(member);
return objIReflect.InvokeMember(member.Name, (BindingFlags.OptionalParamBinding | BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.IgnoreCase) | flags, binder, target, args, null, null, null);
}
示例3: InvokeMember
internal object InvokeMember(string name, BindingFlags invokeAttr, Type objType, IReflect objIReflect, object target, object[] args, string[] namedParameters)
{
object obj4;
if (objType.IsCOMObject)
{
ParameterModifier[] modifiers = null;
if (((this.m_ByRefFlags != null) && (target != null)) && !RemotingServices.IsTransparentProxy(target))
{
ParameterModifier modifier = new ParameterModifier(args.Length);
modifiers = new ParameterModifier[] { modifier };
object obj5 = Missing.Value;
int upperBound = args.GetUpperBound(0);
for (int i = 0; i <= upperBound; i++)
{
if (args[i] != obj5)
{
modifier[i] = this.m_ByRefFlags[i];
}
}
}
try
{
new SecurityPermission(PermissionState.Unrestricted).Demand();
return objIReflect.InvokeMember(name, invokeAttr, null, target, args, modifiers, null, namedParameters);
}
catch (MissingMemberException)
{
throw new MissingMemberException(Utils.GetResourceString("MissingMember_MemberNotFoundOnType2", new string[] { name, Utils.VBFriendlyName(objType) }));
}
}
this.m_BindToName = name;
this.m_objType = objType;
if (name.Length == 0)
{
if (objType == objIReflect)
{
name = this.GetDefaultMemberName(objType);
if (name == null)
{
throw new MissingMemberException(Utils.GetResourceString("MissingMember_NoDefaultMemberFound1", new string[] { Utils.VBFriendlyName(objType) }));
}
}
else
{
name = "";
}
}
MethodBase[] match = this.GetMethodsByName(objType, objIReflect, name, invokeAttr);
if (args == null)
{
args = new object[0];
}
object objState = null;
MethodBase member = this.BindToMethod(invokeAttr, match, ref args, null, null, namedParameters, ref objState);
if (member == null)
{
throw new MissingMemberException(Utils.GetResourceString("NoMethodTakingXArguments2", new string[] { this.CalledMethodName(), Conversions.ToString(this.GetPropArgCount(args, (invokeAttr & BindingFlags.SetProperty) != BindingFlags.Default)) }));
}
SecurityCheckForLateboundCalls(member, objType, objIReflect);
MethodInfo info = (MethodInfo) member;
if (((objType == objIReflect) || info.IsStatic) || LateBinding.DoesTargetObjectMatch(target, info))
{
LateBinding.VerifyObjRefPresentForInstanceCall(target, info);
obj4 = info.Invoke(target, args);
}
else
{
obj4 = LateBinding.InvokeMemberOnIReflect(objIReflect, info, BindingFlags.InvokeMethod, target, args);
}
if (objState != null)
{
this.ReorderArgumentArray(ref args, objState);
}
return obj4;
}
示例4: CallCOMObject
private static Object CallCOMObject(IReflect ir, String name, Object ob, Binder binder, Object[] arguments,
ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters,
bool construct, bool brackets, VsaEngine engine){
try{
try{
LateBinding.Change64bitIntegersToDouble(arguments);
BindingFlags flags =
BindingFlags.Public|BindingFlags.Instance|BindingFlags.Static|BindingFlags.OptionalParamBinding;
if (construct)
return ir.InvokeMember(name, flags|BindingFlags.CreateInstance, binder, ob, arguments, modifiers, culture, namedParameters);
else if (brackets){
// Expression like ob.name[args]. First try to invoke as an indexed property. If that
// results in a ArgumentException, try to evaluate (ob.name) and then invoke
// the default indexed property on the result.
try {
return ir.InvokeMember(name, flags|BindingFlags.GetProperty|BindingFlags.GetField, binder, ob, arguments, modifiers, culture, namedParameters);
}catch(TargetInvocationException){
Object ob1 = ir.InvokeMember(name, flags|BindingFlags.GetProperty|BindingFlags.GetField, binder, ob, new Object[0], modifiers, culture, new String[0]);
return LateBinding.CallValue(ob1, arguments, construct, brackets, engine, ob1, binder, culture, namedParameters);
}
}else{
int length = arguments == null ? 0 : arguments.Length;
if (namedParameters != null && namedParameters.Length > 0 && (namedParameters[0].Equals("[DISPID=-613]") || namedParameters[0].Equals("this")))
length--;
flags |= length > 0
? BindingFlags.InvokeMethod | BindingFlags.GetProperty
: BindingFlags.InvokeMethod;
return ir.InvokeMember(name, flags, binder, ob, arguments, modifiers, culture, namedParameters);
}
}catch(MissingMemberException){
if (brackets) //ob["x"]. Tried ob.Item()["x"] but failed. So return undefined.
return null;
else //ob("x"). Tried ob.Item()("x") but failed. Complain that ob is not a callable thing.
throw new JScriptException(JSError.FunctionExpected);
}
}catch(JScriptException e){
if ((e.Number & 0xFFFF) == (int)JSError.FunctionExpected){
//try to find a method on System.Object
MemberInfo[] members = Typeob.Object.GetMember(name, BindingFlags.Public|BindingFlags.Instance);
if (members != null && members.Length > 0)
return LateBinding.CallOneOfTheMembers(members, arguments, construct, ob, binder, culture, namedParameters, engine);
}
throw e;
}
}