在 Spring.NET 中将类的类型作为值传递

发布于 2024-08-17 06:57:58 字数 844 浏览 4 评论 0原文

有没有办法将类的类型作为 Spring.NET 中的值传递?

我的字典看起来像这样:

private Dictionary<int, Type> ContentItemTypes { get; set; }

在代码中我将初始化为:

registry.addContentItemType(0, typeof(ContentItem));

How do you do this in Spring.NET。到目前为止我有这个:

<object id="ContentItemTypeRegistry"
      type="Edu3.DomainModel.Framework.Model.Registry.ContentItemTypeRegistry, Edu3.DomainModel.Framework"
      factory-method="GetInstance">
  <property name="ContentItemTypes">
    <dictionary key-type="int" value-type="System.Type">
      <entry key="0">
        <value type="System.Type">Edu3.DomainModel.Framework.Model.ContentItem</value>
      </entry>
    </dictionary>
  </property>
</object>

这是正确的吗?

Is there a way to pass a type of a class as the value in Spring.NET?

My Dictionary looks like this:

private Dictionary<int, Type> ContentItemTypes { get; set; }

In code I would initialize as:

registry.addContentItemType(0, typeof(ContentItem));

How do you do this in Spring.NET. So far I have this:

<object id="ContentItemTypeRegistry"
      type="Edu3.DomainModel.Framework.Model.Registry.ContentItemTypeRegistry, Edu3.DomainModel.Framework"
      factory-method="GetInstance">
  <property name="ContentItemTypes">
    <dictionary key-type="int" value-type="System.Type">
      <entry key="0">
        <value type="System.Type">Edu3.DomainModel.Framework.Model.ContentItem</value>
      </entry>
    </dictionary>
  </property>
</object>

Is this correct?

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

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

发布评论

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

评论(2

北方。的韩爷 2024-08-24 06:57:58

或者甚至更短。

<object id="ContentItemTypeRegistry"
 type="Edu3.DomainModel.Framework.Model.Registry.ContentItemTypeRegistry, Edu3.DomainModel.Framework"
 factory-method="GetInstance">
    <property name="ContentItemTypes">
      <dictionary key-type="int" value-type="System.Type">
        <entry key="0" expression="T(Edu3.DomainModel.Framework.Model.ContentItem)" ></entry>
      </dictionary>
    </property>
  </object>

Or even shorter.

<object id="ContentItemTypeRegistry"
 type="Edu3.DomainModel.Framework.Model.Registry.ContentItemTypeRegistry, Edu3.DomainModel.Framework"
 factory-method="GetInstance">
    <property name="ContentItemTypes">
      <dictionary key-type="int" value-type="System.Type">
        <entry key="0" expression="T(Edu3.DomainModel.Framework.Model.ContentItem)" ></entry>
      </dictionary>
    </property>
  </object>
洋洋洒洒 2024-08-24 06:57:58

或许:

  <object id="ContentItemTypeRegistry"
      type="Edu3.DomainModel.Framework.Model.Registry.ContentItemTypeRegistry, Edu3.DomainModel.Framework"
      factory-method="GetInstance">
    <property name="ContentItemTypes">
      <dictionary key-type="int" value-type="System.Type">
        <entry key="0" value-ref="ContentItemType" ></entry>
      </dictionary>
    </property>
  </object>

  <object id="ContentItemType" type="System.Type, System" factory-method="GetType" singleton="false">
    <constructor-arg value="Edu3.DomainModel.Framework.Model.ContentItem" />
  </object>

maybe:

  <object id="ContentItemTypeRegistry"
      type="Edu3.DomainModel.Framework.Model.Registry.ContentItemTypeRegistry, Edu3.DomainModel.Framework"
      factory-method="GetInstance">
    <property name="ContentItemTypes">
      <dictionary key-type="int" value-type="System.Type">
        <entry key="0" value-ref="ContentItemType" ></entry>
      </dictionary>
    </property>
  </object>

  <object id="ContentItemType" type="System.Type, System" factory-method="GetType" singleton="false">
    <constructor-arg value="Edu3.DomainModel.Framework.Model.ContentItem" />
  </object>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文