views:

256

answers:

1

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"

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

Tested with Spring.NET 1.2

BennyM
Thank you-worked like a charm! Much (much) cleaner than the factory workaround with a slew of objects created solely to make Spring happy. Thank you!
JohnKeller
You're welcome, I like working with Spring ;)
BennyM