示例#1
0
        public static MethodInfo[] getALLMethod(Type t)
        {
            var methods = new List <MethodInfo>();

            foreach (var method in t.GetMethods())
            {
                if (AOPAttribute.IsAOPAttribute(method))
                {
                    if (!method.IsVirtual)
                    {
                        throw new AOPException($"{method.Name} is not a virtual method");
                    }
                    methods.Add(method);
                }
                //AOPAttribute aOPAttribute = AOPAttribute.GetAOPAttribute(method);
                //if (aOPAttribute != null)
                //{
                //    if (!method.IsVirtual)
                //    {
                //        throw new AOPException($"{method.Name} is not a virtual method");
                //    }
                //    methods.Add(method);
                //}
            }

            return(methods.ToArray());
        }
示例#2
0
        public static AOPAttribute GetAOPAttribute(MethodInfo methodInfo)
        {
            var          type         = methodInfo.DeclaringType;
            var          methodName   = methodInfo.Name;
            AOPAttribute aopAttribute = (AOPAttribute)Attribute.GetCustomAttribute(type, typeof(AOPAttribute));

            if (aopAttribute == null)
            {
                if (methodName.StartsWith("get_") || methodName.StartsWith("set_"))
                {
                    //获取属性的注解
                    var baseProperty = type.GetProperty(methodName.Substring(4));
                    if (baseProperty != null)
                    {
                        aopAttribute = (AOPAttribute)Attribute.GetCustomAttribute(baseProperty, typeof(AOPAttribute));
                    }
                }
                else
                {
                    //获取方法的注解
                    aopAttribute = (AOPAttribute)Attribute.GetCustomAttribute(methodInfo, typeof(AOPAttribute));
                }
            }
            return(aopAttribute);
        }
示例#3
0
        public Object Call(String methodName, MulticastDelegate methodDelegate, params Object[] args)
        {
            var baseType   = methodDelegate.Method.DeclaringType.BaseType;
            var baseMethod = baseType.GetMethod(methodName);
            //获取类上的注解
            AOPAttribute aopAttribute = AOPAttribute.GetAOPAttribute(baseMethod);

            if (aopAttribute != null)
            {
                return(aopAttribute.Invoke(methodName, methodDelegate, args));
            }

            return(methodDelegate.Method.Invoke(methodDelegate.Target, args));
        }