mirror of
https://github.com/FalconWu2017/Falcon.StoredProcedureRunner.git
synced 2024-11-23 13:39:38 +08:00
为返回值对象赋值失败时会引发ReturnDataSetValueException异常。
This commit is contained in:
parent
9b1b54c5ec
commit
b031355576
|
@ -0,0 +1,22 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Falcon.StoredProcedureRunner
|
||||
{
|
||||
/// <summary>
|
||||
/// 设置返回对象值时候发生异常
|
||||
/// </summary>
|
||||
public class ReturnDataSetValueException:Exception
|
||||
{
|
||||
/// <summary>
|
||||
/// 实例化一个给返回数据设置值的异常
|
||||
/// </summary>
|
||||
/// <param name="rowId">返回数据行号</param>
|
||||
/// <param name="cName">返回的列名</param>
|
||||
/// <param name="pi">要设置值的属性</param>
|
||||
/// <param name="value">要设置的值</param>
|
||||
/// <param name="innException">内部异常</param>
|
||||
public ReturnDataSetValueException(int rowId,string cName, PropertyInfo pi,object value,Exception innException)
|
||||
: base($"存储过程返回第[{rowId}]行[{cName}]列数据值为({value.GetType().FullName})[{value}]无法赋给属性({pi.PropertyType.FullName})[{pi.Name}]。",innException) { }
|
||||
}
|
||||
}
|
|
@ -86,6 +86,7 @@ namespace Falcon.StoredProcedureRunner
|
|||
var result = new List<object>();
|
||||
if(!dr.CanGetColumnSchema())
|
||||
return result;
|
||||
int rowId = 0;
|
||||
while(dr.Read()) {
|
||||
var item = returnType.Assembly.CreateInstance(returnType.FullName);
|
||||
var columnSchema = dr.GetColumnSchema();
|
||||
|
@ -95,9 +96,14 @@ namespace Falcon.StoredProcedureRunner
|
|||
var pi = getProperty(returnType,name);
|
||||
if(pi == null || !pi.CanWrite)
|
||||
continue;
|
||||
try {
|
||||
pi.SetValue(item,value);
|
||||
} catch(Exception ex) {
|
||||
throw new ReturnDataSetValueException(rowId,name,pi,value,ex);
|
||||
}
|
||||
}
|
||||
result.Add(item);
|
||||
rowId++;
|
||||
}
|
||||
connection.Close();
|
||||
return result;
|
||||
|
|
Loading…
Reference in New Issue
Block a user