如何在 Spring.NET 构造函数中使用复杂类型参数

发布于 2024-08-09 15:54:59 字数 544 浏览 1 评论 0原文

我正在尝试将 Spring.NET 与 C# 应用程序一起使用来填充复杂类型的参数数组(params 关键字)构造函数参数(称之为 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);

想法?

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) {...}
} 

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

此岸叶落 2024-08-16 15:54:59

我发布这个问题是为了分享我得出的答案,并看看是否有更深入了解 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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文