Commit d12f1aa9 authored by Damir Ainullin's avatar Damir Ainullin Committed by Marc Gravell

Use loop variable instead of 0 (#1334)

* Use loop variable instead of 0

* Changed unit test, added additional nesting level
parent 7769253d
...@@ -476,7 +476,7 @@ public async Task Issue346_QueryAsyncConvert() ...@@ -476,7 +476,7 @@ public async Task Issue346_QueryAsyncConvert()
public async Task TestSupportForDynamicParametersOutputExpressionsAsync() public async Task TestSupportForDynamicParametersOutputExpressionsAsync()
{ {
{ {
var bob = new Person { Name = "bob", PersonId = 1, Address = new Address { PersonId = 2 } }; var bob = new Person { Name = "bob", PersonId = 1, Address = new Address { PersonId = 2, Index = new Index() } };
var p = new DynamicParameters(bob); var p = new DynamicParameters(bob);
p.Output(bob, b => b.PersonId); p.Output(bob, b => b.PersonId);
...@@ -484,19 +484,22 @@ public async Task TestSupportForDynamicParametersOutputExpressionsAsync() ...@@ -484,19 +484,22 @@ public async Task TestSupportForDynamicParametersOutputExpressionsAsync()
p.Output(bob, b => b.NumberOfLegs); p.Output(bob, b => b.NumberOfLegs);
p.Output(bob, b => b.Address.Name); p.Output(bob, b => b.Address.Name);
p.Output(bob, b => b.Address.PersonId); p.Output(bob, b => b.Address.PersonId);
p.Output(bob, b => b.Address.Index.Id);
await connection.ExecuteAsync(@" await connection.ExecuteAsync(@"
SET @Occupation = 'grillmaster' SET @Occupation = 'grillmaster'
SET @PersonId = @PersonId + 1 SET @PersonId = @PersonId + 1
SET @NumberOfLegs = @NumberOfLegs - 1 SET @NumberOfLegs = @NumberOfLegs - 1
SET @AddressName = 'bobs burgers' SET @AddressName = 'bobs burgers'
SET @AddressPersonId = @PersonId", p).ConfigureAwait(false); SET @AddressPersonId = @PersonId
SET @AddressIndexId = '01088'", p).ConfigureAwait(false);
Assert.Equal("grillmaster", bob.Occupation); Assert.Equal("grillmaster", bob.Occupation);
Assert.Equal(2, bob.PersonId); Assert.Equal(2, bob.PersonId);
Assert.Equal(1, bob.NumberOfLegs); Assert.Equal(1, bob.NumberOfLegs);
Assert.Equal("bobs burgers", bob.Address.Name); Assert.Equal("bobs burgers", bob.Address.Name);
Assert.Equal(2, bob.Address.PersonId); Assert.Equal(2, bob.Address.PersonId);
Assert.Equal("01088", bob.Address.Index.Id);
} }
} }
......
using System; namespace Dapper.Tests
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Dapper.Tests
{ {
public class Address public class Address
{ {
public int AddressId { get; set; } public int AddressId { get; set; }
public string Name { get; set; } public string Name { get; set; }
public int PersonId { get; set; } public int PersonId { get; set; }
public Index Index { get; set; }
} }
} }
namespace Dapper.Tests
{
public class Index
{
public string Id { get; set; }
}
}
...@@ -407,10 +407,9 @@ public DynamicParameters Output<T>(T target, Expression<Func<T, object>> express ...@@ -407,10 +407,9 @@ public DynamicParameters Output<T>(T target, Expression<Func<T, object>> express
il.Emit(OpCodes.Castclass, typeof(T)); // [T] il.Emit(OpCodes.Castclass, typeof(T)); // [T]
// Count - 1 to skip the last member access // Count - 1 to skip the last member access
var i = 0; for (var i = 0; i < chain.Count - 1; i++)
for (; i < (chain.Count - 1); i++)
{ {
var member = chain[0].Member; var member = chain[i].Member;
if (member is PropertyInfo) if (member is PropertyInfo)
{ {
......
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