简体   繁体   English

如何在IOC上下文文件中创建Int32类型的spring .Net独立对象?

[英]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.

相关问题 如何选择列表中的所有元素 <Int32> 进入另一个列表 <Int32> 与LINQ? - How do I select all elements in List<Int32> into another List<Int32> with LINQ? 如何创建一个泛型类型,其中T也可以是int32,但不仅仅是一个类 - How can I create a generic type where T also can be int32,but not only a class 如何格式化Int32数字? - How do I format Int32 numbers? 显示无法创建类型“”的常量值。 在这种情况下,仅支持基本类型(例如Int32,String和Guid) - Showing Unable to create a constant value of type ''. Only primitive types ('such as Int32, String, and Guid') are supported in this context int(Int32)被认为是.NET中的对象还是原语(不是int?)? - Is int (Int32) considered an object in .NET or a primitive (not int?)? SerialPort.Read(byte [],int32,int32)没有阻塞但我想要它 - 我该如何实现? - SerialPort.Read(byte[], int32, int32) is not blocking but i want it to - how do I achieve? 使用 CsvHelper 将子对象迭代到 CSV 文件 - 没有为类型定义属性“Int32” - Using CsvHelper to iterate child objects into CSV file - Property 'Int32' is not defined for type 如何确保传入的对象是基类型(String,Int16,Int32,Double ...)? - How to make sure that incoming object is a base type (String, Int16, Int32, Double…)? ASP.NET Web API - 没有“MediaTypeFormatter”可用于读取“Int32”类型的对象 - ASP.NET Web API - No 'MediaTypeFormatter' is available to read an object of type 'Int32' 无法创建类型为“结算类型”的常量值。 在这种情况下,仅支持基本类型(例如Int32,String和Guid) - Unable to create a constant value of type 'Closure type'. Only primitive types ('such as Int32, String, and Guid') are supported in this context
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM