public SqlCallProcedureInfo(MethodInfo method, ISerializationTypeInfoProvider typeInfoProvider)
 {
     if (method == null) {
         throw new ArgumentNullException("method");
     }
     if (typeInfoProvider == null) {
         throw new ArgumentNullException("typeInfoProvider");
     }
     SqlProcAttribute procedure = GetSqlProcAttribute(method);
     schemaName = procedure.SchemaName;
     name = procedure.Name;
     timeout = procedure.Timeout;
     deserializeReturnNullOnEmptyReader = procedure.DeserializeReturnNullOnEmptyReader;
     deserializeRowLimit = procedure.DeserializeRowLimit;
     deserializeCallConstructor = procedure.DeserializeCallConstructor;
     SortedDictionary<int, SqlCallParameterInfo> sortedParams = new SortedDictionary<int, SqlCallParameterInfo>();
     outArgCount = 0;
     foreach (ParameterInfo parameterInfo in method.GetParameters()) {
         if ((parameterInfo.GetCustomAttributes(typeof(SqlNameTableAttribute), true).Length > 0) || (typeof(XmlNameTable).IsAssignableFrom(parameterInfo.ParameterType))) {
             if (xmlNameTableParameter == null) {
                 xmlNameTableParameter = parameterInfo;
             }
         } else {
             SqlCallParameterInfo sqlParameterInfo = new SqlCallParameterInfo(parameterInfo, typeInfoProvider, ref outArgCount);
             sortedParams.Add(parameterInfo.Position, sqlParameterInfo);
         }
     }
     parameters = sortedParams.Select(p => p.Value).ToArray();
     returnTypeInfo = typeInfoProvider.GetSerializationTypeInfo(method.ReturnType);
     if ((procedure.UseReturnValue != SqlReturnValue.Auto) || (method.ReturnType != typeof(void))) {
         useReturnValue = (procedure.UseReturnValue == SqlReturnValue.ReturnValue) || ((procedure.UseReturnValue == SqlReturnValue.Auto) && (typeInfoProvider.TypeMappingProvider.GetMapping(method.ReturnType).DbType == SqlDbType.Int));
     }
 }
 public SqlCallParameterInfo(ISerializationTypeInfoProvider serializationTypeInfoProvider, ParameterInfo param, ProcedureName procedureName, ProcedureParameter script, ISerializationTypeMappingProvider typeMappingProvider)
     : base(procedureName, script, GetParameterDirection(param), GetParameterNullable(param), GetParameterEnumerable(param))
 {
     parameterInfo = param;
     if (SqlType == SqlDbType.Structured) {
         Type structuredType;
         if (!param.ParameterType.TryGetIEnumerableElementType(out structuredType)) {
             throw new ArgumentException("The given parameter must implement IEnumerable<> in order to be used as SQL structured parameter");
         }
         CreateTypeAsTableStatement createTableTypeScript;
         if (!AssemblyInventory.Get(param.Member.DeclaringType.Assembly).TryFind(script.ParameterTypeName.Name.Value, out createTableTypeScript)) {
             throw new ArgumentException(string.Format("The given structured parameter table type {0} cannot be found in the inventory", script.ParameterTypeName));
         }
         IDictionary<string, SqlColumnInfo> columnInfos;
         ISerializationTypeInfo info = serializationTypeInfoProvider.GetSerializationTypeInfo(structuredType);
         if (info.SimpleConverter != null) {
             string columnName = createTableTypeScript.TableDefinitions.OfType<TableColumnDefinition>().First(d => d.ColumnDefinition is TypedColumnDefinition).ColumnName.Value;
             columnInfos = new Dictionary<string, SqlColumnInfo>(1);
             columnInfos.Add(columnName, new SqlColumnInfo(typeMappingProvider.GetMapping(structuredType), columnName, info.SimpleConverter));
         } else {
             columnInfos = typeMappingProvider.GetMapping(structuredType).Columns;
             Attribute[] mappingAttributes = Attribute.GetCustomAttributes(param, typeof(SqlMappingAttribute), true);
             if ((mappingAttributes != null) && (mappingAttributes.Length > 0)) {
                 IDictionary<string, SqlColumnInfo> mappedColumnInfos = new Dictionary<string, SqlColumnInfo>(columnInfos);
                 foreach (SqlMappingAttribute mappingAttribute in mappingAttributes) {
                     mappedColumnInfos[mappingAttribute.TableTypeColumn] = columnInfos[mappingAttribute.SqlColumn];
                 }
                 columnInfos = mappedColumnInfos;
             }
         }
         structuredSchema = new StructuredParameterSchema(createTableTypeScript, columnInfos);
     }
     #warning Maybe implement more type compatibility checks for arguments here
     //			if ((sqlType == SqlDbType.Udt) && string.IsNullOrEmpty(arg.UserDefinedTypeName)) {
     //				userDefinedTypeName = SqlSerializationTypeMapping.GetClrUserDefinedTypeName(parameter.ParameterType, arg);
     //			}
 }
 public SqlCallParameterInfo(ParameterInfo parameter, ISerializationTypeInfoProvider typeInfoProvider, ref int outArgCount)
 {
     if (parameter == null) {
         throw new ArgumentNullException("parameter");
     }
     if (typeInfoProvider == null) {
         throw new ArgumentNullException("typeInfoProvider");
     }
     this.typeInfoProvider = typeInfoProvider;
     SqlArgAttribute arg = GetSqlArgAttribute(parameter);
     parameterName = arg.Name;
     parameterType = parameter.ParameterType;
     if (parameterType.IsByRef) {
         parameterType = parameterType.GetElementType();
     }
     sqlType = (arg.Type != null) ? arg.Type.Value : typeInfoProvider.TypeMappingProvider.GetMapping(parameter.ParameterType).DbType;
     size = arg.Size;
     if ((size == 0) && ((sqlType == SqlDbType.NChar) || (sqlType == SqlDbType.Char))) {
         size = 1;
     }
     nullable = arg.Nullable;
     if (parameter.ParameterType.IsNullableType()) {
         nullable = true;
     } else if (parameter.ParameterType.IsValueType) {
         nullable = false;
     }
     position = parameter.Position;
     if (parameter.ParameterType.IsByRef) {
         if (sqlType == SqlDbType.Structured) {
             throw new NotSupportedException("Table valued parameters only support readonly inputs!");
         }
         direction = parameter.IsOut ? ParameterDirection.Output : ParameterDirection.InputOutput;
     }
     if (direction != ParameterDirection.Input) {
         outArgPosition = outArgCount++;
     }
     if (sqlType == SqlDbType.Structured) {
         structuredSchema = new StructuredParameterSchema(typeInfoProvider.GetSerializationTypeInfo(parameterType.GetGenericArguments()[0]), typeInfoProvider.TypeMappingProvider);
     }
     if ((sqlType == SqlDbType.Udt) && string.IsNullOrEmpty(arg.UserDefinedTypeName)) {
         userDefinedTypeName = GetClrUserDefinedTypeName(parameter.ParameterType);
     }
 }