Click here to Skip to main content
15,891,253 members
Articles / Programming Languages / C#

TypeBuilderLib, a Library to Build Dynamic Types Easily

Rate me:
Please Sign up or sign in to vote.
4.94/5 (13 votes)
23 Feb 2007CPOL11 min read 44K   243   41  
TypeBuilderLib allows you to create dynamic types on the fly, which can increase the productivity of developers and the performance of applications.
using System;
using System.Reflection;

namespace TypeBuilderLib.Indexer
{
	/// <summary>
	/// Attribute indicating to the emitter to use the base class implementation for implementing a property or
	/// a method of an interface.
	/// </summary>
	[AttributeUsage(AttributeTargets.Property | AttributeTargets.Method, Inherited = true, AllowMultiple = true)]
	public class UseBaseAttribute : ContextAttributeBase
	{
		private bool throwsIfNotPresent = true;
		private string memberName = null;

		/// <summary>
		/// If set to <c>true</c>, a type emitter will throw an exception if the member isn't present.
		/// Otherwise, the emitter emit a member that throws an exception on use.
		/// </summary>
		/// <remarks><c>true</c> by default.</remarks>
		public bool ThrowsIfNotPresent
		{
			get { return throwsIfNotPresent; }
			set { throwsIfNotPresent = value; }
		}

		/// <summary>Name of the member (either method or property) to use.</summary>
		public string MemberName
		{
			get { return memberName; }
			set { memberName = value; }
		}

		/// <summary>Returns the custom attributes associated with a member in a given context.</summary>
		/// <param name="member"></param>
		/// <returns></returns>
		public static UseBaseAttribute GetAttributeInContext(MemberInfo member, object context)
		{
			return GetAttributeInContext<UseBaseAttribute>(member, context, true);
		}
	}
}

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
Architect CGI
Canada Canada
Vincent-Philippe is a Senior Solution Architect working in Montreal (Quebec, Canada).

His main interests are Windows Azure, .NET Enterprise suite (e.g. SharePoint 2013, Biztalk Server 2010) & the new .NET 4.5 platforms.

Comments and Discussions