简体   繁体   中英

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

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>

Try this:

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM