开发者

How to use complex Type params argument in Spring.NET constructor

I am trying to use Spring.NET with a C# application to populate a parameter array (params keyword) constructor argument that is of a complex Type (call it SecretCode, which happens to be an enumerated type.)

Can someone help point me to the documentation to configure the XML file to do this?

For reference, here are relevant code snippets:

public class MyValueSet<T> where T: struct
{
  public MyValueSet(params T[] values) {...}
开发者_StackOverflow中文版} 

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

public enum SecretCode {...}

The hard-coded code I am trying replace with the Spring.NET configuration file is (close enough to) this:

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

Thoughts?


I posted the question in order to share the answer I came up with, and to see if anyone who knows Spring.NET more thoroughly had a better answer.

The configuration I ended up with is this:

<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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜