Last week we were trying to generate some source code in the
form of a C# class out of an XML file that contains some settings configuration
at run time and yet, be able to have an intellisense at design time. This is
all said and the .NET environment is .NET 1.1. After so much research in this
field, we understood that what we are trying to do is a bit hard, but is still doable
in .NET 1.1. The work around was to have some sort of an Interface that the
generated class implements and, hence, a full access to all the configurations
in the XML file through the dynamically generated class in C#. As a drawback
you can easily see that, with the use of the Interface, every time we change
the XML file we have to change the Interface and have a new build. Not feasible,
but it does the job!
Until recently, we have posted on the ASP.NET forums about
this issue and Scott Allen was there to refer to a post on Scott Guthrie’s blog
that talks about BuildProviders in ASP.NET 2.0, which does exactly what we have
been trying to do in the .NET 1.1 Framework.
In this article we will explain what a build provider is,
how it is used by the ASP.NET 2.0 Web Application, refer you to some good links
online about this topic, and, off course, show you how to create a custom
BuildProvider to load an XML file into a C# class and access all the properties
of that class at design time!