你好,游客 登录 注册 搜索
背景:
阅读新闻

SPRING.NET 1.3.2 学习22--使用字段值进行注入 - lee576的专栏

[日期:2013-04-01] 来源:  作者: [字体: ]

FieldRetrievingFactoryObject类的功能和PropertyRetrievingFactoryObject很相似。如其名称所示,FieldRetrievingFactoryObject可以获取对象或类(指静态字段)的公有字段值。

下面的例子使用FieldRetrievingFactoryObject获取一个类的公有静态字段:

<object id="withTypesField" 
        type="Spring.Objects.Factory.Xml.XmlObjectFactoryTests+MyTestObject, Spring.Core.Tests">
  <property name="Types" ref="emptyTypesFactory"/>
</object>

<object id="emptyTypesFactory" 
        type="Spring.Objects.Factory.Config.FieldRetrievingFactoryObject, Spring.Core">
  <property name="TargetType" value="System.Type, Mscorlib"/>
    <property name="TargetField" value="EmPTytypeS"/>

</object>
      

获取公有实例字段的方法如下:

<object id="instanceCultureAware" 
        type="Spring.Objects.Factory.Xml.XmlObjectFactoryTests+MyTestObject, Spring.Core.Tests">
  <property name="Culture" ref="instanceCultureFactory"/>
</object>

<object id="instanceCultureFactory"
  type="Spring.Objects.Factory.Config.FieldRetrievingFactoryObject, Spring.Core">
  <property name="TargetObject" ref="instanceCultureAwareSource"/>
  <property name="TargetField" value="Default"/>

</object>

<object id="instanceCultureAwareSource" 
         type="Spring.Objects.Factory.Xml.XmlObjectFactoryTests+MyTestObject, Spring.Core.Tests"/>
    




收藏 推荐 打印 | 录入:admin | 阅读:
相关新闻