public static CallSite Get(int skipFrames) { // Account for ourselves skipFrames++; if (_stackFrameFast == null) { // This is terribad, this session is going to be soooo sloooooooooooow. // This will eventually happen when the .NET framework authors // excercise their right to change the private implementation we're // depending on. // Fall back to expensive full frame return new CallSite(new StackFrame(skipFrames, true)); } // Don't exactly know why we need to skip 2 and not 1 here. // I suspect expression tree trickery. var key = _stackFrameFast(skipFrames + 2); CallSite cached; if (_cache.TryGetValue(key, out cached)) return cached; var frame = new StackFrame(skipFrames, true); var callSite = new CallSite(frame); return _cache.GetOrAdd(key, callSite); }
internal OperatorInfo(CallSite callSite, MethodInfo operatorMethod) { _id = Interlocked.Increment(ref idCounter); _callSite = callSite; _operatorMethod = operatorMethod; _name = _operatorMethod.Name; _friendlyName = _name + "#" + _id; _anonymous = false; }
Func<IMethodCallMessage, IMethodReturnMessage> GetHandler(IMethodCallMessage call, System.Reflection.MethodInfo method, CallSite callSite) { if (call.MethodName == "GetAwaiter") { return ForwardCall; } var handler = _methodHandlerCache.GetOrAdd( method, _ => new Lazy<Func<IMethodCallMessage, IMethodReturnMessage>>( () => CreateHandler(call, method, callSite), LazyThreadSafetyMode.ExecutionAndPublication)); return handler.Value; }
Func<IMethodCallMessage, IMethodReturnMessage> CreateHandler(IMethodCallMessage call, System.Reflection.MethodInfo method, CallSite callSite) { // IConnectableObservable parameters if (call.MethodName == "RefCount") { return CreateRefCountHandler(call, method, CreateOperatorInfo(method, callSite)); } // IConnectableObservable return types if (Array.IndexOf(_connectableCandidates, call.MethodName) >= 0 && IsGenericTypeDefinition(method.ReturnType, typeof(IConnectableObservable<>))) { return c => HandleConnectableReturnType(c, method, CreateOperatorInfo(method, callSite)); } else if (IsGenericTypeDefinition(method.ReturnType, typeof(IObservable<>))) { return c => HandleObservableReturnType(c, method, CreateOperatorInfo(method, callSite)); } return ForwardCall; }
private static OperatorInfo CreateOperatorInfo(System.Reflection.MethodInfo method, CallSite callsite) { return new OperatorInfo(callsite, new MethodInfo(method)); }