Rana
Rana

Reputation: 1

how can i pass enum as a property to app.config file in c# with spring.net

i have the following enum:

enum ELogLevel
{
    INFO = 1,
    DEBUG = 2,
    WARNING = 3,
    ERROR = 4,
    FATAL = 5
}

and i have the following class:

class Test
{
    private ELogLevel logLevel;}

i've tried doing this:

<object name="test" type="program.Test ,program" singleton="false">
    <property name="logLevel">
      <add key="1" value="INFO"/>
      <add key="2" value="DEBUG"/>
      <add key="3" value="WARNING"/>
      <add key="4" value="ERROR"/>
      <add key="5" value="FATAL"/>

    </property>
  </object>

but i couldn't deal with it and i want to pass "logLevel" property using dependency injection using spring.net... how can i do that and how can i read that property.

Upvotes: 0

Views: 941

Answers (1)

Mohan
Mohan

Reputation: 43

The default type converter for enumerations is the System.ComponentModel.EnumConverter class. To specify the value for an enumerated property, simply use the name of the property. For example the TestObject class has a property of the enumerated type FileMode. One of the values for this enumeration is named Create. The following XML fragment shows how to configure this property

<object id="rod" type="Spring.Objects.TestObject, Spring.Core.Tests">
  <property name="name" value="Rod"/>
  <property name="FileMode" value="Create"/>
</object>

I believe you have to pass Info enum number to the ELogLevel. So you have to write following code in web.config.

<object id="testobj" type="NameSpace.Test, Assembly">
  <property name="ELogLevel" value="INFO"/>
</object>

For More information please refer to this url

https://documentation.help/Spring.NET-Framework/objects.html

Upvotes: 1

Related Questions