我有这段代码:
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> {}
我遇到麻烦的是通过配置XML文件告诉Spring.NET StateId-indexed数组中每个项的值。
在代码中,我会写一些类似的东西:
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" />
给了我错误 “创建上下文'spring.root'时出错:无法为指定的上下文解析'AZ'节点”
答案 0 :(得分:1)
<object id="matrix" type="ArrayOfAnotherObjectByStateId">
<property name="[T(NamespaceYouUse.StateId).AZ]" ref="AZ.Matrix">
</object>
使用Spring.NET 1.2进行测试