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

Implementing Model-View-Presenter in ASP.NET

Rate me:
Please Sign up or sign in to vote.
4.80/5 (27 votes)
17 Nov 2007CPOL12 min read 129.7K   2.7K   120  
Three implementations of Model-View-Presenter in ASP.NET 2.0.
using System;
using System.CodeDom.Compiler;
using System.Data;
using Microsoft.VisualBasic;
using SubSonic.Utilities;

namespace SubSonic
{
	public class VBCodeLanguage : ICodeLanguage
	{
		#region Constants & enumerations

		private readonly string[] keywords = {
			// keywords
			"alias", "addHandler", "ansi", "as", "assembly", "auto", "binary", "byref", "byval", "case", "catch", "class",
			"custom", "date", "datetime", "default", "directcast", "each", "else", "elseif", "end", "error", "false",
			"finally", "for", "friend", "global", "handles", "implements", "in", "is", "lib", "loop", "me", "module",
			"mustinherit", "mustoverride", "mybase", "myclass", "narrowing", "new", "next", "nothing", "notinheritable",
			"notoverridable", "of", "off", "on", "option", "optional", "overloads", "overridable", "overrides", "paramarray",
			"partial", "preserve", "private", "property", "protected", "public", "raiseevent", "readonly", "resume", "shadows",
			"shared", "static", "step", "structure", "text", "then", "to", "true", "trycast", "unicode", "until", "when",
			"while", "widening", "withevents", "writeonly",
			// unreserved keywords
			"compare", "explicit", "isfalse", "istrue", "mid", "strict"
		};

		#endregion

		#region Properties

		public string CodeProvider
		{
			get { return "VBCodeProvider"; }
		}

		public string FileExtension
		{
			get { return SubSonic.FileExtension.DOT_VB; }
		}

		public string Identifier
		{
			get { return "VB"; }
		}

		public string ShortName
		{
			get { return "vb"; }
		}

		public string TemplatePrefix
		{
			get { return "VB_"; }
		}

		#endregion

		#region Methods

		public CodeDomProvider CreateCodeProvider()
		{
			return new VBCodeProvider();
		}

		public string GetDefaultValue(string colName, DbType dbType, bool isNullableColumn)
		{
			string variableType = GetDefaultValue(colName, dbType);
			if (isNullableColumn && Utility.IsNullableDbType(dbType))
				variableType = String.Format(CodeFragment.NULLABLE_VARIABLE_VB, variableType);
			return variableType;
		}

		public string GetUsingStatements(string[] namespaces)
		{
			string usingStatements = "";
			foreach (string space in namespaces)
				usingStatements += "Imports " + space + Environment.NewLine;
			return usingStatements;
		}

		public string GetVariableType(DbType dbType, bool isNullableColumn)
		{
			string variableType = GetVariableType(dbType);
			if (isNullableColumn && Utility.IsNullableDbType(dbType))
				variableType = String.Format(CodeFragment.NULLABLE_VARIABLE_VB, variableType);
			return variableType;
		}

		public bool IsKeyword(string word)
		{
			return Array.IndexOf(keywords, word.ToLower()) != -1;
		}

		#endregion

		#region Private methods

		private static string GetDefaultValue(string colName, DbType dbType)
		{
			if (Utility.IsLogicalDeleteColumn(colName))
				return "False";

			switch (dbType) {
				case DbType.Guid:
					return "Guid.Empty";
				case DbType.AnsiString:
				case DbType.AnsiStringFixedLength:
				case DbType.String:
				case DbType.StringFixedLength:
					return "Nothing";
				case DbType.Boolean:
					return "False";
				case DbType.Binary:
					return "Nothing";
				case DbType.Xml:
					return "";
				case DbType.Date:
				case DbType.DateTime:
					return "New Date(1900,01,01)";
				default:
					return "0";
			}
		}

		private static string GetVariableType(DbType dbType)
		{
			switch (dbType) {
				case DbType.AnsiString:
				case DbType.AnsiStringFixedLength:
				case DbType.String:
				case DbType.StringFixedLength: return "String";

				case DbType.Binary:		return "Byte()";
				case DbType.Boolean:	return "Boolean";
				case DbType.Byte:		return "Byte";

				case DbType.Currency:
				case DbType.Decimal:
				case DbType.VarNumeric:	return "Decimal";

				case DbType.Date:
				case DbType.DateTime:	return "DateTime";

				
				case DbType.Double:		return "Double";
				case DbType.Guid:		return "Guid";
				case DbType.Int16:		return "Short";
				case DbType.Int32:		return "Integer";
				case DbType.Int64:		return "Long";
				case DbType.Object:		return "Object";
				case DbType.SByte:		return "SByte";
				case DbType.Single:		return "Single";

				case DbType.Time:		return "TimeSpan";
				case DbType.UInt16:		return "UShort";
				case DbType.UInt32:		return "UInteger";
				case DbType.UInt64:		return "ULong";
				
				default:				return "String";
			}
		}

		#endregion
	}
}

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
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions