【问题标题】:M2DOC : How to pass a collection of objectsM2DOC:如何传递对象集合
【发布时间】:2020-03-27 22:29:00
【问题描述】:

是否可以将对象列表 (PhysicalComponent) 传递给我的自定义服务以阻止我遍历所有 PhysicalComponent ?

实际上我在我的 M2DOC 模板中这样迭代:

{m:for pc | self.eAllContents(pa::PhysicalComponent)}
{m:pc.MatrixFlow()}
{m:endfor}

【问题讨论】:

    标签: m2doc


    【解决方案1】:

    您可以使用以下签名创建服务:

    public SomeReturnType myService(List<PhysicalComponent> components) {
    ...
    }
    

    public SomeReturnType myService(Set<PhysicalComponent> components) {
    ...
    }
    

    public SomeReturnType myService(Collection<PhysicalComponent> components) {
    ...
    }
    

    那么你可以这样称呼它,例如:

    {m:self.eAllContents(pa::PhysicalComponent)->myService()}
    

    箭头表示将集合传递给服务,点表示在集合的每个元素上调用服务。

    如果您使用 Set 的 List 作为第一个参数,您可能需要使用 asSequence() 或 asOrderedSet():

    {m:self.eAllContents(pa::PhysicalComponent)->asSequence()->myService()}
    

    {m:self.eAllContents(pa::PhysicalComponent)->asOrderedSet()->myService()}
    

    【讨论】:

      猜你喜欢
      • 2023-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-26
      • 1970-01-01
      • 2014-11-04
      • 2019-01-25
      • 2018-09-27
      相关资源
      最近更新 更多