0

一种简单的新手问题......我知道如何创建一个字符串对象,但我将如何创建一个 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>
4

2 回答 2

3

尝试这个:

<object id="MyInt" type="System.Int32" factory-method="Copy">
  <constructor-arg index="0">
    <value>123</value>
  </constructor-arg>
</object>
于 2013-07-02T23:28:16.333 回答
0

尝试这个:

<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 类型中,您必须使用静态方法来执行此操作。

于 2015-05-19T17:01:13.697 回答