public void AddAopHandler(MethodBase methodBase, IList methodHandlers)
        {
            if (usageAttribute)
            {
                AddAopHandlerByUsageAttribute(methodBase, methodHandlers);
            }
            else
            {
                CallerInfoHandler handler;

                if (cachedHandlers == null)
                {
                    cachedHandlers = new Dictionary <MethodBase, CallerInfoHandler>();
                }

                if (!cachedHandlers.TryGetValue(methodBase, out handler))
                {
                    var             parameters = methodBase.GetParameters();
                    string          paramName  = this.parameterName;
                    CallerParamInfo paramInfo  = null;
                    for (int i = 0, len = parameters.Length; i < len; i++)
                    {
                        var p = parameters[i];
                        if (p.Name == paramName)
                        {
                            paramInfo = new CallerParamInfo(i, this.callerType);
                            break;
                        }
                    }

                    if (paramInfo == null)
                    {
                        throw new AopMethodParameterNotFoundException(methodBase.DeclaringType, methodBase.Name, paramName);
                    }
                    handler = new CallerInfoHandler(offset, new CallerParamInfo[] { paramInfo });
                    cachedHandlers[methodBase] = handler;
                }

                if (handler != null)
                {
                    methodHandlers.Add(handler);
                }
            }
        }
        private void AddAopHandlerByUsageAttribute(MethodBase methodBase, IList methodHandlers)
        {
            CallerInfoHandler callerInfo;

            if (cachedStaticHandlers == null)
            {
                cachedStaticHandlers = new Dictionary <MethodBase, CallerInfoHandler>();
            }

            if (!cachedStaticHandlers.TryGetValue(methodBase, out callerInfo))
            {
                int offset     = 0;
                var callerAttr = methodBase.GetCustomAttribute <CallerFrameOffsetAttribute>(false);
                if (callerAttr != null)
                {
                    offset = callerAttr.FrameOffset;
                    offset = Math.Max(offset, 0);
                }

                var ps = methodBase.GetParameters();
                List <CallerParamInfo> callerParameters = null;
                CallerParamInfo        callerParameter;
                for (int i = 0, len = ps.Length; i < len; i++)
                {
                    var p = ps[i];
                    callerParameter = null;

                    if (p.IsDefined(typeof(CallerMemberNameAttribute), false))
                    {
                        callerParameter = new CallerParamInfo(i, CallerParameterType.MemberName);
                    }
                    else if (p.IsDefined(typeof(CallerFilePathAttribute), false))
                    {
                        callerParameter = new CallerParamInfo(i, CallerParameterType.FilePath);
                    }
                    else if (p.IsDefined(typeof(CallerLineNumberAttribute), false))
                    {
                        callerParameter = new CallerParamInfo(i, CallerParameterType.LineNumber);
                    }

                    if (callerParameter != null)
                    {
                        if (callerParameters == null)
                        {
                            callerParameters = new List <CallerParamInfo>();
                        }
                        callerParameters.Add(callerParameter);
                    }
                }

                if (callerParameters == null || callerParameters.Count == 0)
                {
                    callerInfo = null;
                }
                else
                {
                    callerInfo = new CallerInfoHandler(offset, callerParameters.ToArray());
                }
                cachedStaticHandlers[methodBase] = callerInfo;
            }

            if (callerInfo != null)
            {
                methodHandlers.Add(callerInfo);
            }
        }