noargsqlfunction.cs

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

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

namespace NHibernate.Dialect.Function
{
	/// <summary>
	/// Summary description for NoArgSQLFunction.
	/// </summary>
	public class NoArgSQLFunction : ISQLFunction
	{
		protected readonly IType returnType = null;
		protected readonly string name;
		private readonly bool hasParenthesesIfNoArguments;

		public NoArgSQLFunction(string name, IType returnType) : this(name, returnType, true)
		{
		}

		public NoArgSQLFunction(string name, IType returnType, bool hasParenthesesIfNoArguments)
		{
			this.name = name;
			this.returnType = returnType;
			this.hasParenthesesIfNoArguments = hasParenthesesIfNoArguments;
		}

		protected IType FunctionReturnType
		{
			get { return returnType; }
		}

		protected string Name
		{
			get { return name; }
		}

		#region ISQLFunction Members

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

		public bool HasArguments
		{
			get { return false; }
		}

		public bool HasParenthesesIfNoArguments
		{
			get { return hasParenthesesIfNoArguments; }
		}

		public virtual SqlString Render(IList args, ISessionFactoryImplementor factory)
		{
			if (args.Count > 0)
			{
				throw new QueryException("function takes no arguments: " + name);
			}
			SqlStringBuilder buf = new SqlStringBuilder(2);
			buf.Add(name);
			if (hasParenthesesIfNoArguments)
			{
				buf.Add("()");
			}
			return buf.ToSqlString();
		}

		#endregion
	}
}

⌨️ 快捷键说明

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