standardsqlfunction.cs

来自「NHibernate NET开发者所需的」· CS 代码 · 共 88 行

CS
88
字号
using System.Collections;
using System.Text;
using NHibernate.Engine;
using NHibernate.SqlCommand;
using NHibernate.Type;

namespace NHibernate.Dialect.Function
{
	/// <summary>
	/// Provides a standard implementation that supports the majority of the HQL
	/// functions that are translated to SQL.
	/// </summary>
	/// <remarks>
	/// The Dialect and its sub-classes use this class to provide details required
	/// for processing of the associated function.
	/// </remarks>
	public class StandardSQLFunction : ISQLFunction
	{
		private IType returnType = null;
		protected readonly string name;

		/// <summary>
		/// Initializes a new instance of the StandardSQLFunction class.
		/// </summary>
		/// <param name="name">SQL function name.</param>
		public StandardSQLFunction(string name)
		{
			this.name = name;
		}

		/// <summary>
		/// Initializes a new instance of the StandardSQLFunction class.
		/// </summary>
		/// <param name="name">SQL function name.</param>
		/// <param name="typeValue">Return type for the fuction.</param>
		public StandardSQLFunction(string name, IType typeValue)
			: this(name)
		{
			returnType = typeValue;
		}

		#region ISQLFunction Members

		public virtual IType ReturnType(IType columnType, IMapping mapping)
		{
			return returnType ?? columnType;
		}

		public bool HasArguments
		{
			get { return true; }
		}

		public bool HasParenthesesIfNoArguments
		{
			get { return true; }
		}

		public virtual SqlString Render(IList args, ISessionFactoryImplementor factory)
		{
			SqlStringBuilder buf = new SqlStringBuilder();
			buf.Add(name)
				.Add("(");
			for (int i = 0; i < args.Count; i++)
			{
				object arg = args[i];
				if (arg is Parameter || arg is SqlString)
				{
					buf.AddObject(arg);
				}
				else
				{
					buf.Add(arg.ToString());
				}
				if (i < (args.Count - 1)) buf.Add(", ");
			}
			return buf.Add(")").ToSqlString();
		}

		#endregion

		public override string ToString()
		{
			return name;
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?