Beispiel #1
0
        public override void IL(ScanAopInfo info)
        {
            foreach (var method in info.Methods)
            {
                try
                {
                    var assembly = method.Assembly;
                    var attrs    = CommonHelper.GetAttribute(method.Method.CustomAttributes, typeof(AroundAopAttribute).FullName);
                    foreach (var attr in attrs)
                    {
                        //必须实现默认构造函数
                        if (InstuctionsHelper.LoadType(attr.AttributeType).GetConstructor(Type.EmptyTypes) == null)
                        {
                            throw new AopException(string.Format("Type:{0} 必须实现默认无参构造函数", attr.AttributeType.FullName));
                        }

                        var ilProcessor = method.Method.Body.GetILProcessor();
                        ilProcessor.Body.InitLocals = true;

                        assembly.MainModule.Import(attr.AttributeType.Resolve());

                        BeforeIL(method, attr);
                        AfterIL(method, attr);

                        //移除属性,下次不再注入
                        method.Method.CustomAttributes.Remove(attr);
                    }
                }
                catch (Exception exp)
                {
                    throw new AopException("AroundAopIL出错,方法:" + method.Method.FullName, exp);
                }
            }
        }
Beispiel #2
0
        public override void IL(ScanAopInfo info)
        {
            foreach (var aoptype in info.Types)
            {
                try
                {
                    var assembly = aoptype.Assembly; var type = aoptype.Type;
                    var find = CommonHelper.HasAttribute(type.CustomAttributes, typeof(NotifyPropertyChangedAopAttribute).FullName);
                    if (find)
                    {
                        PropertysIL(assembly, type);

                        //移除属性,包括重复定义
                        var attrs = CommonHelper.GetAttribute(type.CustomAttributes, typeof(NotifyPropertyChangedAopAttribute).FullName);
                        foreach (var attr in attrs)
                        {
                            type.CustomAttributes.Remove(attr);
                        }
                    }
                }
                catch (Exception exp)
                {
                    throw new AopException("NotifyPropertyAopIL出错,Type:" + aoptype.Type.FullName, exp);
                }
            }
        }
Beispiel #3
0
 public virtual void IL(ScanAopInfo info)
 {
 }