private static IGenericAspect CreateAspect(ITypedAspect aspect, IGenericAspect newAspect, IList mixins, IList pointcuts) { object[] aspectTargetAttributes = aspect.GetType().GetCustomAttributes(typeof(AspectTargetAttribute), false); if (aspectTargetAttributes != null) { AspectTargetAttribute aspectTargetAttribute = (AspectTargetAttribute)aspectTargetAttributes[0]; if (aspectTargetAttribute.TargetAttribute != null) { newAspect = new AttributeAspect(aspect.GetType().Name, aspectTargetAttribute.TargetAttribute, mixins, pointcuts); } else if (aspectTargetAttribute.TargetInterface != null) { newAspect = new InterfaceAspect(aspect.GetType().Name, aspectTargetAttribute.TargetInterface, mixins, pointcuts); } else if (aspectTargetAttribute.TargetSignature != null) { newAspect = new SignatureAspect(aspect.GetType().Name, aspectTargetAttribute.TargetSignature, mixins, pointcuts); } else if (aspectTargetAttribute.TargetType != null) { newAspect = new SignatureAspect(aspect.GetType().Name, aspectTargetAttribute.TargetType, mixins, pointcuts); } else { throw new Exception("No target specified"); } } return(newAspect); }
private void Form1_Load(object sender, EventArgs e) { Application.Idle += new EventHandler(Application_Idle); IEngine engine = new Engine("AopDraw"); InterfaceAspect canvasAwareAspect = new InterfaceAspect("canvasAwareAspect", typeof(Shape), new Type[] { typeof(CanvasAwareMixin) }, new IPointcut[] { new SignaturePointcut("set_*", new ShapePropertyInterceptor()) }); engine.Configuration.Aspects.Add(canvasAwareAspect); InterfaceAspect typeDescriptorAspect = new InterfaceAspect("typeDescriptorAspect", typeof(Shape), new Type[] { typeof(CustomTypeDescriptorMixin) }, new IPointcut[] { }); engine.Configuration.Aspects.Add(typeDescriptorAspect); InterfaceAspect guidAspect = new InterfaceAspect("guidAspect", typeof(Shape), new Type[] { typeof(GuidObject) }, new IPointcut[] { }); engine.Configuration.Aspects.Add(guidAspect); AttributeAspect resizableAspect = new AttributeAspect("resizableAspect", typeof(ResizableAttribute), new Type[] { typeof(ResizableShape2DMixin) }, new IPointcut[] { }); engine.Configuration.Aspects.Add(resizableAspect); AttributeAspect selectable2DAspect = new AttributeAspect("selectable2DAspect", typeof(SelectableAttribute), new Type[] { typeof(SelectableShape2DMixin) }, new IPointcut[] { }); engine.Configuration.Aspects.Add(selectable2DAspect); InterfaceAspect selectable1DAspect = new InterfaceAspect("selectable1DAspect", typeof(Shape1D), new Type[] { typeof(SelectableShape1DMixin) }, new IPointcut[] { }); engine.Configuration.Aspects.Add(selectable1DAspect); InterfaceAspect mouseEventAspect = new InterfaceAspect("mouseEventAspect", typeof(Shape), new Type[] { typeof(MouseHandlerMixin) }, new IPointcut[] { }); engine.Configuration.Aspects.Add(mouseEventAspect); AttributeAspect movableAspect = new AttributeAspect("movableAspect", typeof(MovableAttribute), new Type[] { typeof(MovableShape2DMixin) }, new IPointcut[] { }); engine.Configuration.Aspects.Add(movableAspect); InterfaceAspect movableShape1DAspect = new InterfaceAspect("movableShape1DAspect", typeof(Shape1D), new Type[] { typeof(MovableShape1DMixin) }, new IPointcut[] { }); engine.Configuration.Aspects.Add(movableShape1DAspect); AttributeAspect designableAspect = new AttributeAspect("designableAspect", typeof(DesignableAttribute), new Type[] { typeof(DesignableMixin) }, new IPointcut[] { }); engine.Configuration.Aspects.Add(designableAspect); SquareShape square = engine.CreateProxy<SquareShape>(); square.X = 10; square.Y = 10; square.Width = 100; square.Height = 100; canvas.AddShape(square); CircleShape circle = engine.CreateProxy<CircleShape>(); circle.X = 240; circle.Y = 120; circle.Width = 200; circle.Height = 200; canvas.AddShape(circle); rectangle = engine.CreateProxy<RectangleShape>(); rectangle.X = 50; rectangle.Y = 90; rectangle.Width = 200; rectangle.Height = 50; canvas.AddShape(rectangle); Line line = engine.CreateProxy<Line>(); line.X = 200; line.Y = 200; line.X2 = 400; line.Y2 = 340; canvas.AddShape(line); TextShape text = engine.CreateProxy<TextShape>(); text.X = 140; text.Y = 3; text.Width = 200; text.Height = 100; canvas.AddShape(text); }
private static IGenericAspect CreateAspect(ITypedAspect aspect, IGenericAspect newAspect, IList mixins, IList pointcuts) { object[] aspectTargetAttributes = aspect.GetType().GetCustomAttributes(typeof (AspectTargetAttribute), false); if (aspectTargetAttributes != null) { AspectTargetAttribute aspectTargetAttribute = (AspectTargetAttribute) aspectTargetAttributes[0]; if (aspectTargetAttribute.TargetAttribute != null) newAspect = new AttributeAspect(aspect.GetType().Name, aspectTargetAttribute.TargetAttribute, mixins, pointcuts); else if (aspectTargetAttribute.TargetInterface != null) newAspect = new InterfaceAspect(aspect.GetType().Name, aspectTargetAttribute.TargetInterface, mixins, pointcuts); else if (aspectTargetAttribute.TargetSignature != null) newAspect = new SignatureAspect(aspect.GetType().Name, aspectTargetAttribute.TargetSignature, mixins, pointcuts); else if (aspectTargetAttribute.TargetType != null) newAspect = new SignatureAspect(aspect.GetType().Name, aspectTargetAttribute.TargetType, mixins, pointcuts); else throw new Exception("No target specified"); } return newAspect; }