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

Slink Framework - Strongly Typed URLs for ASP.NET

Rate me:
Please Sign up or sign in to vote.
5.00/5 (13 votes)
4 Sep 20078 min read 54.4K   36  
Slink is a code generating Framework that generates type safe URLs for ASP.NET. With Slink URLs, you increase code quality, increase maintainability, and get compile time checking of your URLs in all your ASPX pages (code-behind and non-codebehind).
using System;
using System.ComponentModel;
using System.Reflection;

namespace TaHoGen
{
	/// <summary>
	/// An extension of the PropertyTable class that assumes the properties of any
	/// type that it is given.
	/// </summary>
	/// 
	[Serializable]
	public class PropertyMimic : PropertyTable
	{
		private System.Type _subject = null;
		public PropertyMimic() : base()
		{
			
		}
		public PropertyMimic(System.Type subject) : this()
		{
			_subject = subject;
			
			Mimic(Subject);
		}
		public System.Type Subject
		{
			get { return _subject; }
		}
		
		public void Mimic(System.Type subject)
		{
			Mimic(subject, null);
		}
		public void Mimic(System.Type subject, PropertyInfoPredicate predicate)
		{
			
			// Read the properties of the subject
			PropertyInfo[] pi = subject.GetProperties();

			// If there aren't any properties, do nothing
			if (pi == null)
				return;
			
			Mimic(pi, predicate);
			
		}
		public void Mimic(PropertyInfo[] pi)
		{
			Mimic(pi, null);
		}
		public void Mimic(PropertyInfo[] pi, PropertyInfoPredicate predicate)
		{
			if (pi == null)
				return;

			// Clear the current list of properties (if any)
			if (Properties.Count > 0)
			{
				Properties.Clear();
				Clear();
			}

			foreach(PropertyInfo property in pi)
			{
				// Skip the property if it fails the predicate condition
				if (predicate != null && predicate(property) == false)
					continue;

				// Create a property that looks like the type's property
				PropertySpec spec = CreatePropertySpec(property);

				// Add it to the list of properties
				if (spec != null)
					Properties.Add(spec);
			}
		}
		public override string GetClassName()
		{
			if (_subject == null)
				return base.GetClassName ();

			return _subject.FullName;
		}

		private PropertySpec CreatePropertySpec(PropertyInfo pi)
		{
			string name = pi.Name;
			Type propertyType = pi.PropertyType;
			
			// Get the name, category, description, type,
			// and default value of the property
			PropertyHelper helper = new PropertyHelper(pi);

			PropertySpec result = new PropertySpec(pi.Name, pi.PropertyType);
			
			if (helper.Category.Length > 0)
				result.Category = helper.Category;

			if (helper.DefaultValue != null)
				result.DefaultValue = helper.DefaultValue;

			if (helper.Description != null)
				result.Description = helper.Description;

	
			return result;
		}

		
	}
}

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
I'm a .NET developer with a crazy drive to create neat computer stuff.

You can find me coding the night away in my small garage working on various fun projects for my small startup, Bit Armory, with the hopes of making it big someday, just like the YouTube and MySpace guys did. Smile | :)

You can read my blog here http://bchavez.bitarmory.com

Comments and Discussions