0

名前空間 Device.Control に列挙があります ...

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

そして、私はクラスを持っています...

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

そして、これがspring.netの構成XMLです...

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

MyStateManager オブジェクトをビルドして注入しようとすると、Spring.NET は、オブジェクトの ManagingStates プロパティを設定できないと文句を言います。このエラーが発生します...

「ファイル [Spring.xml] 行 3」で定義された「MyStateManager」という名前のオブジェクトの作成中にエラーが発生しました: プロパティ値の設定エラー: PropertyAccessExceptionsException (1 エラー); [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.IList1[[SandboxConsole.Device.Control.ApplicationEnumerations+State, SandboxConsole,プロパティ 'ManagingStates' のバージョン = 1.0.0.0、カルチャ = ニュートラル、PublicKeyToken = null]]]...

私はSpring.NETに少し慣れていないので、ArrayListをIListプロパティに挿入できないこと以外に、ここで何が問題なのかわかりません。 値が列挙型である構成でリストを作成することは可能ですか? もしそうなら、どのように?

4

1 に答える 1

2

You have to specify the element-type:

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

where Namespace is the namespace of your class and Assembly the assembly that contains your enum.

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

ApplicationEnumerations+State because you try to access an inner class.

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

于 2013-07-24T19:20:29.000 に答える