views:

169

answers:

1

How could I add a config element in config file in Net 2.0 that would be placed under existing structure that is defined in different assembly?

In my case I have some core library that creates root section (and already some other settings) in config file (using company name for name of the root element, section). In other assembly I wanna create elements that would put any new settings under existing structure which is specified in our core library.

So far I can only see the way I repeat everywhere the required structure in each assembly.

Thanks for any suggestion. X.

An example of implementation of the config element defined in single class.

public class SpecificServiceElement : ConfigurationElement { private static ConfigurationProperty _requestTimeout; private static ConfigurationProperty _serviceAddress;

  private static ConfigurationPropertyCollection _properties;

  public int RequestTimeout{
     get { return (int) base[_requestTimeout]; }
  }
  public string ServiceAddress{
     get { return (string) base[_serviceAddress]; }
  }

  protected override ConfigurationPropertyCollection Properties{
     get { return _properties; }
  }

  static SpecificServiceElement(){
     _requestTimeout = new ConfigurationProperty("requestTimeout", typeof (int), 10000,
                                                 ConfigurationPropertyOptions.IsRequired);
     _serviceAddress = new ConfigurationProperty("serviceAddress", typeof (string), null,
                                                 ConfigurationPropertyOptions.IsRequired);
     _properties = new ConfigurationPropertyCollection();
     _properties.Add(_requestTimeout);
     _properties.Add(_serviceAddress);
  }

}

+1  A: 

You could put the required structure in its own library assembly and link to it when you need it. That way it is defined once and used many times.

Brody