Click here to Skip to main content
15,896,063 members
Articles / Web Development / ASP.NET

Creating DAL Components Using Custom ASP.NET Build Providers And Compiler Techniques

Rate me:
Please Sign up or sign in to vote.
4.86/5 (28 votes)
24 Oct 2006CPOL9 min read 107.3K   886   114  
This article describes how to create Data Access Layer Components (DALC) using ASP.NET build providers and a self-defined description language in C#, including an easy scanner, parser, and CodeDOM generator.
//
// Parago Media GmbH & Co. KG, J�rgen B�urle (jbaurle@parago.de)
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
//

using System;
using System.IO;
using System.Web.Compilation;
using Parago.DALComp.Compiler;

namespace Parago.DALComp {

	/// <summary>
	/// Build provider to generate DAL code from source file with extension '.dal'. 
	/// The file gets compiled only within the application folder 'App_Code'.
	/// </summary>
	[BuildProviderAppliesTo(BuildProviderAppliesTo.Code)]
	public class DALCompBuildProvider : BuildProvider {

		public override void GenerateCode(AssemblyBuilder builder) {

			// Read the source code file to compile (*.dal)
			string source=String.Empty;
			using(TextReader reader=OpenReader()) {
				source=reader.ReadToEnd();
				reader.Close();
			}
			
			// Tokenize, parse and generate DAL code and turn generated 
			// compile unit over to ASP.NET build process
			Tokenizer tokenizer=new Tokenizer(source);
			Parser parser=new Parser(tokenizer);
			CodeGen codeGen=new CodeGen(parser);
			builder.AddCodeCompileUnit(this, codeGen.Generate());

		}

	}

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Germany Germany
I’m a software developer based in Germany.

Homepage

Comments and Discussions