How do I create a spring .Net standalone object of type Int32 defined in the IOC context file?

允我心安 提交于 2019-12-11 19:26:15

问题


Kind of a simple newbie question...I see how I can create a string object, but how would I create an int object?

Here is the xml code fragment from my context file:

<object id="myString" type="System.String">
  <constructor-arg value="foo" />    
</object>
<object id="myInt" type="System.Int32">
   <<<**** how do I set this ****>>>>
</object>

回答1:


Try this:

<object id="MyInt" type="System.Int32" factory-method="Copy">
  <constructor-arg index="0">
    <value>123</value>
  </constructor-arg>
</object>



回答2:


Try this:

<object id="MyInt" type="System.Int32" factory-method="Parse">
  <constructor-arg index="0">
    <value>123</value>
  </constructor-arg>
</object>

For creating an object of primitive type System.Int32, you must use the factory-method="Parse". The attribute factory-method="Copy" doesn't works because it not exists in the type System.Int32 and you have to use a static method to do it.



来源:https://stackoverflow.com/questions/17437040/how-do-i-create-a-spring-net-standalone-object-of-type-int32-defined-in-the-ioc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!