【发布时间】:2009-11-04 22:34:06
【问题描述】:
我有这个代码:
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 索引数组中每个项目的值。
在代码中,我会这样写:
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'节点"
【问题讨论】:
标签: arrays enums spring.net indexer