2013-07-24 25 views
0

注入通用的IList我在命名空间Device.Control枚举...从spring.net

public enum State { 
    IN_PROGRESS, SUSPENDED, HALTED, FINISHED 
} 

而且我有一个类...

public class CustomStateManager { 
    public IList<State> ManagingStates { get; set; } 
} 

下面是我的配置XML为spring.net ...

<object id="MyStateManager" type="CustomStateManager"> 
    <property name="ManagingStates"> 
     <list> 
      <value>SUSPENDED</value> 
      <value>HALTED</value> 
     </list> 
    </property> 
</object> 

建设,并试图注入MyStateManager对象后,spring.NET抱怨说,它不能设置个e对象的ManagingStates属性。我得到这个错误...

错误创建名为 'MyStateManager' 中所定义 '文件 [Spring.xml] 3' 线对象:错误设置属性值: PropertyAccessExceptionsException(1个错误);嵌套0​​PropertyAccessExceptions是:[Spring.Core.TypeMismatchException: 无法类型的属性值转换[System.Collections.ArrayList] 所需类型 [System.Collections.Generic.IList 1[[SandboxConsole.Device.Control.ApplicationEnumerations+State, SandboxConsole, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]] for property 'ManagingStates'., Inner Exception: Spring.Core.TypeMismatchException: Cannot convert property value of type [System.Collections.ArrayList] to required type [System.Collections.Generic.IList 1 [[SandboxConsole.Device.Control.ApplicationEnumerations +国家, SandboxConsole,版本= 1.0.0.0,文化=中立, 公钥=空]]]财产 'ManagingStates' ......

我有点新Spring.NET,我想不通除了它不能将一个ArrayList注入到IList属性中外,这里列出的问题是什么。 是否有可能在值为枚举类型的配置中创建列表?如果是这样,怎么样?

回答

2

您必须指定element-type

<list element-type="Namespace.State, Assembly"> 
    <value>SUSPENDED</value> 
    <value>HALTED</value> 
</list> 

其中命名空间是你的类和大会包含您的枚举组件的命名空间。

<list element-type="SandboxConsole.Device.Control.ApplicationEnumerations+State, SandboxConsole"> 
    <value>SUSPENDED</value> 
    <value>HALTED</value> 
</list> 

ApplicationEnumerations +国家因为您尝试访问一个内部类。

http://www.springframework.net/doc-latest/reference/html/objects.html#objects-generic-collections-values

+0

工作正常!谢谢! – kevin628