0

我有这个代码:

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'节点无法为指定的上下文解析”

4

1 回答 1

1
<object id="matrix" type="ArrayOfAnotherObjectByStateId">
   <property name="[T(NamespaceYouUse.StateId).AZ]" ref="AZ.Matrix">
</object>

使用 Spring.NET 1.2 测试

于 2009-11-06T11:27:02.543 回答