NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

ConfigManager.Get

System runtimes, modules that extend the system runtimes, applications, as well as administrative tools, can retrieve configuration information through the GetItem and GetProperty methods.

The Get methods return configuration information as collections of configuration items (IConfigCollection). They can be used to retrieve any configuration information, including singleton ConfigTypes, as long as configuration schema has been defined.

Other methods exist to retrieve singleton configuration items (GetItem) or individual configuration properties (GetProperty).

Example 1: Singleton property- AppDomain ShadowCopy

In this example, the configuration information consists of a single named value, which occurs exactly once in a configuration scope (file).

The NGWS runtime system setting for application domains (as used by the EXE host) consists of such singleton properties: there can be only one "ShadowCopy" flag for each application.

[C#]

using System.Configuration;
 
 // Reading a single value: Boolean ShadowCopy = (Boolean) 
 Boolean ShadowCopy = (Boolean) ConfigManager.GetProperty("AppDomain", "c:\myapp\foo.cfg", "ShadowCopy");

Example 2: Singleton Item- AppDomain

The AppDomain configuration consists of more than one property, but still each of the properties can appear at most once in a configuration scope (file).

The configuration system makes it easy to retrieve all properties in a ConfigType at once:

[C#]

using System.Configuration;
 using System.Configuration.Core;
 
 AppDomain appdomain = ConfigManager.GetItem("AppDomain", "c:\myapp\foo.cfg");
 
 if (appdomain.ShadowCopy) { ... } 
 String path = appdomain.SharedPath;

Example 3: Collection of items- Binding Policy

In this example, the configuration information is slightly more complex: every property in a ConfigType can actually occur more than once within a given configuration scope (file).

The NGWS runtime 2.0 system setting for binding policy ("<BindingPolicy>"), is a good example of such a configuration setting: every assembly that could potentially be loaded into an application can have it's own binding redirection entry.

[C#]

using System.Configuration;
 using System.Configuration.Core;
 
 IConfigCollection bindings = ConfigManager.Get("BindingPolicy", "c:\myapp\foo.cfg");
 foreach (BindingPolicy bindingredir in bindings) {
   Console.WriteLine(bindingredir.Name+": "+bindingredir.Version);
 }

Example 4: Generic configuration reader

In some cases (administrative tools, generic applications), it is necessary to process arbitrary configuration information without prior knowledge. The configuration system provides schema (property names, types etc.) discovery mechanisms for sophisticated tools, but also lets simple tools read configuration information in a generic way, by letting a caller enumerate the available properties in a configuration item.

The example code below outputs an arbitrary set of configuration information, by only modifying the ConfigType and Selector passed to the ConfigManager.Get method:

[C#]

// Late bound, generic
 IConfigCollection collection = ConfigManager.Get( "BindingPolicy", "c:\myapp\foo.cfg");
 foreach (IConfigItem item in collection) {
   Console.WriteLine("");
   foreach (Object property in item) {
     Console.WriteLine( property ); 
   }
 }

Overload List

This overload of the Get method accepts a selector in string form. It attempts to create a Selector from this string. It also accepts a set of flags indicating the desired level of service.

[Visual Basic] Overloads Public Shared Function Get(String, String, Integer) As IConfigCollection
[C#] public static IConfigCollection Get(String, String, int);
[C++] public: static IConfigCollection* Get(String*, String*, int);
[JScript] public static function Get(String, String, int) : IConfigCollection;

This overload of the Get method accepts a selector in string form. It attempts to create a Selector from this string.

[Visual Basic] Overloads Public Shared Function Get(String, String) As IConfigCollection
[C#] public static IConfigCollection Get(String, String);
[C++] public: static IConfigCollection* Get(String*, String*);
[JScript] public static function Get(String, String) : IConfigCollection;

This overload of the Get method accepts a selector in the form of an object and also accepts a set of flags indicating the desired level of service.

[Visual Basic] Overloads Public Shared Function Get(String, Selector, Integer) As IConfigCollection
[C#] public static IConfigCollection Get(String, Selector, int);
[C++] public: static IConfigCollection* Get(String*, Selector, int);
[JScript] public static function Get(String, Selector, int) : IConfigCollection;

This overload of the Get method accepts a selector in the form of an object.

[Visual Basic] Overloads Public Shared Function Get(String, Selector) As IConfigCollection
[C#] public static IConfigCollection Get(String, Selector);
[C++] public: static IConfigCollection* Get(String*, Selector);
[JScript] public static function Get(String, Selector) : IConfigCollection;

See Also

ConfigManager Class | ConfigManager Members | System.Configuration Namespace