WF Rules对于迭代的实现

因为WF Rules 是针对Instance而非Type,也就是说针对单个对象而不是针对于集合,所以对于集合的规则来说,就显得实现起来非常麻烦,首先需要定义额外的属性,另外需要定义多个规则,而且要精心设计,才能实现迭代。典型的实现如下:
  Rule 1 (Priority = 2)  //Always execute this rule once to create the enumerator.
     IF 1==1
     THEN this.enumerator = this.myCollection.GetEnumerator()
  Rule2 (Priority = 1)
     IF this.enumerator.MoveNext()
     THEN this.currentInstance = this.enumerator.Current
 Rules 3-N (Priority = 0)
      .... //Additional rules written against this.currentInstance
  Rule N+1 (Priority = -1)
           // can be any condition as long as it is evaluated every time;
           // this.currentInstance will be evaluated each time this.currentInstance changes, whereas
            // "1==1" would only be evaluated once.
       IF this.currentInstance == this.currentInstance  
       THEN ...
            Update("this/enumerator") //this will cause Rule 2 to be reevaluated
        ELSE ...
            Update("this/enumerator")

这种模式仅仅能够实现一个Collection,若存在多个collection或者存在层次机构的Collection的话,必须依次实现多个Collection的迭代。

可见这是非常麻烦的。因为WF并非是基于Rete算法的实现(其基于类型和集合,而非Instance),所以只能这么麻烦了,期待WF的下一个版本吧。
posted @ 2007-07-23 10:51  headchen  阅读(211)  评论(0编辑  收藏  举报