[英]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? 有点简单的新手问题...我知道如何创建字符串对象,但是如何创建int对象呢?
Here is the xml code fragment from my context file: 这是上下文文件中的xml代码片段:
<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" . 要创建基本类型System.Int32的对象,必须使用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.
属性factory-method =“ Copy”不起作用,因为它在System.Int32类型中不存在,因此您必须使用静态方法来执行此操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.