Commit fdc7a1ef authored by mgravell's avatar mgravell

hybrid parameters for new DynamicParameters(template)

parent b7245aac
......@@ -1194,6 +1194,27 @@ class ParamInfo
public IDbDataParameter AttachedParam { get; set; }
}
public DynamicParameters() { }
public DynamicParameters(object template)
{
const BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.Instance;
if (template != null)
{
foreach (PropertyInfo prop in template.GetType().GetProperties(bindingFlags))
{
if (!prop.CanRead) continue;
var idx = prop.GetIndexParameters();
if (idx != null && idx.Length != 0) continue;
Add("@" + prop.Name, prop.GetValue(template, null), null, ParameterDirection.Input, null);
}
foreach (FieldInfo field in template.GetType().GetFields(bindingFlags))
{
Add("@" + field.Name, field.GetValue(template), null, ParameterDirection.Input, null);
}
}
}
public void Add(
#if CSHARP30
......
......@@ -180,7 +180,13 @@ public void TestExecuteCommand()
set nocount on
drop table #t", new {a=1, b=2 }).IsEqualTo(2);
}
public void TestExecuteCommandWithHybridParameters()
{
var p = new DynamicParameters(new { a = 1, b = 2 });
p.Add("@c", dbType: DbType.Int32, direction: ParameterDirection.Output);
connection.Execute(@"set @c = @a + @b", p);
p.Get<int>("@c").IsEqualTo(3);
}
public void TestExecuteMultipleCommand()
{
connection.Execute("create table #t(i int)");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment