/// <summary> /// Converts to a <see cref="SqlParameter"/>. /// </summary> /// <param name="stringInputParameter">The string input parameter.</param> /// <returns>SqlParameter.</returns> public static SqlParameter ToSqlParameter( this InputParameterDefinition <string> stringInputParameter) { stringInputParameter.MustForArg(nameof(stringInputParameter)).NotBeNull(); if (stringInputParameter.SqlDataType.GetType() == typeof(StringSqlDataTypeRepresentation)) { var stringDataType = (StringSqlDataTypeRepresentation)stringInputParameter.SqlDataType; var name = stringInputParameter.Name; name = name.StartsWith("@", StringComparison.Ordinal) ? name : "@" + name; var result = stringInputParameter.Value.CreateInputSqlParameter(name, stringDataType.SupportUnicode ? SqlDbType.NVarChar : SqlDbType.VarChar, stringDataType.SupportedLength); return(result); } else if (stringInputParameter.SqlDataType.GetType() == typeof(XmlSqlDataTypeRepresentation)) { var name = stringInputParameter.Name; name = name.StartsWith("@", StringComparison.Ordinal) ? name : "@" + name; var result = stringInputParameter.Value.CreateInputSqlParameter(name, SqlDbType.Xml); return(result); } else { throw new NotSupportedException(FormattableString.Invariant($"Cannot create a {nameof(SqlParameter)} from {nameof(InputParameterDefinition<string>)} with a datatype of {stringInputParameter.SqlDataType}.")); } }
/// <summary> /// Converts to a <see cref="SqlParameter"/>. /// </summary> /// <param name="dateTimeInputParameter">The nullable <see cref="DateTime"/> input parameter.</param> /// <returns>SqlParameter.</returns> public static SqlParameter ToSqlParameter( this InputParameterDefinition <DateTime?> dateTimeInputParameter) { dateTimeInputParameter.MustForArg(nameof(dateTimeInputParameter)).NotBeNull(); var name = dateTimeInputParameter.Name; name = name.StartsWith("@", StringComparison.Ordinal) ? name : "@" + name; var result = dateTimeInputParameter.Value.CreateInputSqlParameter(name); return(result); }