Exemple #1
0
        //添加Aspect和被拦截类的映射。缓存该信息已获得好的性能
        private void AddAspectMatch(IMethodMessage mmsg, AspectInfo aspectInfo, AspectActionPosition position)
        {
            bool match = (aspectInfo.ActionPosition.Equals("Both") || position.ToString().Equals(aspectInfo.ActionPosition));

            if (match)
            {
                //首先校验是否Match类
                if (aspectInfo.MatchClass.IndexOf("*") > -1)
                {
                    string clssName = aspectInfo.MatchClass;
                    if (clssName.StartsWith("*"))
                    {
                        clssName = clssName.Substring(1, clssName.Length - 1);
                    }
                    match = Regex.IsMatch(mmsg.MethodBase.ReflectedType.FullName, clssName);
                }
                else
                {
                    match = (mmsg.MethodBase.ReflectedType.FullName.Equals(aspectInfo.MatchClass) ||
                             mmsg.MethodBase.ReflectedType.Name.Equals(aspectInfo.MatchClass));
                }
                //校验是否Match方法
                if (match)
                {
                    match = mmsg.MethodBase.IsConstructor;
                    if (match)
                    {
                        match = (aspectInfo.PointCutType.IndexOf("Construction") > -1);
                    }
                    else
                    {
                        match = ((aspectInfo.PointCutType.IndexOf("Method") > -1) || (aspectInfo.PointCutType.IndexOf("Property") > -1));
                        if (match)
                        {
                            if (aspectInfo.MatchMethod.IndexOf("*") > -1)
                            {
                                string methodName = aspectInfo.MatchMethod;
                                if (methodName.StartsWith("*"))
                                {
                                    methodName = methodName.Substring(1, methodName.Length - 1);
                                }
                                match = Regex.IsMatch(mmsg.MethodName, methodName);
                            }
                            else
                            {
                                match = (mmsg.MethodName.Equals(aspectInfo.MatchMethod));
                            }
                        }
                    }
                }
            }
            _AspectsMatch[GetMatchHashKey(mmsg, aspectInfo, position)] = match;
        }
Exemple #2
0
 // 获取Aspect和被拦截类的映射的HashKey
 private string GetMatchHashKey(IMethodMessage mmsg, AspectInfo aspectInfo, AspectActionPosition position)
 {
     return(mmsg.MethodBase.ReflectedType.FullName + "--" + mmsg.MethodName + aspectInfo.MatchPattern + position.ToString());
 }