一种简单的新手问题......我知道如何创建一个字符串对象,但我将如何创建一个 int 对象?
这是我的上下文文件中的 xml 代码片段:
<object id="myString" type="System.String">
<constructor-arg value="foo" />
</object>
<object id="myInt" type="System.Int32">
<<<**** how do I set this ****>>>>
</object>
一种简单的新手问题......我知道如何创建一个字符串对象,但我将如何创建一个 int 对象?
这是我的上下文文件中的 xml 代码片段:
<object id="myString" type="System.String">
<constructor-arg value="foo" />
</object>
<object id="myInt" type="System.Int32">
<<<**** how do I set this ****>>>>
</object>
尝试这个:
<object id="MyInt" type="System.Int32" factory-method="Copy">
<constructor-arg index="0">
<value>123</value>
</constructor-arg>
</object>
尝试这个:
<object id="MyInt" type="System.Int32" factory-method="Parse">
<constructor-arg index="0">
<value>123</value>
</constructor-arg>
</object>
要创建原始类型 System.Int32 的对象,您必须使用factory-method="Parse"。属性 factory-method="Copy" 不起作用,因为它不存在于 System.Int32 类型中,您必须使用静态方法来执行此操作。