public static object FastDynamicInvoke(this Delegate functor, params object[] arguments) { if (functor.Method.ReturnType == typeof(void)) { InvocationMapping.DynamicInvokeAction(functor, arguments); return(null); } return(InvocationMapping.DynamicInvokeReturn(functor, arguments)); }
public static bool InvokeIsEvent(object target, string name) { Type context; bool staticContext; target = target.GetInvocationContext(out context, out staticContext); context = context.MaybeDetectArrayContext(); CallSite theCallSite = null; return(InvocationMapping.InvokeIsEventCallSite(target, name, context, ref theCallSite)); }
public static dynamic Conversion(object target, Type type, bool explict = false) { Type tContext; bool tDummy; target = target.GetInvocationContext(out tContext, out tDummy); CallSite tCallSite = null; return(InvocationMapping.InvokeConvertCallSite(target, explict, type, tContext, ref tCallSite)); }
public static CallSite <T> CreateCallSite <T>( CallSiteBinder binder, MemberInvocationMoniker name, Type context, string[] argumentNames = null, bool staticContext = false, bool isEvent = false) where T : class { return(InvocationMapping.CreateCallSite <T>(binder.GetType(), () => binder, name, context, argumentNames, staticContext, isEvent)); }
public static dynamic Invoke(object target, params object[] arguments) { string[] argumentNames; Type context; bool staticContext; target = target.GetInvocationContext(out context, out staticContext); arguments = TypeFactorization.ExtractArgumentNamesAndValues(arguments, out argumentNames); CallSite theCallSite = null; return(InvocationMapping.InvokeDirectCallSite(target, arguments, argumentNames, context, staticContext, ref theCallSite)); }
public static CallSite CreateCallSite( Type delegateType, CallSiteBinder binder, MemberInvocationMoniker name, Type context, string[] argumentNames = null, bool staticContext = false, bool isEvent = false) { return(InvocationMapping.CreateCallSite(delegateType, binder.GetType(), () => binder, name, context, argumentNames, staticContext, isEvent)); }
public static void InvokeMemberAction(object target, MemberInvocationMoniker name, params object[] arguments) { string[] argumentNames; Type context; bool staticContext; target = target.GetInvocationContext(out context, out staticContext); arguments = TypeFactorization.ExtractArgumentNamesAndValues(arguments, out argumentNames); CallSite theCallSite = null; InvocationMapping.InvokeMemberActionCallSite(target, name, arguments, argumentNames, context, staticContext, ref theCallSite); }
public static void InvokeSetIndex(object target, params object[] indexesThenValue) { string[] argNames; Type context; bool staticContext; target = target.GetInvocationContext(out context, out staticContext); indexesThenValue = TypeFactorization.ExtractArgumentNamesAndValues(indexesThenValue, out argNames); CallSite theCallSite = null; InvocationMapping.InvokeSetIndexCallSite(target, indexesThenValue, argNames, context, staticContext, ref theCallSite); }
internal static void InvokeSubtractAssignCallSite(object target, string name, object[] arguments, string[] argumentNames, Type context, bool staticContext, ref CallSite callSiteIsEvent, ref CallSite callSiteRemove, ref CallSite callSiteGet, ref CallSite callSiteSet) { if (InvokeIsEventCallSite(target, name, context, ref callSiteIsEvent)) { InvokeMemberActionCallSite(target, InvokeMemberByName.CreateSpecialName("remove_" + name), arguments, argumentNames, context, staticContext, ref callSiteRemove); } else { dynamic tGet = InvokeGetCallSite(target, name, context, staticContext, ref callSiteGet); tGet -= (arguments[0]); InvocationMapping.InvokeSetCallSite(target, name, tGet, context, staticContext, ref callSiteSet); } }
public static dynamic CreateInstance(Type type, params object[] arguments) { string[] argumentNames; bool isValue = type.IsValueType; if (isValue && arguments.Length == 0) //dynamic invocation doesn't see constructors of value types { return(Activator.CreateInstance(type)); } arguments = TypeFactorization.ExtractArgumentNamesAndValues(arguments, out argumentNames); CallSite theCallSite = null; var context = type.MaybeDetectArrayContext(); return(InvocationMapping.InvokeConstructorCallSite(type, isValue, arguments, argumentNames, context, ref theCallSite)); }
public static void InvokeAddAssign(object target, string name, object value) { CallSite callSiteAdd = null; CallSite callSiteGet = null; CallSite callSiteSet = null; CallSite callSiteIsEvent = null; Type context; bool staticContext; target = target.GetInvocationContext(out context, out staticContext); var args = new[] { value }; string[] argNames; args = TypeFactorization.ExtractArgumentNamesAndValues(args, out argNames); InvocationMapping.InvokeAddAssignCallSite(target, name, args, argNames, context, staticContext, ref callSiteIsEvent, ref callSiteAdd, ref callSiteGet, ref callSiteSet); }
public override object Invoke(object target, params object[] args) { var invocationContext = target as InvocationContext; if (invocationContext != null) { target = invocationContext.Target; } if (args == null) { args = new object[] { null }; } ValidateInvocationArguments(args); switch (Kind) { case InvocationKind.Constructor: var tTarget = (Type)target; return(InvocationMapping.InvokeConstructorCallSite(tTarget, tTarget.IsValueType, args, _argumentNames, _context, ref _callSite)); case InvocationKind.Convert: return(InvocationMapping.InvokeConvertCallSite(target, _convertExplict, _convertType, _context, ref _callSite)); case InvocationKind.Get: return(InvocationMapping.InvokeGetCallSite(target, Name.Name, _context, _staticContext, ref _callSite)); case InvocationKind.Set: InvocationMapping.InvokeSetCallSite(target, Name.Name, args[0], _context, _staticContext, ref _callSite); return(null); case InvocationKind.GetIndex: return(InvocationMapping.InvokeGetIndexCallSite(target, args, _argumentNames, _context, _staticContext, ref _callSite)); case InvocationKind.SetIndex: InvocationBinding.InvokeSetIndex(target, args); return(null); case InvocationKind.InvokeMember: return(InvocationMapping.InvokeMemberCallSite(target, Name, args, _argumentNames, _context, _staticContext, ref _callSite)); case InvocationKind.InvokeMemberAction: InvocationMapping.InvokeMemberActionCallSite(target, Name, args, _argumentNames, _context, _staticContext, ref _callSite); return(null); case InvocationKind.InvokeMemberUnknown: { try { var tObj = InvocationMapping.InvokeMemberCallSite(target, Name, args, _argumentNames, _context, _staticContext, ref _callSite); return(tObj); } catch (RuntimeBinderException) { InvocationMapping.InvokeMemberActionCallSite(target, Name, args, _argumentNames, _context, _staticContext, ref _callSite2); return(null); } } case InvocationKind.Invoke: return(InvocationMapping.InvokeDirectCallSite(target, args, _argumentNames, _context, _staticContext, ref _callSite)); case InvocationKind.InvokeAction: InvocationMapping.InvokeDirectActionCallSite(target, args, _argumentNames, _context, _staticContext, ref _callSite); return(null); case InvocationKind.InvokeUnknown: { try { var tObj = InvocationMapping.InvokeDirectCallSite(target, args, _argumentNames, _context, _staticContext, ref _callSite); return(tObj); } catch (RuntimeBinderException) { InvocationMapping.InvokeDirectActionCallSite(target, args, _argumentNames, _context, _staticContext, ref _callSite2); return(null); } } case InvocationKind.AddAssign: InvocationMapping.InvokeAddAssignCallSite(target, Name.Name, args, _argumentNames, _context, _staticContext, ref _callSite, ref _callSite2, ref _callSite3, ref _callSite4); return(null); case InvocationKind.SubtractAssign: InvocationMapping.InvokeSubtractAssignCallSite(target, Name.Name, args, _argumentNames, _context, _staticContext, ref _callSite, ref _callSite2, ref _callSite3, ref _callSite4); return(null); case InvocationKind.IsEvent: return(InvocationMapping.InvokeIsEventCallSite(target, Name.Name, _context, ref _callSite)); default: throw new InvalidOperationException("Unknown Invocation Kind: " + Kind); } }