internal static object InvokeConstructorCallSite(Type type, bool isValueType, object[] arguments, string[] argumentNames, Type context, ref CallSite callSite) { LazyBinder binder = null; Type binderType = typeof(InvokeConstructorDummy); if (callSite == null || isValueType) { if (isValueType && arguments.Length == 0) //dynamic invocation doesn't see no argument constructors of value types { return(Activator.CreateInstance(type)); } binder = () => { var tList = GetBindingArgumentList(arguments, argumentNames, true); return(Binder.InvokeConstructor(CSharpBinderFlags.None, type, tList)); }; } if (isValueType || TypeFactorization.IsMonoRuntimeEnvironment) { CallSite dummyCallSite = null; return(DynamicInvokeStaticMember(type, ref dummyCallSite, binderType, binder, Invocation.ConstructorBinderName, true, type, argumentNames, type, arguments)); } return(MemberTargetTypeInvoke <Type, object>(ref callSite, binderType, binder, Invocation.ConstructorBinderName, true, type, argumentNames, type, arguments)); }
internal static void InvokeMemberActionCallSite(object target, InvokeMemberName name, object[] args, string[] tArgNames, Type tContext, bool tStaticContext, ref CallSite callSite) { LazyBinder tBinder = null; Type tBinderType = null; if (callSite == null) { tBinder = () => { IEnumerable <CSharpArgumentInfo> tList; tList = GetBindingArgumentList(args, tArgNames, tStaticContext); var tFlag = CSharpBinderFlags.ResultDiscarded; if (name.IsSpecialName) { tFlag |= CSharpBinderFlags.InvokeSpecialName; } return(Binder.InvokeMember(tFlag, name.Name, name.GenericArgs, tContext, tList)); }; tBinderType = typeof(InvokeMemberBinder); } InvokeMemberAction(ref callSite, tBinderType, KnownMember, tBinder, name, tStaticContext, tContext, tArgNames, target, args); }
internal static object InvokeConvertCallSite(object target, bool explict, Type type, Type context, ref CallSite callSite) { if (callSite == null) { LazyBinder binder = () => { var flags = explict ? CSharpBinderFlags.ConvertExplicit : CSharpBinderFlags.None; return(Binder.Convert(flags, type, context)); }; Type binderType = typeof(ConvertBinder); var func = BuildProxy.GenerateCallSiteFuncType(new Type[] {}, type); callSite = CreateCallSite(func, binderType, binder, explict ? Invocation.ExplicitConvertBinderName : Invocation.ImplicitConvertBinderName, context); } dynamic theDynamicCallSite = callSite; return(theDynamicCallSite.OriginalTarget(callSite, target)); }
internal static CallSite CreateCallSite( Type delegateType, Type specificBinderType, int knownType, LazyBinder binder, String_OR_InvokeMemberName name, Type context, string[] argNames = null, bool staticContext = false, bool isEvent = false ) { var tHash = BinderHash.Create(delegateType, name, context, argNames, specificBinderType, staticContext, isEvent, knownType != Unknown); lock (_binderCacheLock) { CallSite tOut; if (!TryDynamicCachedCallSite(tHash, knownType, out tOut)) { tOut = CallSite.Create(delegateType, binder()); SetDynamicCachedCallSite(tHash, knownType, tOut); } return(tOut); } }
internal static void InvokeMemberActionCallSite(object target, MemberInvocationMoniker name, object[] arguments, string[] argumentNames, Type context, bool staticContext, ref CallSite callSite) { LazyBinder binder = null; Type binderType = null; if (callSite == null) { binder = () => { var argumentBindingList = GetBindingArgumentList(arguments, argumentNames, staticContext); var flag = CSharpBinderFlags.ResultDiscarded; if (name.IsNameSpecial) { flag |= CSharpBinderFlags.InvokeSpecialName; } return(Binder.InvokeMember(flag, name.Name, name.GenericArguments, context, argumentBindingList)); }; binderType = typeof(InvokeMemberBinder); } MemberActionInvoke(ref callSite, binderType, binder, name, staticContext, context, argumentNames, target, arguments); }
internal static CallSite <T> CreateCallSite <T>( Type specificBinderType, int knownType, LazyBinder binder, string name, Type context, string[] argNames = null, bool staticContext = false, bool isEvent = false ) where T : class { var tHash = BinderHash <T> .Create(name, context, argNames, specificBinderType, staticContext, isEvent, knownType != Unknown); lock (_binderCacheLock) { CallSite <T> tOut; if (!TryDynamicCachedCallSite(tHash, knownType, out tOut)) { tOut = CallSite <T> .Create(binder()); SetDynamicCachedCallSite(tHash, knownType, tOut); } return(tOut); } }
internal static CallSite <T> CreateCallSite <T>( Type specificBinderType, LazyBinder binder, MemberInvocationMoniker name, Type context, string[] argumentNames = null, bool staticContext = false, bool isEvent = false) where T : class { var hashCode = BinderHashGenerator <T> .Create(name, context, argumentNames, specificBinderType, staticContext, isEvent); lock (_binderCacheLock) { CallSite callSite; if (!_binderCache.TryGetValue(hashCode, out callSite)) { callSite = CallSite <T> .Create(binder()); _binderCache[hashCode] = callSite; } return((CallSite <T>)callSite); } }
internal static object InvokeConstructorCallSite(Type type, bool isValueType, object[] args, string[] argNames, ref CallSite callSite) { LazyBinder tBinder = null; Type tBinderType = typeof(InvokeConstructorDummy); if (callSite == null || isValueType) { if (isValueType && args.Length == 0) //dynamic invocation doesn't see no argument constructors of value types { return(Activator.CreateInstance(type)); } tBinder = () => { var tList = GetBindingArgumentList(args, argNames, true); return(Binder.InvokeConstructor(CSharpBinderFlags.None, type, tList)); }; } if (isValueType || Util.IsMono) { CallSite tDummy = null; return(DynamicInvokeStaticMember(type, ref tDummy, tBinderType, KnownConstructor, tBinder, ConstructorName, true, type, argNames, type, args)); } return(InvokeMemberTargetType <Type, object>(ref callSite, tBinderType, KnownConstructor, tBinder, ConstructorName, true, type, argNames, type, args)); }
internal static CallSite CreateCallSite( Type delegateType, Type specificBinderType, int knownType, LazyBinder binder, InvokeMemberName name, Type context, string[] argNames = null, bool staticContext = false, bool isEvent = false ) { CallSite <DynamicCreateCallSite> tSite; bool foundInCache; lock (_callSiteCacheLock) { foundInCache = DynamicInvokeCreateCallSite.TryGetValue(delegateType, out tSite); } if (!foundInCache) { tSite = CallSite <DynamicCreateCallSite> .Create( Binder.InvokeMember( CSharpBinderFlags.None, "CreateCallSite", new[] { delegateType }, typeof(InvokeHelper), new[] { CSharpArgumentInfo.Create( CSharpArgumentInfoFlags.IsStaticType | CSharpArgumentInfoFlags.UseCompileTimeType, null), // InvokeHelper CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null), //binderType CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null), //knownType CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null), //binder CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null), //name CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null), //context CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null), //argnames CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null), //staticcontext CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null), //isevent } )); lock (_callSiteCacheLock) { // another thread might have been faster; add to dictionary only if we are the first if (!DynamicInvokeCreateCallSite.ContainsKey(delegateType)) { DynamicInvokeCreateCallSite[delegateType] = tSite; } } } return((CallSite)tSite.Target(tSite, typeof(InvokeHelper), specificBinderType, knownType, binder, name, context, argNames, staticContext, isEvent)); }
internal static bool InvokeIsEventCallSite(object target, string name, Type tContext, ref CallSite callSite) { if (callSite == null) { LazyBinder tBinder = () => Binder.IsEvent(CSharpBinderFlags.None, name, tContext); var tBinderType = typeof(IsEventBinderDummy); callSite = CreateCallSite <Func <CallSite, object, bool> >(tBinderType, Unknown, tBinder, name, tContext, isEvent: true); } var tCallSite = (CallSite <Func <CallSite, object, bool> >)callSite; return(tCallSite.Target(tCallSite, target)); }
public override object Invoke(Type[] types, object[] parameters, out Type returnType) { MethodInfo methodInfo = GetMethodInfo(types); if (methodInfo == null) { throw new MissingMethodException(MethodName); } returnType = methodInfo.ReturnType; return(LazyBinder.Invoke(methodInfo, _object, parameters)); }
internal static object InvokeGetIndexCallSite(object target, object[] indexes, string[] argNames, Type context, bool tStaticContext, ref CallSite callSite) { LazyBinder tBinder = null; Type tBinderType = null; if (callSite == null) { tBinder = () => { var tList = GetBindingArgumentList(indexes, argNames, tStaticContext); return(Binder.GetIndex(CSharpBinderFlags.None, context, tList)); }; tBinderType = typeof(GetIndexBinder); } return(InvokeMember <object>(ref callSite, tBinderType, tBinder, Invocation.IndexBinderName, tStaticContext, context, argNames, target, indexes)); }
internal static object InvokeDirectCallSite(object target, object[] args, string[] tArgNames, Type tContext, bool tStaticContext, ref CallSite callSite) { LazyBinder tBinder = null; Type tBinderType = null; if (callSite == null) { tBinder = () => { var tList = GetBindingArgumentList(args, tArgNames, tStaticContext); var tFlag = CSharpBinderFlags.None; return(Binder.Invoke(tFlag, tContext, tList)); }; tBinderType = typeof(InvokeBinder); } return(InvokeMember <object>(ref callSite, tBinderType, tBinder, String.Empty, tStaticContext, tContext, tArgNames, target, args)); }
internal static void InvokeSetIndexCallSite(object target, object[] indexesThenValue, string[] tArgNames, Type tContext, bool tStaticContext, ref CallSite tCallSite) { LazyBinder tBinder = null; Type tBinderType = null; if (tCallSite == null) { tBinder = () => { var tList = GetBindingArgumentList(indexesThenValue, tArgNames, tStaticContext); return(Binder.SetIndex(CSharpBinderFlags.None, tContext, tList)); }; tBinderType = typeof(SetIndexBinder); } InvokeMemberAction(ref tCallSite, tBinderType, tBinder, Invocation.IndexBinderName, tStaticContext, tContext, tArgNames, target, indexesThenValue); }
internal static dynamic DynamicInvokeStaticMember( Type returnType, ref CallSite callSite, Type binderType, LazyBinder binder, string name, bool staticContext, Type context, string[] argumentNames, Type target, params object[] arguments) { CallSite <DynamicInvokeMemberConstructorValueType> site; if (!_dynamicInvokeMemberSite.TryGetValue(returnType, out site)) { site = CallSite <DynamicInvokeMemberConstructorValueType> .Create( Binder.InvokeMember( CSharpBinderFlags.None, "InvokeMemberTargetType", new[] { typeof(Type), returnType }, typeof(InvocationMapping), new[] { CSharpArgumentInfo.Create( CSharpArgumentInfoFlags.IsStaticType | CSharpArgumentInfoFlags.UseCompileTimeType, null), CSharpArgumentInfo.Create( CSharpArgumentInfoFlags.UseCompileTimeType | CSharpArgumentInfoFlags.IsRef, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null), })); _dynamicInvokeMemberSite[returnType] = site; } return(site.Target(site, typeof(InvocationMapping), ref callSite, binderType, binder, name, staticContext, context, argumentNames, target, arguments)); }
internal static CallSite CreateCallSite( Type delegateType, Type specificBinderType, int knownType, LazyBinder binder, InvokeMemberName name, Type context, string[] argNames = null, bool staticContext = false, bool isEvent = false ) { CallSite <DynamicCreateCallSite> tSite; if (!_dynamicInvokeCreateCallSite.TryGetValue(delegateType, out tSite)) { tSite = CallSite <DynamicCreateCallSite> .Create( Binder.InvokeMember( CSharpBinderFlags.None, "CreateCallSite", new[] { delegateType }, typeof(InvokeHelper), new[] { CSharpArgumentInfo.Create( CSharpArgumentInfoFlags.IsStaticType | CSharpArgumentInfoFlags.UseCompileTimeType, null), // InvokeHelper CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null), //binderType CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null), //knownType CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null), //binder CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null), //name CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null), //context CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null), //argnames CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null), //staticcontext CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null), //isevent } )); _dynamicInvokeCreateCallSite[delegateType] = tSite; } return((CallSite)tSite.Target(tSite, typeof(InvokeHelper), specificBinderType, knownType, binder, name, context, argNames, staticContext, isEvent)); }
internal static void InvokeDirectActionCallSite(object target, object[] args, string[] tArgNames, Type tContext, bool tStaticContext, ref CallSite callSite) { LazyBinder tBinder = null; Type tBinderType = null; if (callSite == null) { tBinder = () => { IEnumerable <CSharpArgumentInfo> tList; tList = GetBindingArgumentList(args, tArgNames, tStaticContext); var tFlag = CSharpBinderFlags.ResultDiscarded; return(Binder.Invoke(tFlag, tContext, tList)); }; tBinderType = typeof(InvokeBinder); } InvokeMemberAction(ref callSite, tBinderType, tBinder, String.Empty, tStaticContext, tContext, tArgNames, target, args); }
internal static object InvokeDirectCallSite(object target, object[] arguments, string[] argumentNames, Type context, bool staticContext, ref CallSite callSite) { LazyBinder binder = null; Type binderType = null; if (callSite == null) { binder = () => { var bindingArgumentList = GetBindingArgumentList(arguments, argumentNames, staticContext); var flag = CSharpBinderFlags.None; return(Binder.Invoke(flag, context, bindingArgumentList)); }; binderType = typeof(InvokeBinder); } return(InvokeMember <object>(ref callSite, binderType, binder, String.Empty, staticContext, context, argumentNames, target, arguments)); }
internal static void InvokeSetIndexCallSite(object target, object[] indexesThenValue, string[] argumentNames, Type context, bool staticContext, ref CallSite callSite) { LazyBinder binder = null; Type binderType = null; if (callSite == null) { binder = () => { var bindingArgumentList = GetBindingArgumentList(indexesThenValue, argumentNames, staticContext); return(Binder.SetIndex(CSharpBinderFlags.None, context, bindingArgumentList)); }; binderType = typeof(SetIndexBinder); } MemberActionInvoke(ref callSite, binderType, binder, Invocation.IndexBinderName, staticContext, context, argumentNames, target, indexesThenValue); }
internal static object InvokeMemberCallSite(object target, String_OR_InvokeMemberName name, object[] args, string[] tArgNames, Type tContext, bool tStaticContext, ref CallSite callSite) { LazyBinder tBinder = null; Type tBinderType = null; if (callSite == null) { tBinder = () => { var tList = GetBindingArgumentList(args, tArgNames, tStaticContext); var tFlag = CSharpBinderFlags.None; if (name.IsSpecialName) { tFlag |= CSharpBinderFlags.InvokeSpecialName; } return(Binder.InvokeMember(tFlag, name.Name, name.GenericArgs, tContext, tList)); }; tBinderType = typeof(InvokeMemberBinder); } return(InvokeMember <object>(ref callSite, tBinderType, tBinder, name, tStaticContext, tContext, tArgNames, target, args)); }
internal static void InvokeDirectActionCallSite(object target, object[] arguments, string[] argumentNames, Type context, bool staticContext, ref CallSite callSite) { LazyBinder binder = null; Type binderType = null; if (callSite == null) { binder = () => { var bindingArgumentList = GetBindingArgumentList(arguments, argumentNames, staticContext); var flag = CSharpBinderFlags.ResultDiscarded; return(Binder.Invoke(flag, context, bindingArgumentList)); }; binderType = typeof(InvokeBinder); } MemberActionInvoke(ref callSite, binderType, binder, String.Empty, staticContext, context, argumentNames, target, arguments); }
internal static CallSite CreateCallSite( Type delegateType, Type specificBinderType, LazyBinder binder, String_OR_InvokeMemberName name, Type context, string[] argNames = null, bool staticContext = false, bool isEvent = false ) { var tHash = BinderHash.Create(delegateType, name, context, argNames, specificBinderType, staticContext, isEvent); lock (_binderCacheLock) { CallSite tOut; if (!_binderCache.TryGetValue(tHash, out tOut)) { tOut = CallSite.Create(delegateType, binder()); _binderCache[tHash] = tOut; } return(tOut); } }
internal static CallSite CreateCallSite( Type delegateType, Type specificBinderType, LazyBinder binder, MemberInvocationMoniker name, Type context, string[] argumentNames = null, bool staticContext = false, bool isEvent = false) { var hash = BinderHashGenerator.Create(delegateType, name, context, argumentNames, specificBinderType, staticContext, isEvent); lock (_binderCacheLock) { CallSite tOut; if (!_binderCache.TryGetValue(hash, out tOut)) { tOut = CallSite.Create(delegateType, binder()); _binderCache[hash] = tOut; } return(tOut); } }
internal static object InvokeConvertCallSite(object target, bool explict, Type type, Type context, ref CallSite callSite) { if (callSite == null) { LazyBinder tBinder = () => { var tFlags = explict ? CSharpBinderFlags.ConvertExplicit : CSharpBinderFlags.None; return(Binder.Convert(tFlags, type, context)); }; Type tBinderType = typeof(ConvertBinder); var tFunc = typeof(Func <, ,>).MakeGenericType(typeof(CallSite), typeof(object), type); callSite = CreateCallSite(tFunc, tBinderType, Unknown, tBinder, explict ? Invocation.ExplicitConvertBinderName : Invocation.ImplicitConvertBinderName, context); } dynamic tDynCallSite = callSite; return(tDynCallSite.Target(callSite, target)); }
internal static TReturn InvokeMember <TReturn>(ref CallSite callsite, Type binderType, LazyBinder binder, MemberInvocationMoniker name, bool staticContext, Type context, string[] argumentNames, object target, params object[] arguments) { return(MemberTargetTypeInvoke <object, TReturn>(ref callsite, binderType, binder, name, staticContext, context, argumentNames, target, arguments)); }
public override ValueExpression Evaluate(IParserContext context) { object methodObject = MethodExpression.Evaluate(context).Value; ValueExpression[] parameters = EvaluateExpressionArray(Parameters, context); Type[] parameterTypes = parameters.ConvertAll(expr => expr.Type); object[] parameterValues = parameters.ConvertAll(expr => expr.Value); if (methodObject is MethodDefinition) { Type returnType; return(Exp.Value(TokenPosition, ((MethodDefinition)methodObject).Invoke(parameterTypes, parameterValues, out returnType), returnType)); } if (methodObject is ConstructorInfo[]) { ConstructorInfo[] constructors = (ConstructorInfo[])methodObject; MethodBase method = LazyBinder.SelectBestMethod(constructors, parameterTypes, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance); if (method == null) { throw new ExpressionEvaluationException("No match found for constructor " + constructors[0].Name, this); } object value = LazyBinder.Invoke(method, parameterValues); //object value = ((ConstructorInfo)method).Invoke(parameterValues); return(Exp.Value(TokenPosition, value, method.DeclaringType)); } if (methodObject is Delegate[]) { Delegate[] delegates = (Delegate[])methodObject; MethodBase[] methods = delegates.ConvertAll <Delegate, MethodBase>(d => d.GetMethodInfo()); MethodBase method = LazyBinder.SelectBestMethod(methods, parameterTypes, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance); if (method == null) { throw new ExpressionEvaluationException("No match found for delegate " + MethodExpression, this); } object value = LazyBinder.Invoke(method, delegates[Array.IndexOf(methods, method)].Target, parameterValues); return(Exp.Value(TokenPosition, value, ((MethodInfo)method).ReturnType)); } if (methodObject is Delegate) { Delegate method = (Delegate)methodObject; MethodInfo methodInfo = method.GetMethodInfo(); object value = methodInfo.Invoke(method.Target, parameterValues); return(new ValueExpression(TokenPosition, value, methodInfo.ReturnType)); } if (methodObject is FunctionDefinitionExpression) { FunctionDefinitionExpression func = (FunctionDefinitionExpression)methodObject; var functionContext = context.CreateLocal(); for (int i = 0; i < parameterValues.Length; i++) { functionContext.Set(func.ParameterNames[i], parameterValues[i]); } return(func.Body.Evaluate(functionContext)); } throw new ExpressionEvaluationException(MethodExpression + " is not a function", this); }
internal static TReturn InvokeMember <TReturn>(ref CallSite callsite, Type binderType, int knownType, LazyBinder binder, InvokeMemberName name, bool staticContext, Type context, string[] argNames, object target, params object[] args) { return(InvokeMemberTargetType <object, TReturn>(ref callsite, binderType, knownType, binder, name, staticContext, context, argNames, target, args)); }
internal static dynamic DynamicInvokeStaticMember(Type tReturn, ref CallSite callsite, Type binderType, int knownType, LazyBinder binder, InvokeMemberName name, bool staticContext, Type context, string[] argNames, Type target, params object[] args) { CallSite <DynamicInvokeMemberConstructorValueType> tSite; if (!_dynamicInvokeMemberSite.TryGetValue(tReturn, out tSite)) { tSite = CallSite <DynamicInvokeMemberConstructorValueType> .Create( Binder.InvokeMember( CSharpBinderFlags.None, "InvokeMemberTargetType", new[] { typeof(Type), tReturn }, typeof(InvokeHelper), new[] { CSharpArgumentInfo.Create( CSharpArgumentInfoFlags.IsStaticType | CSharpArgumentInfoFlags.UseCompileTimeType, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType | CSharpArgumentInfoFlags.IsRef, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null), } ) ); _dynamicInvokeMemberSite[tReturn] = tSite; } return(tSite.Target(tSite, typeof(InvokeHelper), ref callsite, binderType, knownType, binder, name, staticContext, context, argNames, target, args)); }
internal static TReturn InvokeMemberTargetType <TTarget, TReturn>( ref CallSite callsite, Type binderType, LazyBinder binder, String_OR_InvokeMemberName name, bool staticContext, Type context, string[] argNames, TTarget target, params object [] args) { var tSwitch = args.Length; switch (tSwitch) { case 0: { var tCallSite = (CallSite <Func <CallSite, TTarget, TReturn> >)callsite; if (tCallSite == null) { tCallSite = CreateCallSite <Func <CallSite, TTarget, TReturn> >(binderType, binder, name, context, argNames, staticContext); callsite = tCallSite; } return(tCallSite.Target(tCallSite, target)); } case 1: { var tCallSite = (CallSite <Func <CallSite, TTarget, object, TReturn> >)callsite; if (tCallSite == null) { tCallSite = CreateCallSite <Func <CallSite, TTarget, object, TReturn> >(binderType, binder, name, context, argNames, staticContext); callsite = tCallSite; } return(tCallSite.Target(tCallSite, target, args[0])); } case 2: { var tCallSite = (CallSite <Func <CallSite, TTarget, object, object, TReturn> >)callsite; if (tCallSite == null) { tCallSite = CreateCallSite <Func <CallSite, TTarget, object, object, TReturn> >(binderType, binder, name, context, argNames, staticContext); callsite = tCallSite; } return(tCallSite.Target(tCallSite, target, args[0], args[1])); } case 3: { var tCallSite = (CallSite <Func <CallSite, TTarget, object, object, object, TReturn> >)callsite; if (tCallSite == null) { tCallSite = CreateCallSite <Func <CallSite, TTarget, object, object, object, TReturn> >(binderType, binder, name, context, argNames, staticContext); callsite = tCallSite; } return(tCallSite.Target(tCallSite, target, args[0], args[1], args[2])); } case 4: { var tCallSite = (CallSite <Func <CallSite, TTarget, object, object, object, object, TReturn> >)callsite; if (tCallSite == null) { tCallSite = CreateCallSite <Func <CallSite, TTarget, object, object, object, object, TReturn> >(binderType, binder, name, context, argNames, staticContext); callsite = tCallSite; } return(tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3])); } case 5: { var tCallSite = (CallSite <Func <CallSite, TTarget, object, object, object, object, object, TReturn> >)callsite; if (tCallSite == null) { tCallSite = CreateCallSite <Func <CallSite, TTarget, object, object, object, object, object, TReturn> >(binderType, binder, name, context, argNames, staticContext); callsite = tCallSite; } return(tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4])); } case 6: { var tCallSite = (CallSite <Func <CallSite, TTarget, object, object, object, object, object, object, TReturn> >)callsite; if (tCallSite == null) { tCallSite = CreateCallSite <Func <CallSite, TTarget, object, object, object, object, object, object, TReturn> >(binderType, binder, name, context, argNames, staticContext); callsite = tCallSite; } return(tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4], args[5])); } case 7: { var tCallSite = (CallSite <Func <CallSite, TTarget, object, object, object, object, object, object, object, TReturn> >)callsite; if (tCallSite == null) { tCallSite = CreateCallSite <Func <CallSite, TTarget, object, object, object, object, object, object, object, TReturn> >(binderType, binder, name, context, argNames, staticContext); callsite = tCallSite; } return(tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4], args[5], args[6])); } case 8: { var tCallSite = (CallSite <Func <CallSite, TTarget, object, object, object, object, object, object, object, object, TReturn> >)callsite; if (tCallSite == null) { tCallSite = CreateCallSite <Func <CallSite, TTarget, object, object, object, object, object, object, object, object, TReturn> >(binderType, binder, name, context, argNames, staticContext); callsite = tCallSite; } return(tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7])); } case 9: { var tCallSite = (CallSite <Func <CallSite, TTarget, object, object, object, object, object, object, object, object, object, TReturn> >)callsite; if (tCallSite == null) { tCallSite = CreateCallSite <Func <CallSite, TTarget, object, object, object, object, object, object, object, object, object, TReturn> >(binderType, binder, name, context, argNames, staticContext); callsite = tCallSite; } return(tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8])); } case 10: { var tCallSite = (CallSite <Func <CallSite, TTarget, object, object, object, object, object, object, object, object, object, object, TReturn> >)callsite; if (tCallSite == null) { tCallSite = CreateCallSite <Func <CallSite, TTarget, object, object, object, object, object, object, object, object, object, object, TReturn> >(binderType, binder, name, context, argNames, staticContext); callsite = tCallSite; } return(tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9])); } case 11: { var tCallSite = (CallSite <Func <CallSite, TTarget, object, object, object, object, object, object, object, object, object, object, object, TReturn> >)callsite; if (tCallSite == null) { tCallSite = CreateCallSite <Func <CallSite, TTarget, object, object, object, object, object, object, object, object, object, object, object, TReturn> >(binderType, binder, name, context, argNames, staticContext); callsite = tCallSite; } return(tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10])); } case 12: { var tCallSite = (CallSite <Func <CallSite, TTarget, object, object, object, object, object, object, object, object, object, object, object, object, TReturn> >)callsite; if (tCallSite == null) { tCallSite = CreateCallSite <Func <CallSite, TTarget, object, object, object, object, object, object, object, object, object, object, object, object, TReturn> >(binderType, binder, name, context, argNames, staticContext); callsite = tCallSite; } return(tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11])); } case 13: { var tCallSite = (CallSite <Func <CallSite, TTarget, object, object, object, object, object, object, object, object, object, object, object, object, object, TReturn> >)callsite; if (tCallSite == null) { tCallSite = CreateCallSite <Func <CallSite, TTarget, object, object, object, object, object, object, object, object, object, object, object, object, object, TReturn> >(binderType, binder, name, context, argNames, staticContext); callsite = tCallSite; } return(tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11], args[12])); } case 14: { var tCallSite = (CallSite <Func <CallSite, TTarget, object, object, object, object, object, object, object, object, object, object, object, object, object, object, TReturn> >)callsite; if (tCallSite == null) { tCallSite = CreateCallSite <Func <CallSite, TTarget, object, object, object, object, object, object, object, object, object, object, object, object, object, object, TReturn> >(binderType, binder, name, context, argNames, staticContext); callsite = tCallSite; } return(tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11], args[12], args[13])); } default: var tArgTypes = Enumerable.Repeat(typeof(object), tSwitch); var tDelagateType = BuildProxy.GenerateCallSiteFuncType(tArgTypes, typeof(TTarget)); return(Impromptu.InvokeCallSite(CreateCallSite(tDelagateType, binderType, binder, name, context, argNames), target, args)); } }
internal static void InvokeMemberAction(ref CallSite callsite, Type binderType, int knownType, LazyBinder binder, String_OR_InvokeMemberName name, bool staticContext, Type context, string[] argNames, object target, params object [] args) { var tSwitch = args.Length; switch (tSwitch) { #region Optimizations case 0: { var tCallSite = (CallSite <Action <CallSite, object> >)callsite; if (tCallSite == null) { tCallSite = CreateCallSite <Action <CallSite, object> >(binderType, knownType, binder, name, context, argNames, staticContext); callsite = tCallSite; } tCallSite.Target(tCallSite, target); break; } case 1: { var tCallSite = (CallSite <Action <CallSite, object, object> >)callsite; if (tCallSite == null) { tCallSite = CreateCallSite <Action <CallSite, object, object> >(binderType, knownType, binder, name, context, argNames, staticContext); callsite = tCallSite; } tCallSite.Target(tCallSite, target, args[0]); break; } case 2: { var tCallSite = (CallSite <Action <CallSite, object, object, object> >)callsite; if (tCallSite == null) { tCallSite = CreateCallSite <Action <CallSite, object, object, object> >(binderType, knownType, binder, name, context, argNames, staticContext); callsite = tCallSite; } tCallSite.Target(tCallSite, target, args[0], args[1]); break; } case 3: { var tCallSite = (CallSite <Action <CallSite, object, object, object, object> >)callsite; if (tCallSite == null) { tCallSite = CreateCallSite <Action <CallSite, object, object, object, object> >(binderType, knownType, binder, name, context, argNames, staticContext); callsite = tCallSite; } tCallSite.Target(tCallSite, target, args[0], args[1], args[2]); break; } case 4: { var tCallSite = (CallSite <Action <CallSite, object, object, object, object, object> >)callsite; if (tCallSite == null) { tCallSite = CreateCallSite <Action <CallSite, object, object, object, object, object> >(binderType, knownType, binder, name, context, argNames, staticContext); callsite = tCallSite; } tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3]); break; } case 5: { var tCallSite = (CallSite <Action <CallSite, object, object, object, object, object, object> >)callsite; if (tCallSite == null) { tCallSite = CreateCallSite <Action <CallSite, object, object, object, object, object, object> >(binderType, knownType, binder, name, context, argNames, staticContext); callsite = tCallSite; } tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4]); break; } case 6: { var tCallSite = (CallSite <Action <CallSite, object, object, object, object, object, object, object> >)callsite; if (tCallSite == null) { tCallSite = CreateCallSite <Action <CallSite, object, object, object, object, object, object, object> >(binderType, knownType, binder, name, context, argNames, staticContext); callsite = tCallSite; } tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4], args[5]); break; } case 7: { var tCallSite = (CallSite <Action <CallSite, object, object, object, object, object, object, object, object> >)callsite; if (tCallSite == null) { tCallSite = CreateCallSite <Action <CallSite, object, object, object, object, object, object, object, object> >(binderType, knownType, binder, name, context, argNames, staticContext); callsite = tCallSite; } tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4], args[5], args[6]); break; } case 8: { var tCallSite = (CallSite <Action <CallSite, object, object, object, object, object, object, object, object, object> >)callsite; if (tCallSite == null) { tCallSite = CreateCallSite <Action <CallSite, object, object, object, object, object, object, object, object, object> >(binderType, knownType, binder, name, context, argNames, staticContext); callsite = tCallSite; } tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]); break; } case 9: { var tCallSite = (CallSite <Action <CallSite, object, object, object, object, object, object, object, object, object, object> >)callsite; if (tCallSite == null) { tCallSite = CreateCallSite <Action <CallSite, object, object, object, object, object, object, object, object, object, object> >(binderType, knownType, binder, name, context, argNames, staticContext); callsite = tCallSite; } tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8]); break; } case 10: { var tCallSite = (CallSite <Action <CallSite, object, object, object, object, object, object, object, object, object, object, object> >)callsite; if (tCallSite == null) { tCallSite = CreateCallSite <Action <CallSite, object, object, object, object, object, object, object, object, object, object, object> >(binderType, knownType, binder, name, context, argNames, staticContext); callsite = tCallSite; } tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9]); break; } case 11: { var tCallSite = (CallSite <Action <CallSite, object, object, object, object, object, object, object, object, object, object, object, object> >)callsite; if (tCallSite == null) { tCallSite = CreateCallSite <Action <CallSite, object, object, object, object, object, object, object, object, object, object, object, object> >(binderType, knownType, binder, name, context, argNames, staticContext); callsite = tCallSite; } tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10]); break; } case 12: { var tCallSite = (CallSite <Action <CallSite, object, object, object, object, object, object, object, object, object, object, object, object, object> >)callsite; if (tCallSite == null) { tCallSite = CreateCallSite <Action <CallSite, object, object, object, object, object, object, object, object, object, object, object, object, object> >(binderType, knownType, binder, name, context, argNames, staticContext); callsite = tCallSite; } tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11]); break; } case 13: { var tCallSite = (CallSite <Action <CallSite, object, object, object, object, object, object, object, object, object, object, object, object, object, object> >)callsite; if (tCallSite == null) { tCallSite = CreateCallSite <Action <CallSite, object, object, object, object, object, object, object, object, object, object, object, object, object, object> >(binderType, knownType, binder, name, context, argNames, staticContext); callsite = tCallSite; } tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11], args[12]); break; } case 14: { var tCallSite = (CallSite <Action <CallSite, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object> >)callsite; if (tCallSite == null) { tCallSite = CreateCallSite <Action <CallSite, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object> >(binderType, knownType, binder, name, context, argNames, staticContext); callsite = tCallSite; } tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11], args[12], args[13]); break; } #endregion default: var tArgTypes = Enumerable.Repeat(typeof(object), tSwitch); var tDelagateType = BuildProxy.GenerateCallSiteFuncType(tArgTypes, typeof(void)); Impromptu.InvokeCallSite(CreateCallSite(tDelagateType, binderType, knownType, binder, name, context, argNames), target, args); break; } }