public DynamicInstructionN(Type delegateType, CallSite site) { var methodInfo = delegateType.GetMethod("Invoke"); var parameters = methodInfo.GetParameters(); _target = CallInstruction.Create(methodInfo, parameters); _targetField = site.GetType().GetField("Target"); _site = site; _argCount = parameters.Length; }
public DynamicInstructionN(Type delegateType, CallSite site) { var methodInfo = delegateType.GetMethod("Invoke"); var parameters = methodInfo.GetParameters(); // <Delegate>.Invoke is ok to target by a delegate in partial trust (SecurityException is not thrown): _targetInvocationInstruction = CallInstruction.Create(methodInfo, parameters); _site = site; _argumentCount = parameters.Length - 1; _targetDelegate = site.GetType().GetInheritedFields("Target").First().GetValue(site); }
private bool TrackUsage(object[] args) { bool shouldOptimize; _hitCount++; shouldOptimize = false; bool forceCaller = false; if (_hitCount <= 100 && _caller == null) { foreach (object o in args) { // can't pass Missing.Value via reflection, use a ReflectedCaller if (o == Missing.Value) { forceCaller = true; } } } if (_hitCount > 100) { shouldOptimize = true; } else if ((_hitCount > 5 || forceCaller) && _caller == null) { _caller = CallInstruction.Create(_mi, _mi.GetParameters()); } return shouldOptimize; }