ASP.NET page gets compiled dynamically into a .NET class in the background by a BuildProvider.
Whenever you create a file that has the extension .simple, the SimpleBuilderProvider builds a new class with the same name as the file in the background.
File: App_Code\SimpleBuildProvider.cs
using System;
using System.Web.Compilation;
using System.CodeDom;
using System.IO;
namespace MyNamespace
{
public class SimpleBuildProvider : BuildProvider
{
public override void GenerateCode(AssemblyBuilder ab)
{
string fileName = Path.GetFileNameWithoutExtension(this.VirtualPath);
string snippet = "public class " + fileName + @"{
public static void DoSomething(){}
}";
ab.AddCodeCompileUnit(this, new CodeSnippetCompileUnit(snippet));
}
}
}
|