Commit 6fdba5f2 authored by Marc Gravell's avatar Marc Gravell

Merge pull request #349 from Nigrimmist/SmallFixesBranch

- code improvements
parents 0b212ea7 b2754e8e
......@@ -3494,7 +3494,6 @@ private static IDataReader ExecuteReaderImpl(IDbConnection cnn, ref CommandDefin
{
object param = command.Parameters;
IEnumerable multiExec = GetMultiExec(param);
Identity identity;
CacheInfo info = null;
if (multiExec != null)
{
......@@ -3504,7 +3503,7 @@ private static IDataReader ExecuteReaderImpl(IDbConnection cnn, ref CommandDefin
// nice and simple
if (param != null)
{
identity = new Identity(command.CommandText, command.CommandType, cnn, null, param.GetType(), null);
var identity = new Identity(command.CommandText, command.CommandType, cnn, null, param.GetType(), null);
info = GetCacheInfo(identity, param, command.AddToCache);
}
var paramReader = info == null ? null : info.ParamReader;
......@@ -3901,14 +3900,7 @@ public static void SetTypeMap(Type type, ITypeMap map)
// Store the value in the property/field
if (item.Property != null)
{
if (type.IsValueType())
{
il.Emit(OpCodes.Call, DefaultTypeMap.GetPropertySetter(item.Property, type)); // stack is now [target]
}
else
{
il.Emit(OpCodes.Callvirt, DefaultTypeMap.GetPropertySetter(item.Property, type)); // stack is now [target]
}
il.Emit(type.IsValueType() ? OpCodes.Call : OpCodes.Callvirt, DefaultTypeMap.GetPropertySetter(item.Property, type));
}
else
{
......@@ -4938,7 +4930,6 @@ public DynamicParameters Output<T>(T target, Expression<Func<T, object>> express
// Does the chain consist of MemberExpressions leading to a ParameterExpression of type T?
MemberExpression diving = lastMemberAccess;
ParameterExpression constant = null;
// Retain a list of member names and the member expressions so we can rebuild the chain.
List<string> names = new List<string>();
List<MemberExpression> chain = new List<MemberExpression>();
......@@ -4950,7 +4941,7 @@ public DynamicParameters Output<T>(T target, Expression<Func<T, object>> express
names.Insert(0, diving.Member.Name);
chain.Insert(0, diving);
constant = diving.Expression as ParameterExpression;
var constant = diving.Expression as ParameterExpression;
diving = diving.Expression as MemberExpression;
if (constant != null &&
......
......@@ -123,7 +123,7 @@ private static async Task<IEnumerable<T>> QueryAsync<T>(this IDbConnection cnn,
}
while (await reader.NextResultAsync().ConfigureAwait(false)) { }
while (await reader.NextResultAsync(cancel).ConfigureAwait(false)) { }
command.OnCompleted();
return buffer;
}
......
......@@ -131,7 +131,7 @@ internal static List<string> GetParamNames(object o)
{
var attribs = prop.GetCustomAttributes(typeof(IgnorePropertyAttribute), true);
var attr = attribs.FirstOrDefault() as IgnorePropertyAttribute;
if (attr==null || (attr != null && !attr.Value))
if (attr==null || (!attr.Value))
{
paramNames.Add(prop.Name);
}
......
......@@ -78,7 +78,7 @@ static List<PropertyInfo> RelevantProperties()
private static bool AreEqual<U>(U first, U second)
{
if (first == null && second == null) return true;
if (first == null && second != null) return false;
if (first == null) return false;
return first.Equals(second);
}
......@@ -171,7 +171,6 @@ private static bool AreEqual<U>(U first, U second)
// adapted from http://stackoverflow.com/a/966466/17174
private static Func<T, T> GenerateCloner()
{
Delegate myExec = null;
var dm = new DynamicMethod("DoClone", typeof(T), new Type[] { typeof(T) }, true);
var ctor = typeof(T).GetConstructor(new Type[] { });
......@@ -199,7 +198,7 @@ private static bool AreEqual<U>(U first, U second)
// Return constructed object. --> 0 items on stack
il.Emit(OpCodes.Ret);
myExec = dm.CreateDelegate(typeof(Func<T, T>));
var myExec = dm.CreateDelegate(typeof(Func<T, T>));
return (Func<T, T>)myExec;
}
......
......@@ -26,9 +26,9 @@ public SqlCompactTable(Database<TDatabase> database, string likelyTableName)
paramNames.Remove("Id");
string cols = string.Join(",", paramNames);
string cols_params = string.Join(",", paramNames.Select(p => "@" + p));
string colsParams = string.Join(",", paramNames.Select(p => "@" + p));
var sql = "insert " + TableName + " (" + cols + ") values (" + cols_params + ")";
var sql = "insert " + TableName + " (" + cols + ") values (" + colsParams + ")";
if (database.Execute(sql, o) != 1)
{
return null;
......
......@@ -175,7 +175,7 @@ private static void RunTests<T>(ref int fail, ref int skip, ref int pass, ref in
{
MethodInfo[] methods = typeof(T).GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
var activeTests = methods.Where(m => HasAttribute<ActiveTestAttribute>(m)).ToArray();
var activeTests = methods.Where(HasAttribute<ActiveTestAttribute>).ToArray();
if (activeTests.Length != 0) methods = activeTests;
foreach (var method in methods)
{
......
......@@ -20,7 +20,6 @@
using System.Dynamic;
using System.ComponentModel;
using Microsoft.CSharp.RuntimeBinder;
using System.Data.Common;
using System.Globalization;
using System.Threading;
using System.Data.SqlTypes;
......@@ -407,7 +406,7 @@ public void TestSchemaChangedMultiMap()
connection.Execute("create table #dog(Age int, Name nvarchar(max)) insert #dog values(1, 'Alf')");
try
{
var tuple = connection.Query<Dog, Dog, Tuple<Dog, Dog>>("select * from #dog d1 join #dog d2 on 1=1", (d1, d2) => Tuple.Create(d1, d2), splitOn: "Age").Single();
var tuple = connection.Query<Dog, Dog, Tuple<Dog, Dog>>("select * from #dog d1 join #dog d2 on 1=1", Tuple.Create, splitOn: "Age").Single();
tuple.Item1.Name.IsEqualTo("Alf");
tuple.Item1.Age.IsEqualTo(1);
......@@ -415,7 +414,7 @@ public void TestSchemaChangedMultiMap()
tuple.Item2.Age.IsEqualTo(1);
connection.Execute("alter table #dog drop column Name");
tuple = connection.Query<Dog, Dog, Tuple<Dog, Dog>>("select * from #dog d1 join #dog d2 on 1=1", (d1, d2) => Tuple.Create(d1, d2), splitOn: "Age").Single();
tuple = connection.Query<Dog, Dog, Tuple<Dog, Dog>>("select * from #dog d1 join #dog d2 on 1=1", Tuple.Create, splitOn: "Age").Single();
tuple.Item1.Name.IsNull();
tuple.Item1.Age.IsEqualTo(1);
......@@ -1573,7 +1572,7 @@ public void TestFlexibleMultiMapping()
3 as Id, 'fred' as Name
";
var personWithAddress = connection.Query<Person, Address, Extra, Tuple<Person, Address, Extra>>
(sql, (p, a, e) => Tuple.Create(p, a, e), splitOn: "AddressId,Id").First();
(sql, Tuple.Create, splitOn: "AddressId,Id").First();
personWithAddress.Item1.PersonId.IsEqualTo(1);
personWithAddress.Item1.Name.IsEqualTo("bob");
......@@ -1593,7 +1592,7 @@ public void TestMultiMappingWithSplitOnSpaceBetweenCommas()
3 as Id, 'fred' as Name
";
var personWithAddress = connection.Query<Person, Address, Extra, Tuple<Person, Address, Extra>>
(sql, (p, a, e) => Tuple.Create(p, a, e), splitOn: "AddressId, Id").First();
(sql, Tuple.Create, splitOn: "AddressId, Id").First();
personWithAddress.Item1.PersonId.IsEqualTo(1);
personWithAddress.Item1.Name.IsEqualTo("bob");
......@@ -2130,7 +2129,7 @@ class Bar1
}
public void TestMultiMapperIsNotConfusedWithUnorderedCols()
{
var result = connection.Query<Foo1, Bar1, Tuple<Foo1, Bar1>>("select 1 as Id, 2 as BarId, 3 as BarId, 'a' as Name", (f, b) => Tuple.Create(f, b), splitOn: "BarId").First();
var result = connection.Query<Foo1, Bar1, Tuple<Foo1, Bar1>>("select 1 as Id, 2 as BarId, 3 as BarId, 'a' as Name", Tuple.Create, splitOn: "BarId").First();
result.Item1.Id.IsEqualTo(1);
result.Item1.BarId.IsEqualTo(2);
......@@ -2534,7 +2533,7 @@ public void TestCustomTypeMap()
// custom mapping
var map = new CustomPropertyTypeMap(typeof(TypeWithMapping),
(type, columnName) => type.GetProperties().Where(prop => GetDescriptionFromAttribute(prop) == columnName).FirstOrDefault());
(type, columnName) => type.GetProperties().FirstOrDefault(prop => GetDescriptionFromAttribute(prop) == columnName));
Dapper.SqlMapper.SetTypeMap(typeof(TypeWithMapping), map);
item = connection.Query<TypeWithMapping>("Select 'AVal' as A, 'BVal' as B").Single();
......@@ -2837,10 +2836,7 @@ public void TestIssue131()
{
var results = connection.Query<dynamic, int, dynamic>(
"SELECT 1 Id, 'Mr' Title, 'John' Surname, 4 AddressCount",
(person, addressCount) =>
{
return person;
},
(person, addressCount) => person,
splitOn: "AddressCount"
).FirstOrDefault();
......
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