2009-11-04 64 views
0

我有這樣的代碼:如何在Spring.NET配置xml中設置枚舉類型索引器?

public enum StateId { NotSet = 0, AL, ..., WY } 

public class EnumBasedArray<I,V>:IEnumerable<V> 
{ 
    public V this[I index] 
    { 
    get { return _data[index]; } 
    set { _data[index] = value; } 
    } 
    // other code to manage values internally 
} 

public class AnotherObject { ... } 

public class ArrayOfAnotherObjectByStateId:EnumBasedArray<StateId, AnotherObject> {} 

哪裏有麻煩是告訴Spring.NET通過配置XML文件STATEID索引數組中的每個項目的值。

在代碼中,我會寫這樣的:

var x = new ArrayOfAnotherObjectByStateId(); 
x[StateId.AZ] = new AnotherObject(...); 
x[StateId.CA] = new AnotherObject(...); 

如何在Spring XML做到這一點? 我來最接近的是:

<object id="matrix" type="ArrayOfAnotherObjectByStateId"> 
    <property name="[AZ]" ref="AZ.Matrix"> 
</object> 

<object id="AZ.Matrix" type="AnotherObject" /> 

它給我的錯誤 :

回答

1
<object id="matrix" type="ArrayOfAnotherObjectByStateId"> 
    <property name="[T(NamespaceYouUse.StateId).AZ]" ref="AZ.Matrix"> 
</object> 
「錯誤創設情境‘spring.root’‘AZ’節點不能被指定的範圍內解決。」

使用Spring.NET 1.2測試過

+0

謝謝你的工作就像一個魅力!許多(很多)比工廠解決方案更乾淨,只有一些物品是爲了讓Spring開心而創建的。謝謝! – JohnKeller 2009-11-09 13:23:36

+0

不客氣,我喜歡和Spring一起工作;) – BennyM 2009-11-09 13:32:50