I got it to work after 4 hours. The first code is for the CarBuilderProvider.dll I created a class library called CarBuildProvider. Complied it into a dll.
using System.IO;
using System.Web.Compilation;
using System.Xml;
using System.CodeDom;
namespace CarBuildProvider
{
classCar : BuildProvider
{
publicoverridevoid GenerateCode(AssemblyBuilder myAb)
{
XmlDocument carXmlDoc = newXmlDocument();
using(Stream passedFile = OpenStream())
{
carXmlDoc.Load(passedFile);
}
XmlNode mainNode = carXmlDoc.SelectSingleNode("/car");
string selectionMainNode = mainNode.Attributes["name"].Value;
XmlNode colorNode = carXmlDoc.SelectSingleNode("/car/color");
string selectionColorNode = colorNode.InnerText;
XmlNode doorNode = carXmlDoc.SelectSingleNode("/car/door");
string selectionDoorNode = doorNode.InnerText;
XmlNode speedNode = carXmlDoc.SelectSingleNode("/car/speed");
string selectionSpeedNode = speedNode.InnerText;
CodeCompileUnit ccu = newCodeCompileUnit();
CodeNamespace cn = newCodeNamespace();
CodeMemberProperty cmp1 = newCodeMemberProperty();
CodeMemberProperty cmp2 = newCodeMemberProperty();
CodeMemberMethod cmm1 = newCodeMemberMethod();
cn.Imports.Add(newCodeNamespaceImport("System"));
cmp1.Name = "Color";
cmp1.Type = newCodeTypeReference(typeof(string));
cmp1.Attributes = MemberAttributes.Public;
cmp1.GetStatements.Add(newCodeSnippetExpression("return \"" + selectionColorNode + "\""));
cmp2.Name = "Doors";
cmp2.Type = newCodeTypeReference(typeof(int));
cmp2.Attributes = MemberAttributes.Public;
cmp2.GetStatements.Add(newCodeSnippetExpression("return " + selectionDoorNode));
cmm1.Name = "Go";
cmm1.ReturnType = newCodeTypeReference(typeof(int));
cmm1.Attributes = MemberAttributes.Public;
cmm1.Statements.Add(newCodeSnippetExpression("return " + selectionSpeedNode));
CodeTypeDeclaration ctd = newCodeTypeDeclaration(selectionMainNode);
ctd.Members.Add(cmp1);
ctd.Members.Add(cmp2);
ctd.Members.Add(cmm1);
cn.Types.Add(ctd);
ccu.Namespaces.Add(cn);
myAb.AddCodeCompileUnit(this, ccu);
}
}
}
Next I created the ExampleBP website. I modified the web.config file and added the following under the <Compilation>:
<buildProviders>
<addextension=".car"type="CarBuildProvider.Car" />
</buildProviders>
I created the Car.car xml file and placed it in the App_Code filder:
<?xmlversion="1.0"encoding="utf-8" ?>
<carname="EvjenCar">
<color>Blue</color>
<door>4</door>
<speed>150</speed>
</car>
Next I copied the CarBuilderProvider.dll and CarBuildProvider.pdb into the bin folder.
In the default.aspx file I added the following code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
publicpartialclass_Default : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
EvjenCar newCar = newEvjenCar();
Response.Write(newCar.Color + "<br/>");
Response.Write(newCar.Doors.ToString() + "<br/>");
Response.Write(newCar.Go().ToString() + "<br/>");
}
}
I built the website and ran it and it worked. My mistake the web.config file was wrong. I only added type="CarBuildProvider". I included only the namespace and forgot to add the .Car class name. 4 hours of frustraton.
here is a link to a database version by Fritz Onion that helped my solve my problem:
http://www.pluralsight.com/community...9/06/2188.aspx
At the bottom of the article you can download the code.
I hope this works.