下面定义了两个集合,一个叫parent,一个叫child,都有一个属性为AdminEmails
<object id="parent" abstract="true" type="Example.ComplexObject, Examples">
<property name="AdminEmails">
<name-values>
<add key="administrator" value="administrator@example.com"/>
<add key="support" value="support@example.com"/>
</name-values>
</property>
</object>
<object id="child" parent="parent" >
<property name="AdminEmails">
<!-- the merge is specified on the *child* collection definition -->
<name-values merge="true">
<add key="sales" value="sales@example.com"/>
<add key="support" value="support@example.co.uk"/>
</name-values>
</property>
</object>
child集合的parent标签值为上面定义的parent,并且有一个标签名为<name-values merge="true">,表示需要合并这两个集合。注意有一个key与parent的key一样<add key="support" value="support@example.co.uk"/> ,它会覆盖parent的“support”,所以最后结果为:
administrator=administrator@example.com
sales=sales@example.com
support=support@example.co.uk