コード例 #1
0
        public void Intercept(IInvocation invocation)
        {
            var entity = invocation.InvocationTarget;

            if (Inited)
            {
                var joinDefine = metadata.GetClassJoinDefineMetadata(invocation.Method);
                if (joinDefine != null)
                {
                    if (joinDefine.JoinType == MethodJoinType.PropertySet)
                    {
                        var data = invocation.Arguments[0];
                        if (data == null)
                        {
                            caches.Remove(joinDefine.JoinName);
                        }
                        else
                        {
                            caches[joinDefine.JoinName] = data;
                        }
                        invocation.Proceed();
                        return;
                    }
                    else if (joinDefine.JoinType == MethodJoinType.PropertyGet)
                    {
                        if (caches.ContainsKey(joinDefine.JoinName))
                        {
                            invocation.ReturnValue = caches[joinDefine.JoinName];
                            return;
                        }
                    }

                    ProfilerContext.Current.Trace("platform", String.Format("intercept method {0}.{1}", invocation.Method.DeclaringType.ToPrettyString(), invocation.Method.Name));

                    log.DebugFormat("intercept property {0}.{1}", invocation.Method.DeclaringType.ToPrettyString(), invocation.Method.Name);
                    invocation.ReturnValue = joinDefine.DataProcesser.Process(entity);

                    if (joinDefine.JoinType == MethodJoinType.PropertyGet)
                    {
                        caches[joinDefine.JoinName] = invocation.ReturnValue;
                    }
                    return;
                }
            }
            invocation.Proceed();
        }
コード例 #2
0
 public bool ShouldInterceptMethod(Type type, MethodInfo methodInfo)
 {
     return(!SkippedTypes.Contains(methodInfo.DeclaringType) && metadata.GetClassJoinDefineMetadata(methodInfo) != null);
 }