支持关系方面实现的.Net方面编织器

时间:2009-08-20 14:54:30

标签: .net aop aspectj

在AspectJ中实现关系方面,我可以通过以下方式关联两种类型的对象(请参阅下面的代码示例)。我想将此概念转移到.net。 你能指点我的.net weaver实现,这将允许我这样做或类似吗?

关系方面由Pearce& Sons设计。高贵。在此处阅读有关概念和实施的更多信息:http://homepages.ecs.vuw.ac.nz/~djp/RAL/index.html

我是AOP的新手,我从AspectJ中获取的知识有限。我已经确定设计受益于AspectJ支持intertype声明和泛型类型的能力,以及能够在“方面”单元内对编织规则和建议进行分组。

使用(简化)关系方面关联学生和课程对象的示例:

public class Course02 {
    public String title;
    public Course02(String title)   {this.title = title;    }
}

public class Student02 {
    public String name;
    public Student02(String name)   {this.name = name;  }
}

public aspect Attends02 extends SimpleStaticRel02<Student02, Course02> {}

public abstract aspect SimpleStaticRel02<FROM,TO>{ 

    public static interface Fwd{}
    public static interface Bwd{}

    declare parents : FROM implements Fwd;
    declare parents : TO implements Bwd;

    final private HashSet Fwd.fwd = new HashSet();
    final private HashSet Bwd.bwd = new HashSet();

    public boolean add(FROM _f, TO _t) {
        Fwd f = (Fwd) _f;
        Bwd t = (Bwd) _t;

        f.fwd.add(_t); // from adder to i fwd hashset
        return t.bwd.add(_f); // to adder from i bwd hashset
    }  

    public void printFwdCount(FROM _f)
    {
        Fwd f = (Fwd) _f;
        System.out.println("Count forward is: " + f.fwd.size());
    }

    public void printBwdCount(TO _t)
    {
        Bwd b  = (Bwd) _t;
        System.out.println("Count backward is: " + b.bwd.size());
    }

}

public class TestDriver {

    public TestDriver() {

        Course02 comp205 = new Course02("comp205");
        Course02 comp206 = new Course02("comp206");
        Student02 Joe = new Student02("Joe");
        Student02 Andreas = new Student02("Andreas");

        Attends02.aspectOf().add(Joe, comp205);
        Attends02.aspectOf().add(Joe, comp206);

        Attends02.aspectOf().printFwdCount(Andreas);
        Attends02.aspectOf().printFwdCount(Joe);
        Attends02.aspectOf().printBwdCount(comp206);
    }

    public static void main(String[] args) {
        new TestDriver();
    }
}

1 个答案:

答案 0 :(得分:0)

我对关系方面不熟悉,但你看过PostSharp吗?它是.NET的方面编织者中的顶级狗。我的猜测是他们支持关系方面。