varargssqlfunction.cs

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

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

namespace NHibernate.Dialect.Function
{
	/// <summary>
	/// Support for slightly more general templating than StandardSQLFunction,
	/// with an unlimited number of arguments.
	/// </summary>
	public class VarArgsSQLFunction : ISQLFunction
	{
		private readonly string begin;
		private readonly string sep;
		private readonly string end;
		private readonly IType returnType = null;

		public VarArgsSQLFunction(string begin, string sep, string end)
		{
			this.begin = begin;
			this.sep = sep;
			this.end = end;
		}

		public VarArgsSQLFunction(IType type, string begin, string sep, string end)
			: this(begin, sep, end)
		{
			this.returnType = type;
		}

		#region ISQLFunction Members

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

		public bool HasArguments
		{
			get { return true; }
		}

		public bool HasParenthesesIfNoArguments
		{
			get { return true; }
		}

		public SqlString Render(IList args, ISessionFactoryImplementor factory)
		{
			SqlStringBuilder buf = new SqlStringBuilder().Add(begin);
			for (int i = 0; i < args.Count; i++)
			{
				buf.AddObject(args[i]);
				if (i < args.Count - 1) buf.Add(sep);
			}
			return buf.Add(end).ToSqlString();
		}

		#endregion
	}
}

⌨️ 快捷键说明

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