Tool to generate strongly typed classes for configuration sections

I wrote a simple tool to generate strongly typed classes for IIS configuration sections which can then be used with MWA to enable intellisense. This tool should be able to generate very logical intuitive type names in most cases. Generated code is similar to code samples in my earlier blog.

Usage:
genscode.exe <schemaFile> <optional section name>

This tool dumps the code on the console. Redirect to save in a file.
genscode.exe %windir%\system32\inetsrv\config\schema\IIS_Schema.xml system.webServer/httpCompression > HttpCompression.cs

Omitting section name will make it generate classes for all sections defined in schema file.
genscode.exe %windir%\system32\inetsrv\config\schema\IIS_Schema.xml > IISConfigSections.cs

Compile the generated code to build a library.
csc /t:library /r:Microsoft.Web.Administration.dll IISConfigSections.cs

Add this library to your project references or just copy-paste the generated code in your code which is using MWA and start editing IIS sections without referring to schema. Here is how adding caching profiles will look like.

using SystemwebServer;

ServerManager
sm = new ServerManager();

CachingSection cs = (CachingSection)sm.GetApplicationHostConfiguration().GetSection(
    CachingSection.SectionName,
    typeof(CachingSection));
cs.Profiles.Add(
    ".htm",
    EnumProfilesPolicy.CacheForTimePeriod,
    EnumProfilesKernelCachePolicy.CacheForTimePeriod,
    new TimeSpan(1000),
    EnumProfilesLocation.Downstream,
    "HEADER",
    "QUERYSTRING");

ProfilesCollection profiles = cs.Profiles;
ProfilesCollectionElement aspProfile = profiles.CreateElement();
aspProfile.Extension = ".asp";
aspProfile.Policy = EnumProfilesPolicy.CacheUntilChange;
profiles.Add(aspProfile);

sm.CommitChanges();

Attached: GenSCodeInstall.zip (containing installer GenSCodeInstall.exe which will install genscode.exe and configschema.dll).

View the original post

No Comments