如何在Spring.NET构造函数中使用复杂的Type params参数

时间:2009-11-03 18:55:50

标签: constructor spring.net params params-keyword

我正在尝试将Spring.NET与C#应用程序一起使用来填充一个复杂Type的参数数组(params keyword)构造函数参数(称之为SecretCode,恰好是枚举类型。)

有人可以帮我指点配置XML文件的文档来执行此操作吗?

供参考,以下是相关的代码片段:

public class MyValueSet<T> where T: struct
{
  public MyValueSet(params T[] values) {...}
} 

public class DerivedClass : MyValueSet<SecretCode> {...}

public enum SecretCode {...}

我正在尝试使用Spring.NET配置文件替换的硬编码代码(足够接近):

var something = new DerivedClass(SecretCode.One, SecretCode.Two, SecretCode.Fifty-Two);

思考?

1 个答案:

答案 0 :(得分:1)

我发布了这个问题,以便分享我提出的答案,看看是否有人更了解Spring.NET有更好的答案。

我最终得到的配置是:

<object id="myobject" type="DerivedClass, Assembly.Containing.The.DerivedClass">
  <constructor-arg name="values">
    <list element-type="SecretCode, Assembly.Containing.The.SecretCode.Enumeration">
      <value>One</value>
      <value>Two</value>
      <value>Fifty-Two</value>
    </list>
  </constructor-arg>
</object>