/// <summary> /// 将XmlCommand参数转换成OracleParameter[] /// </summary> /// <param name="item">XmlCommand的命令参数</param> /// <param name="ht">参数键值Hashtable</param> /// <returns>OracleParameter[]</returns> public static OracleParameter[] ToArrayOracleParameter(this XmlCommandItem item, Hashtable ht) { if (item.Parameters == null || item.Parameters.Count == 0 || ht == null || ht.Count == 0) { return(null); } int length = item.Parameters.Count; OracleParameter[] arrParameter = new OracleParameter[item.Parameters.Count]; XmlCmdParameter cmdParameter = null; for (int i = 0; i < length; i++) { cmdParameter = item.Parameters[i]; object value = ht[cmdParameter.Name.Replace(":", "")]; if (value == null || value == DBNull.Value) { arrParameter[i] = new OracleParameter(cmdParameter.Name, DBNull.Value); } else { if (!value.IsBooleanType()) { arrParameter[i] = new OracleParameter(cmdParameter.Name, cmdParameter.Type, value, cmdParameter.Direction); } else { arrParameter[i] = new OracleParameter(cmdParameter.Name, cmdParameter.Type, Convert.ToInt32(value), cmdParameter.Direction); } } } return(arrParameter); }
/// <summary> /// 将XmlCommand参数转换成OracleParameter[] /// </summary> /// <param name="item">XmlCommand的命令参数</param> /// <param name="ht">new{A="123"}形式参数</param> /// <returns>OracleParameter[]</returns> public static OracleParameter[] ToArrayOracleParameter(this XmlCommandItem item, object argsObject) { if (item.Parameters == null || item.Parameters.Count == 0 || argsObject == null) { return(null); } int length = item.Parameters.Count; OracleParameter[] arrParameter = new OracleParameter[item.Parameters.Count]; XmlCmdParameter cmdParameter = null; PropertyInfo[] properties = argsObject.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public); PropertyInfo pInfo = null; for (int i = 0; i < length; i++) { cmdParameter = item.Parameters[i]; pInfo = Array.Find <PropertyInfo>(properties, (e) => { return((":" + e.Name).Equals(cmdParameter.Name, StringComparison.OrdinalIgnoreCase)); }); if (pInfo == null) { arrParameter[i] = new OracleParameter(cmdParameter.Name, DBNull.Value); continue; } object value = pInfo.FastGetValue(argsObject); if (value == null || value == DBNull.Value) { arrParameter[i] = new OracleParameter(cmdParameter.Name, DBNull.Value); } else { if (!value.IsBooleanType()) { arrParameter[i] = new OracleParameter(cmdParameter.Name, cmdParameter.Type, value, cmdParameter.Direction); } else { arrParameter[i] = new OracleParameter(cmdParameter.Name, cmdParameter.Type, Convert.ToInt32(value), cmdParameter.Direction); } } } return(arrParameter); }