Yaron Avital
Yaron Avital

Reputation: 968

Spring.net how to assign an enum value to property

I've a class with the following property:

public class Animal
{    
     public AnimalTypeEnum AnimalType { get; set; }
}

and this following enum:

public enum AnimalTypeEnum 
{
      Dog = 0,
      Cat = 1,
      Bird = 2,
}

And i'd like to initiate an instance of my class via Spring.Net configuration file, in the following manner:

 <object id="MyAnimal" type="MyProg.Animal , MyProg">    
      <property name="AnimalType" expression="MyProg.AnimalTypeEnum.Dog"/>
 </object>

So far I've little success to evaluate AnimalType.Dog, I've tried numerous ways, any idea?

The error message i'm getting: Cannot initialize property or field node 'MyProg' because the specified context is null

Upvotes: 1

Views: 725

Answers (1)

Yaron Avital
Yaron Avital

Reputation: 968

Finally found the answer at the most obvious place, spring.net web site

according the documentation (and it works!)

all you have to do is simply specify the enum value like the following:

<object id="MyAnimal" type="MyProg.Animal , MyProg">    
  <property name="AnimalType" value="Dog"/>
</object>

Upvotes: 1

Related Questions