简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM