Click here to Skip to main content
15,894,410 members
Articles / Hosted Services / Azure

Kerosene ORM: a dynamic, configuration-less and self-adaptive ORM for POCO objects supporting a SQL-like syntax from C#

Rate me:
Please Sign up or sign in to vote.
4.96/5 (71 votes)
1 Mar 2015CPOL35 min read 547.6K   4.6K   212  
The seventh version of the dynamic, configuration-less and self-adaptive Kerosene ORM library, that provides full real support for POCO objects, natural SQL-like syntax from C#, and advanced capabilities while being extremely easy to use.
// ======================================================== MethodEx.cs
namespace Kerosene.Tools
{
	using System;
	using System.Diagnostics;
	using System.Reflection;

	// ==================================================== 
	/// <summary>
	/// Helpers and extensions for working with <see cref="System.Reflection.MethodBase"/>
	/// instances.
	/// </summary>
	public static class MethodEx
	{
		/// <summary>
		/// Gets the method at the given position in the calling stack, or null if this
		/// information is not available.
		/// </summary>
		/// <param name="depth">The depth into the calling stack:
		/// <para>- 0: the current <see cref="MethodonStack"/> method.</para>
		/// <para>- 1: the method that has called this one.</para>
		/// <para>- 2: the method from which the caller of this one was invoked.</para>
		/// <para>Etc...</para>
		/// </param>
		/// <returns>The method reference, or null.</returns>
		public static MethodBase MethodOnStack(uint depth = 1)
		{
			var stack = new StackTrace();
			var frame = stack.GetFrame((int)depth);

			return frame == null ? null : frame.GetMethod();
		}

		/// <summary>
		/// Returns the name of this method, including the C#-alike name of the type that declares
		/// it.
		/// </summary>
		/// <param name="method"></param>
		/// <param name="depth">The depth of the declaring chain to be included in the name of
		/// type:
		/// <para>- 0: only to include the name of the type.</para>
		/// <para>- 1: to also include the name of the namespace or type where it is declared.</para>
		/// <para>- n: include to the nth-level the names in the declaring chain.</para>
		/// </param>
		/// <param name="genericNames">True to include the names of the generic type arguments, if
		/// any, or false to leave them blank.</param>
		/// <returns>The extended name of the method.</returns>
		public static string ExtendedName(this MethodBase method, int depth = 0, bool genericNames = false)
		{
			if (method == null) throw new NullReferenceException("Method cannot be null.");

			var name = method.Name;
			var type = method.DeclaringType;

			if (type != null) name = string.Format("{0}.{1}",
				type.EasyName(depth, genericNames),
				name);

			return name;
		}
	}
}
// ======================================================== 

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
Spain Spain
mbarbac has worked in start-ups, multinational tech companies, and consulting ones, serving as CIO, CTO, SW Development Director, and Consulting Director, among many other roles.

Solving complex puzzles and getting out of them business value has ever been among his main interests - and that's why he has spent his latest 25 years trying to combine his degree in Theoretical Physics with his MBA... and he is still trying to figure out how all these things can fit together.

Even if flying a lot across many countries, along with the long working days that are customary in IT management and Consultancy, he can say that, after all, he lives in Spain (at least the weekends).

Comments and Discussions