Esempio n. 1
0
 public DynamicInstructionN(Type delegateType, CallSite site) {
     var methodInfo = delegateType.GetMethod("Invoke");
     _target = ReflectedCaller.Create(methodInfo);
     _targetField = site.GetType().GetField("Target");
     _site = site;
     _argCount = methodInfo.GetParameters().Length;
 }
Esempio n. 2
0
            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 = ReflectedCaller.Create(_mi);
                }
                return shouldOptimize;
            }
        private object InvokeMethod(object instance, object[] parameters) {
            if (_caller == null) {
                _caller = ReflectedCaller.Create(_method);
            }
            if (instance == null) {
                return _caller.Invoke(parameters);
            } else {
                return _caller.InvokeInstance(instance, parameters);
            }

        }