using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Villain.Databases
{
	public static class SqlCommandEx
	{
		public static void TryParse<T>(this SqlCommand sqlCommand, string parameterName, out T value) where T : struct, IComparable, IFormattable, IConvertible, IComparable<T>, IEquatable<T>
		{
			if (!sqlCommand.Parameters.Contains(parameterName) || sqlCommand.Parameters[parameterName].Value == DBNull.Value)
			{
				value = default(T);

				return;
			}

			value = (T)sqlCommand.Parameters[parameterName].Value;
		}
	}
}