/// <summary> /// Allows programmatic addition to the Collection /// </summary> /// <param name="element">Element to add to collection</param> public void Add(FilterParameterConfigElement element) { if (element == null) { throw new ArgumentNullException("element"); } base.BaseAdd(element, true); }
private static void CheckFilterParamTypeAndSize(FilterParameterConfigElement filterParam) { if (filterParam.SqlType == "VARCHAR(100)") { filterParam.SqlType = "varchar"; filterParam.DataSize = 100; } // Check that all relavant properties for a SqlParameter are present. // Check that name starts with a @ if (!filterParam.Name.Trim().StartsWith("@", StringComparison.Ordinal)) { throw new Exception(string.Format("FilterParameter '{0}' Name property does not start with '@'.", filterParam.Name)); } // First check that SqlType is a valid SqlDbType enum if (Enum.GetNames(typeof(SqlDbType)).Where((e) => e.Equals(filterParam.SqlType, StringComparison.OrdinalIgnoreCase)).Count() == 0) { throw new Exception(string.Format("SqlType '{0}' for filter parameter {1} is not a valid SqlDbType enum.", filterParam.SqlType, filterParam.Name)); } // Ensure that the DataSize attribute has a value set for the required types SqlDbType type = (SqlDbType)Enum.Parse(typeof(SqlDbType), filterParam.SqlType, true); switch (type) { case SqlDbType.Binary: case SqlDbType.Char: case SqlDbType.Image: case SqlDbType.NChar: case SqlDbType.NText: case SqlDbType.NVarChar: case SqlDbType.Text: case SqlDbType.VarBinary: case SqlDbType.VarChar: if (filterParam.DataSize <= 0) { throw new Exception(string.Format("Filter parameter '{0}' must specify a non zero number for the DataSize attribute.", filterParam.Name)); } break; } }