如何在 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> {}
我遇到问题的地方是通过配置 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’节点”
I have this code:
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> {}
Where I have trouble is telling Spring.NET the values of each item in the StateId-indexed array via the configuration XML file.
In code, I'd write something like:
var x = new ArrayOfAnotherObjectByStateId();
x[StateId.AZ] = new AnotherObject(...);
x[StateId.CA] = new AnotherObject(...);
How do I do this in the Spring xml?
The closest I've come is:
<object id="matrix" type="ArrayOfAnotherObjectByStateId">
<property name="[AZ]" ref="AZ.Matrix">
</object>
<object id="AZ.Matrix" type="AnotherObject" />
which gives me the error
"Error creating context 'spring.root': 'AZ' node cannot be resolved for the specified context"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 Spring.NET 1.2 进行测试
Tested with Spring.NET 1.2