Commit 071a3fd5 authored by Nick Craver's avatar Nick Craver

.editorconfig and formatting

parent 9e67f97f
# EditorConfig is awesome:http://EditorConfig.org
# top-most EditorConfig file
root = true
# Don't use tabs for indentation.
[*]
indent_style = space
# (Please don't specify an indent_size here; that has too many unintended consequences.)
# Code files
[*.{cs,csx,vb,vbx}]
indent_size = 4
insert_final_newline = true
charset = utf-8-bom
# Xml project files
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}]
indent_size = 2
# Xml config files
[*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}]
indent_size = 2
# JSON files
[*.json]
indent_size = 2
# Dotnet code style settings:
[*.{cs,vb}]
# Sort using and Import directives with System.* appearing first
dotnet_sort_system_directives_first = true
# Avoid "this." and "Me." if not necessary
dotnet_style_qualification_for_field = false:suggestion
dotnet_style_qualification_for_property = false:suggestion
dotnet_style_qualification_for_method = false:suggestion
dotnet_style_qualification_for_event = false:suggestion
# Use language keywords instead of framework type names for type references
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
dotnet_style_predefined_type_for_member_access = true:suggestion
# Suggest more modern language features when available
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion
# CSharp code style settings:
[*.cs]
# Prefer "var" everywhere
#csharp_style_var_for_built_in_types = true:suggestion
#csharp_style_var_when_type_is_apparent = false:suggestion
#csharp_style_var_elsewhere = true:suggestion
# Prefer method-like constructs to have a expression-body
csharp_style_expression_bodied_methods = true:none
csharp_style_expression_bodied_constructors = true:none
csharp_style_expression_bodied_operators = true:none
# Prefer property-like constructs to have an expression-body
csharp_style_expression_bodied_properties = true:none
csharp_style_expression_bodied_indexers = true:none
csharp_style_expression_bodied_accessors = true:none
# Suggest more modern language features when available
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion
csharp_style_throw_expression = true:suggestion
csharp_style_conditional_delegate_call = true:suggestion
# Newline settings
csharp_new_line_before_open_brace = all
csharp_new_line_before_else = true
csharp_new_line_before_catch = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_members_in_anonymous_types = true
\ No newline at end of file
......@@ -92,7 +92,7 @@ public static partial class SqlMapperExtensions
private static async Task<IEnumerable<T>> GetAllAsyncImpl<T>(IDbConnection connection, IDbTransaction transaction, int? commandTimeout, string sql, Type type) where T : class
{
var result = await connection.QueryAsync(sql);
var result = await connection.QueryAsync(sql).ConfigureAwait(false);
var list = new List<T>();
foreach (IDictionary<string, object> res in result)
{
......@@ -313,7 +313,7 @@ public partial interface ISqlAdapter
/// <param name="keyProperties">The key columns in this table.</param>
/// <param name="entityToInsert">The entity to insert.</param>
/// <returns>The Id of the row created.</returns>
Task<int> InsertAsync(IDbConnection connection, IDbTransaction transaction, int? commandTimeout, String tableName, string columnList, string parameterList, IEnumerable<PropertyInfo> keyProperties, object entityToInsert);
Task<int> InsertAsync(IDbConnection connection, IDbTransaction transaction, int? commandTimeout, string tableName, string columnList, string parameterList, IEnumerable<PropertyInfo> keyProperties, object entityToInsert);
}
public partial class SqlServerAdapter
......@@ -330,10 +330,10 @@ public partial class SqlServerAdapter
/// <param name="keyProperties">The key columns in this table.</param>
/// <param name="entityToInsert">The entity to insert.</param>
/// <returns>The Id of the row created.</returns>
public async Task<int> InsertAsync(IDbConnection connection, IDbTransaction transaction, int? commandTimeout, String tableName, string columnList, string parameterList, IEnumerable<PropertyInfo> keyProperties, object entityToInsert)
public async Task<int> InsertAsync(IDbConnection connection, IDbTransaction transaction, int? commandTimeout, string tableName, string columnList, string parameterList, IEnumerable<PropertyInfo> keyProperties, object entityToInsert)
{
var cmd = $"INSERT INTO {tableName} ({columnList}) values ({parameterList}); SELECT SCOPE_IDENTITY() id";
var multi = await connection.QueryMultipleAsync(cmd, entityToInsert, transaction, commandTimeout);
var multi = await connection.QueryMultipleAsync(cmd, entityToInsert, transaction, commandTimeout).ConfigureAwait(false);
var first = multi.Read().FirstOrDefault();
if (first == null || first.id == null) return 0;
......@@ -485,7 +485,7 @@ public partial class SQLiteAdapter
public async Task<int> InsertAsync(IDbConnection connection, IDbTransaction transaction, int? commandTimeout, string tableName, string columnList, string parameterList, IEnumerable<PropertyInfo> keyProperties, object entityToInsert)
{
var cmd = $"INSERT INTO {tableName} ({columnList}) VALUES ({parameterList}); SELECT last_insert_rowid() id";
var multi = await connection.QueryMultipleAsync(cmd, entityToInsert, transaction, commandTimeout);
var multi = await connection.QueryMultipleAsync(cmd, entityToInsert, transaction, commandTimeout).ConfigureAwait(false);
var id = (int)multi.Read().First().id;
var pi = keyProperties as PropertyInfo[] ?? keyProperties.ToArray();
......@@ -515,11 +515,11 @@ public partial class FbAdapter
public async Task<int> InsertAsync(IDbConnection connection, IDbTransaction transaction, int? commandTimeout, string tableName, string columnList, string parameterList, IEnumerable<PropertyInfo> keyProperties, object entityToInsert)
{
var cmd = $"insert into {tableName} ({columnList}) values ({parameterList})";
await connection.ExecuteAsync(cmd, entityToInsert, transaction, commandTimeout);
await connection.ExecuteAsync(cmd, entityToInsert, transaction, commandTimeout).ConfigureAwait(false);
var propertyInfos = keyProperties as PropertyInfo[] ?? keyProperties.ToArray();
var keyName = propertyInfos[0].Name;
var r = await connection.QueryAsync($"SELECT FIRST 1 {keyName} ID FROM {tableName} ORDER BY {keyName} DESC", transaction: transaction, commandTimeout: commandTimeout);
var r = await connection.QueryAsync($"SELECT FIRST 1 {keyName} ID FROM {tableName} ORDER BY {keyName} DESC", transaction: transaction, commandTimeout: commandTimeout).ConfigureAwait(false);
var id = r.First().ID;
if (id == null) return 0;
......
......@@ -114,7 +114,7 @@ private static List<PropertyInfo> KeyPropertiesCache(Type type)
if (keyProperties.Count == 0)
{
var idProp = allProperties.FirstOrDefault(p => p.Name.ToLower() == "id");
var idProp = allProperties.Find(p => string.Equals(p.Name, "id", StringComparison.CurrentCultureIgnoreCase));
if (idProp != null && !idProp.GetCustomAttributes(true).Any(a => a is ExplicitKeyAttribute))
{
keyProperties.Add(idProp);
......@@ -148,7 +148,7 @@ private static bool IsWriteable(PropertyInfo pi)
private static PropertyInfo GetSingleKey<T>(string method)
{
var type = typeof (T);
var type = typeof(T);
var keys = KeyPropertiesCache(type);
var explicitKeys = ExplicitKeyPropertiesCache(type);
var keyCount = keys.Count + explicitKeys.Count;
......@@ -564,17 +564,17 @@ public static T GetInterfaceProxy<T>()
private static MethodInfo CreateIsDirtyProperty(TypeBuilder typeBuilder)
{
var propType = typeof(bool);
var field = typeBuilder.DefineField("_" + "IsDirty", propType, FieldAttributes.Private);
var property = typeBuilder.DefineProperty("IsDirty",
var field = typeBuilder.DefineField("_" + nameof(IProxy.IsDirty), propType, FieldAttributes.Private);
var property = typeBuilder.DefineProperty(nameof(IProxy.IsDirty),
System.Reflection.PropertyAttributes.None,
propType,
new[] { propType });
const MethodAttributes getSetAttr = MethodAttributes.Public | MethodAttributes.NewSlot | MethodAttributes.SpecialName |
MethodAttributes.Final | MethodAttributes.Virtual | MethodAttributes.HideBySig;
const MethodAttributes getSetAttr = MethodAttributes.Public | MethodAttributes.NewSlot | MethodAttributes.SpecialName
| MethodAttributes.Final | MethodAttributes.Virtual | MethodAttributes.HideBySig;
// Define the "get" and "set" accessor methods
var currGetPropMthdBldr = typeBuilder.DefineMethod("get_" + "IsDirty",
var currGetPropMthdBldr = typeBuilder.DefineMethod("get_" + nameof(IProxy.IsDirty),
getSetAttr,
propType,
Type.EmptyTypes);
......@@ -582,7 +582,7 @@ private static MethodInfo CreateIsDirtyProperty(TypeBuilder typeBuilder)
currGetIl.Emit(OpCodes.Ldarg_0);
currGetIl.Emit(OpCodes.Ldfld, field);
currGetIl.Emit(OpCodes.Ret);
var currSetPropMthdBldr = typeBuilder.DefineMethod("set_" + "IsDirty",
var currSetPropMthdBldr = typeBuilder.DefineMethod("set_" + nameof(IProxy.IsDirty),
getSetAttr,
null,
new[] { propType });
......@@ -594,8 +594,8 @@ private static MethodInfo CreateIsDirtyProperty(TypeBuilder typeBuilder)
property.SetGetMethod(currGetPropMthdBldr);
property.SetSetMethod(currSetPropMthdBldr);
var getMethod = typeof(IProxy).GetMethod("get_" + "IsDirty");
var setMethod = typeof(IProxy).GetMethod("set_" + "IsDirty");
var getMethod = typeof(IProxy).GetMethod("get_" + nameof(IProxy.IsDirty));
var setMethod = typeof(IProxy).GetMethod("set_" + nameof(IProxy.IsDirty));
typeBuilder.DefineMethodOverride(currGetPropMthdBldr, getMethod);
typeBuilder.DefineMethodOverride(currSetPropMthdBldr, setMethod);
......@@ -841,7 +841,7 @@ public int Insert(IDbConnection connection, IDbTransaction transaction, int? com
var r = connection.Query("select @@IDENTITY id", transaction: transaction, commandTimeout: commandTimeout).ToList();
if (r[0].id == null) return 0;
var id = (int) r[0].id;
var id = (int)r[0].id;
var propertyInfos = keyProperties as PropertyInfo[] ?? keyProperties.ToArray();
if (propertyInfos.Length == 0) return id;
......
......@@ -88,7 +88,7 @@ public Task<int> UpdateAsync(TId id, dynamic data)
/// <param name="param">The parameters to use.</param>
/// <returns>The number of rows affected.</returns>
public Task<int> ExecuteAsync(string sql, dynamic param = null) =>
_connection.ExecuteAsync(sql, param as object, _transaction, this._commandTimeout);
_connection.ExecuteAsync(sql, param as object, _transaction, _commandTimeout);
/// <summary>
/// Asynchronously queries the current database.
......
......@@ -238,7 +238,7 @@ public void RollbackTransaction()
/// <returns>The function to create the <paramref name="tableType"/> table.</returns>
protected Action<TDatabase> CreateTableConstructor(Type tableType)
{
return CreateTableConstructor(new[] {tableType});
return CreateTableConstructor(new[] { tableType });
}
/// <summary>
......@@ -315,7 +315,7 @@ private bool TableExists(string name)
name = name.Replace("[", "");
name = name.Replace("]", "");
if(name.Contains("."))
if (name.Contains("."))
{
var parts = name.Split('.');
if (parts.Length == 2)
......
......@@ -40,7 +40,7 @@ public async Task InsertGetUpdateDeleteWithExplicitKeyAsync()
var originalyCount = connection.Query<int>("Select Count(*) From ObjectY").First();
await connection.InsertAsync(o2).ConfigureAwait(false);
var list2 = (await connection.QueryAsync<ObjectY>("select * from ObjectY").ConfigureAwait(false)).ToList();
Assert.Equal(list2.Count, originalyCount+1);
Assert.Equal(list2.Count, originalyCount + 1);
o2 = await connection.GetAsync<ObjectY>(id).ConfigureAwait(false);
Assert.Equal(o2.ObjectYId, id);
o2.Name = "Bar";
......@@ -112,13 +112,13 @@ public async Task InsertGetUpdateAsync()
Assert.True(await connection.UpdateAsync(notrackedUser).ConfigureAwait(false));
Assert.Equal("Cecil", (await connection.GetAsync<User>(id).ConfigureAwait(false)).Name);
Assert.Equal((await connection.QueryAsync<User>("select * from Users").ConfigureAwait(false)).Count(), originalCount+1);
Assert.Equal((await connection.QueryAsync<User>("select * from Users").ConfigureAwait(false)).Count(), originalCount + 1);
Assert.True(await connection.DeleteAsync(user).ConfigureAwait(false));
Assert.Equal((await connection.QueryAsync<User>("select * from Users").ConfigureAwait(false)).Count(), originalCount);
Assert.False(await connection.UpdateAsync(notrackedUser).ConfigureAwait(false)); //returns false, user not found
Assert.True(await connection.InsertAsync(new User {Name = "Adam", Age = 10}).ConfigureAwait(false) > originalCount + 1);
Assert.True(await connection.InsertAsync(new User { Name = "Adam", Age = 10 }).ConfigureAwait(false) > originalCount + 1);
}
}
......
......@@ -180,7 +180,7 @@ public void GetAllWithExplicitKey()
var objectXs = connection.GetAll<ObjectX>().ToList();
Assert.True(objectXs.Count > 0);
Assert.Equal(1, objectXs.Count(x => x.ObjectXId== guid));
Assert.Equal(1, objectXs.Count(x => x.ObjectXId == guid));
}
}
......
......@@ -63,7 +63,7 @@ public class MySqlServerTestSuite : TestSuite
{
private const string DbName = "DapperContribTests";
public static string ConnectionString { get; private set; } =
public static string ConnectionString { get; } =
IsAppVeyor
? "Server=localhost;Uid=root;Pwd=Password12!;"
: "Server=localhost;Uid=test;Pwd=pass;";
......
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes;
using Dapper.Contrib.Extensions;
using System.Linq;
......
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes;
using System;
using System.Data;
using System.Data.SqlClient;
......@@ -86,7 +86,7 @@ public dynamic DataTableDynamic()
reader.Read();
reader.GetValues(values);
_table.Rows.Add(values);
return _table.Rows[_table.Rows.Count-1];
return _table.Rows[_table.Rows.Count - 1];
}
}
}
......
......@@ -9,6 +9,6 @@ public EFContext(DbConnection connection, bool owned = false) : base(connection,
{
}
public DbSet<Post> Posts { get;set; }
public DbSet<Post> Posts { get; set; }
}
}
using System;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Linq;
......@@ -266,7 +266,8 @@ public async Task RunAsync(int iterations)
}, "Belgrade Sql Client");
//Susanoo
Try(() => {
Try(() =>
{
var susanooDb = new DatabaseManager(connection);
var susanooPreDefinedCommand =
......@@ -307,7 +308,8 @@ public async Task RunAsync(int iterations)
}, "ServiceStack.OrmLite");
// Hand Coded
Try(() => {
Try(() =>
{
var postCommand = new SqlCommand()
{
Connection = connection,
......
......@@ -23,7 +23,7 @@ namespace Dapper.Tests.Performance.Linq2Sql
using System;
[global::System.Data.Linq.Mapping.DatabaseAttribute(Name="tempdb")]
[global::System.Data.Linq.Mapping.DatabaseAttribute(Name = "tempdb")]
public partial class DataClassesDataContext : System.Data.Linq.DataContext
{
......@@ -69,7 +69,7 @@ public System.Data.Linq.Table<Post> Posts
}
}
[global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.Posts")]
[global::System.Data.Linq.Mapping.TableAttribute(Name = "dbo.Posts")]
public partial class Post : INotifyPropertyChanging, INotifyPropertyChanged
{
......@@ -138,7 +138,7 @@ public Post()
OnCreated();
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Id", AutoSync=AutoSync.OnInsert, DbType="Int NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)]
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_Id", AutoSync = AutoSync.OnInsert, DbType = "Int NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)]
public int Id
{
get
......@@ -158,7 +158,7 @@ public int Id
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Text", DbType="VarChar(MAX) NOT NULL", CanBeNull=false)]
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_Text", DbType = "VarChar(MAX) NOT NULL", CanBeNull = false)]
public string Text
{
get
......@@ -178,7 +178,7 @@ public string Text
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_CreationDate", DbType="DateTime NOT NULL")]
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_CreationDate", DbType = "DateTime NOT NULL")]
public System.DateTime CreationDate
{
get
......@@ -198,7 +198,7 @@ public System.DateTime CreationDate
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_LastChangeDate", DbType="DateTime NOT NULL")]
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_LastChangeDate", DbType = "DateTime NOT NULL")]
public System.DateTime LastChangeDate
{
get
......@@ -218,7 +218,7 @@ public System.DateTime LastChangeDate
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Counter1", DbType="Int")]
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_Counter1", DbType = "Int")]
public System.Nullable<int> Counter1
{
get
......@@ -238,7 +238,7 @@ public System.Nullable<int> Counter1
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Counter2", DbType="Int")]
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_Counter2", DbType = "Int")]
public System.Nullable<int> Counter2
{
get
......@@ -258,7 +258,7 @@ public System.Nullable<int> Counter2
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Counter3", DbType="Int")]
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_Counter3", DbType = "Int")]
public System.Nullable<int> Counter3
{
get
......@@ -278,7 +278,7 @@ public System.Nullable<int> Counter3
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Counter4", DbType="Int")]
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_Counter4", DbType = "Int")]
public System.Nullable<int> Counter4
{
get
......@@ -298,7 +298,7 @@ public System.Nullable<int> Counter4
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Counter5", DbType="Int")]
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_Counter5", DbType = "Int")]
public System.Nullable<int> Counter5
{
get
......@@ -318,7 +318,7 @@ public System.Nullable<int> Counter5
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Counter6", DbType="Int")]
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_Counter6", DbType = "Int")]
public System.Nullable<int> Counter6
{
get
......@@ -338,7 +338,7 @@ public System.Nullable<int> Counter6
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Counter7", DbType="Int")]
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_Counter7", DbType = "Int")]
public System.Nullable<int> Counter7
{
get
......@@ -358,7 +358,7 @@ public System.Nullable<int> Counter7
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Counter8", DbType="Int")]
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_Counter8", DbType = "Int")]
public System.Nullable<int> Counter8
{
get
......@@ -378,7 +378,7 @@ public System.Nullable<int> Counter8
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Counter9", DbType="Int")]
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_Counter9", DbType = "Int")]
public System.Nullable<int> Counter9
{
get
......
......@@ -25,7 +25,7 @@ public async Task TestBasicStringUsageAsync()
[Fact]
public async Task TestBasicStringUsageQueryFirstAsync()
{
var str = await connection.QueryFirstAsync<string>(new CommandDefinition("select 'abc' as [Value] union all select @txt", new {txt = "def"})).ConfigureAwait(false);
var str = await connection.QueryFirstAsync<string>(new CommandDefinition("select 'abc' as [Value] union all select @txt", new { txt = "def" })).ConfigureAwait(false);
Assert.Equal("abc", str);
}
......@@ -39,7 +39,7 @@ public async Task TestBasicStringUsageQueryFirstAsyncDynamic()
[Fact]
public async Task TestBasicStringUsageQueryFirstOrDefaultAsync()
{
var str = await connection.QueryFirstOrDefaultAsync<string>(new CommandDefinition("select null as [Value] union all select @txt", new {txt = "def"})).ConfigureAwait(false);
var str = await connection.QueryFirstOrDefaultAsync<string>(new CommandDefinition("select null as [Value] union all select @txt", new { txt = "def" })).ConfigureAwait(false);
Assert.Null(str);
}
......@@ -165,7 +165,8 @@ public async Task TestMultiMapWithSplitAsync()
public async Task TestMultiMapArbitraryWithSplitAsync()
{
const string sql = "select 1 as id, 'abc' as name, 2 as id, 'def' as name";
var productQuery = await connection.QueryAsync<Product>(sql, new[] { typeof(Product), typeof(Category) }, (objects) => {
var productQuery = await connection.QueryAsync<Product>(sql, new[] { typeof(Product), typeof(Category) }, (objects) =>
{
var prod = (Product)objects[0];
prod.Category = (Category)objects[1];
return prod;
......@@ -393,7 +394,8 @@ public void AssertNoCacheWorksForQueryMultiple()
const int a = 123, b = 456;
var cmdDef = new CommandDefinition("select @a; select @b;", new
{
a, b
a,
b
}, commandType: CommandType.Text, flags: CommandFlags.NoCache);
int c, d;
......@@ -784,7 +786,7 @@ public async Task Issue157_ClosedReaderAsync()
var args = new { x = 42 };
const string sql = "select 123 as [A], 'abc' as [B] where @x=42";
var row = (await connection.QueryAsync<SomeType>(new CommandDefinition(
sql, args, flags:CommandFlags.None)).ConfigureAwait(false)).Single();
sql, args, flags: CommandFlags.None)).ConfigureAwait(false)).Single();
Assert.NotNull(row);
Assert.Equal(123, row.A);
Assert.Equal("abc", row.B);
......
......@@ -91,9 +91,9 @@ union all
var col = reader.GetOrdinal("Type");
var splitOn = reader.GetOrdinal("Id");
var toFoo = reader.GetRowParser<DiscriminatedWithMultiMapping_BaseType>(typeof(DiscriminatedWithMultiMapping_Foo),0, splitOn);
var toBar = reader.GetRowParser<DiscriminatedWithMultiMapping_BaseType>(typeof(DiscriminatedWithMultiMapping_Bar),0, splitOn);
var toHaz = reader.GetRowParser<HazNameId>(typeof(HazNameId),splitOn, reader.FieldCount - splitOn);
var toFoo = reader.GetRowParser<DiscriminatedWithMultiMapping_BaseType>(typeof(DiscriminatedWithMultiMapping_Foo), 0, splitOn);
var toBar = reader.GetRowParser<DiscriminatedWithMultiMapping_BaseType>(typeof(DiscriminatedWithMultiMapping_Bar), 0, splitOn);
var toHaz = reader.GetRowParser<HazNameId>(typeof(HazNameId), splitOn, reader.FieldCount - splitOn);
do
{
......
......@@ -59,7 +59,8 @@ private void TestNullable(bool applyNulls)
Assert.Equal(AnEnum.B, obj.D);
Assert.Equal(AnEnum.B, obj.E);
}
} finally
}
finally
{
SqlMapper.Settings.ApplyNullValues = oldSetting;
}
......
......@@ -445,7 +445,7 @@ public void SO29533765_DataTableParametersViaDynamicParameters()
connection.Execute("create type MyTVPType as table (id int)");
connection.Execute("create proc #DataTableParameters @ids MyTVPType readonly as select count(1) from @ids");
var table = new DataTable { TableName="MyTVPType", Columns = { { "id", typeof(int) } }, Rows = { { 1 }, { 2 }, { 3 } } };
var table = new DataTable { TableName = "MyTVPType", Columns = { { "id", typeof(int) } }, Rows = { { 1 }, { 2 }, { 3 } } };
table.SetTypeName(table.TableName); // per SO29533765
IDictionary<string, object> args = new Dictionary<string, object>
{
......@@ -1060,8 +1060,9 @@ public void SO25297173_DynamicIn()
insert @table values(6);
insert @table values(7);
SELECT value FROM @table WHERE value IN @myIds";
var queryParams = new Dictionary<string, object> {
["myIds"] = new [] { 5, 6 }
var queryParams = new Dictionary<string, object>
{
["myIds"] = new[] { 5, 6 }
};
var dynamicParams = new DynamicParameters(queryParams);
......
......@@ -145,7 +145,7 @@ public void Issue524_QueryMultiple_Cast()
Assert.Equal(42, connection.QuerySingle<int>("select cast(42 as bigint)"));
// using multi-reader API
using(var reader = connection.QueryMultiple("select cast(42 as bigint); select cast(42 as bigint)"))
using (var reader = connection.QueryMultiple("select cast(42 as bigint); select cast(42 as bigint)"))
{
Assert.Equal(42, reader.Read<int>().Single());
Assert.Equal(42, reader.ReadSingle<int>());
......
......@@ -377,9 +377,9 @@ private RatingValueHandler()
public override RatingValue Parse(object value)
{
if (value is Int32)
if (value is int)
{
return new RatingValue() { Value = (Int32)value };
return new RatingValue() { Value = (int)value };
}
throw new FormatException("Invalid conversion to RatingValue");
......@@ -395,13 +395,13 @@ public override void SetValue(IDbDataParameter parameter, RatingValue value)
public class RatingValue
{
public Int32 Value { get; set; }
public int Value { get; set; }
// ... some other properties etc ...
}
public class MyResult
{
public String CategoryName { get; set; }
public string CategoryName { get; set; }
public RatingValue CategoryRating { get; set; }
}
......@@ -424,7 +424,7 @@ public void SO24740733_TestCustomValueSingleColumn()
Assert.Equal(200, foo.Value);
}
public class StringListTypeHandler : SqlMapper.TypeHandler<List<String>>
public class StringListTypeHandler : SqlMapper.TypeHandler<List<string>>
{
private StringListTypeHandler()
{
......@@ -434,18 +434,18 @@ private StringListTypeHandler()
//Just a simple List<string> type handler implementation
public override void SetValue(IDbDataParameter parameter, List<string> value)
{
parameter.Value = String.Join(",", value);
parameter.Value = string.Join(",", value);
}
public override List<string> Parse(object value)
{
return ((value as String) ?? "").Split(',').ToList();
return ((value as string) ?? "").Split(',').ToList();
}
}
public class MyObjectWithStringList
{
public List<String> Names { get; set; }
public List<string> Names { get; set; }
}
[Fact]
......
......@@ -5,6 +5,7 @@ VisualStudioVersion = 15.0.26730.8
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A34907DF-958A-4E4C-8491-84CF303FD13E}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
appveyor.yml = appveyor.yml
build.ps1 = build.ps1
build.sh = build.sh
......
......@@ -61,7 +61,6 @@ public void AddParameter(IDbCommand command, string name)
{
param = command.CreateParameter();
param.ParameterName = name;
}
else
{
......
......@@ -91,7 +91,7 @@ public ConstructorInfo FindConstructor(string[] names, Type[] types)
int i = 0;
for (; i < ctorParameters.Length; i++)
{
if (!String.Equals(ctorParameters[i].Name, names[i], StringComparison.OrdinalIgnoreCase))
if (!string.Equals(ctorParameters[i].Name, names[i], StringComparison.OrdinalIgnoreCase))
break;
if (types[i] == typeof(byte[]) && ctorParameters[i].ParameterType.FullName == SqlMapper.LinqBinary)
continue;
......@@ -152,13 +152,13 @@ public SqlMapper.IMemberMap GetConstructorParameter(ConstructorInfo constructor,
/// <returns>Mapping implementation</returns>
public SqlMapper.IMemberMap GetMember(string columnName)
{
var property = Properties.FirstOrDefault(p => string.Equals(p.Name, columnName, StringComparison.Ordinal))
?? Properties.FirstOrDefault(p => string.Equals(p.Name, columnName, StringComparison.OrdinalIgnoreCase));
var property = Properties.Find(p => string.Equals(p.Name, columnName, StringComparison.Ordinal))
?? Properties.Find(p => string.Equals(p.Name, columnName, StringComparison.OrdinalIgnoreCase));
if (property == null && MatchNamesWithUnderscores)
{
property = Properties.FirstOrDefault(p => string.Equals(p.Name, columnName.Replace("_", ""), StringComparison.Ordinal))
?? Properties.FirstOrDefault(p => string.Equals(p.Name, columnName.Replace("_", ""), StringComparison.OrdinalIgnoreCase));
property = Properties.Find(p => string.Equals(p.Name, columnName.Replace("_", ""), StringComparison.Ordinal))
?? Properties.Find(p => string.Equals(p.Name, columnName.Replace("_", ""), StringComparison.OrdinalIgnoreCase));
}
if (property != null)
......@@ -169,20 +169,20 @@ public SqlMapper.IMemberMap GetMember(string columnName)
// preference order is:
// exact match over underscre match, exact case over wrong case, backing fields over regular fields, match-inc-underscores over match-exc-underscores
var field = _fields.FirstOrDefault(p => string.Equals(p.Name, columnName, StringComparison.Ordinal))
?? _fields.FirstOrDefault(p => string.Equals(p.Name, backingFieldName, StringComparison.Ordinal))
?? _fields.FirstOrDefault(p => string.Equals(p.Name, columnName, StringComparison.OrdinalIgnoreCase))
?? _fields.FirstOrDefault(p => string.Equals(p.Name, backingFieldName, StringComparison.OrdinalIgnoreCase));
var field = _fields.Find(p => string.Equals(p.Name, columnName, StringComparison.Ordinal))
?? _fields.Find(p => string.Equals(p.Name, backingFieldName, StringComparison.Ordinal))
?? _fields.Find(p => string.Equals(p.Name, columnName, StringComparison.OrdinalIgnoreCase))
?? _fields.Find(p => string.Equals(p.Name, backingFieldName, StringComparison.OrdinalIgnoreCase));
if (field == null && MatchNamesWithUnderscores)
{
var effectiveColumnName = columnName.Replace("_", "");
backingFieldName = "<" +effectiveColumnName + ">k__BackingField";
backingFieldName = "<" + effectiveColumnName + ">k__BackingField";
field = _fields.FirstOrDefault(p => string.Equals(p.Name, effectiveColumnName, StringComparison.Ordinal))
?? _fields.FirstOrDefault(p => string.Equals(p.Name, backingFieldName, StringComparison.Ordinal))
?? _fields.FirstOrDefault(p => string.Equals(p.Name, effectiveColumnName, StringComparison.OrdinalIgnoreCase))
?? _fields.FirstOrDefault(p => string.Equals(p.Name, backingFieldName, StringComparison.OrdinalIgnoreCase));
field = _fields.Find(p => string.Equals(p.Name, effectiveColumnName, StringComparison.Ordinal))
?? _fields.Find(p => string.Equals(p.Name, backingFieldName, StringComparison.Ordinal))
?? _fields.Find(p => string.Equals(p.Name, effectiveColumnName, StringComparison.OrdinalIgnoreCase))
?? _fields.Find(p => string.Equals(p.Name, backingFieldName, StringComparison.OrdinalIgnoreCase));
}
if (field != null)
......
......@@ -394,7 +394,7 @@ public DynamicParameters Output<T>(T target, Expression<Func<T, object>> express
}
while (diving != null);
var dynamicParamName = string.Join(string.Empty, names.ToArray());
var dynamicParamName = string.Concat(names.ToArray());
// Before we get all emitty...
var lookup = string.Join("|", names.ToArray());
......
......@@ -407,7 +407,7 @@ private static async Task<IEnumerable<T>> QueryAsync<T>(this IDbConnection cnn,
object val = func(reader);
if (val == null || val is T)
{
buffer.Add((T) val);
buffer.Add((T)val);
}
else
{
......@@ -564,7 +564,8 @@ private static async Task<int> ExecuteMultiImplAsync(IDbConnection cnn, CommandD
masterSql = cmd.CommandText;
var identity = new Identity(command.CommandText, cmd.CommandType, cnn, null, obj.GetType(), null);
info = GetCacheInfo(identity, obj, command.AddToCache);
} else if(pending.Count >= MAX_PENDING)
}
else if (pending.Count >= MAX_PENDING)
{
var recycled = pending.Dequeue();
total += await recycled.Task.ConfigureAwait(false);
......@@ -955,15 +956,18 @@ private static async Task<IEnumerable<TReturn>> MultiMapAsync<TReturn>(this IDbC
var identity = new Identity(command.CommandText, command.CommandType, cnn, types[0], param?.GetType(), types);
var info = GetCacheInfo(identity, param, command.AddToCache);
bool wasClosed = cnn.State == ConnectionState.Closed;
try {
try
{
if (wasClosed) await ((DbConnection)cnn).OpenAsync().ConfigureAwait(false);
using (var cmd = (DbCommand)command.SetupCommand(cnn, info.ParamReader))
using (var reader = await ExecuteReaderWithFlagsFallbackAsync(cmd, wasClosed, CommandBehavior.SequentialAccess | CommandBehavior.SingleResult, command.CancellationToken).ConfigureAwait(false)) {
using (var reader = await ExecuteReaderWithFlagsFallbackAsync(cmd, wasClosed, CommandBehavior.SequentialAccess | CommandBehavior.SingleResult, command.CancellationToken).ConfigureAwait(false))
{
var results = MultiMapImpl(null, default(CommandDefinition), types, map, splitOn, reader, identity, true);
return command.Buffered ? results.ToList() : results;
}
}
finally {
finally
{
if (wasClosed) cnn.Close();
}
}
......@@ -1027,7 +1031,8 @@ public static async Task<GridReader> QueryMultipleAsync(this IDbConnection cnn,
if (!reader.IsClosed)
{
try { cmd.Cancel(); }
catch { /* don't spoil the existing exception */
catch
{ /* don't spoil the existing exception */
}
}
reader.Dispose();
......
......@@ -169,7 +169,7 @@ private T ReadRow<T>(Type type, Row row)
IsConsumed = true;
T result = default(T);
if(reader.Read() && reader.FieldCount != 0)
if (reader.Read() && reader.FieldCount != 0)
{
var typedIdentity = identity.ForGrid(type, gridIndex);
CacheInfo cache = GetCacheInfo(typedIdentity, null, addToCache);
......@@ -194,7 +194,7 @@ private T ReadRow<T>(Type type, Row row)
if ((row & Row.Single) != 0 && reader.Read()) ThrowMultipleRows(row);
while (reader.Read()) { /* ignore subsequent rows */ }
}
else if((row & Row.FirstOrDefault) == 0) // demanding a row, and don't have one
else if ((row & Row.FirstOrDefault) == 0) // demanding a row, and don't have one
{
ThrowZeroRows(row);
}
......@@ -372,9 +372,12 @@ private IEnumerable<T> ReadDeferred<T>(int index, Func<IDataReader, object> dese
while (index == gridIndex && reader.Read())
{
object val = deserializer(reader);
if (val == null || val is T) {
if (val == null || val is T)
{
yield return (T)val;
} else {
}
else
{
yield return (T)Convert.ChangeType(val, convertToType, CultureInfo.InvariantCulture);
}
}
......
......@@ -327,7 +327,7 @@ public static void AddTypeHandlerImpl(Type type, ITypeHandler handler, bool clon
else
{
newCopy[type] = handler;
if(secondary != null) newCopy[secondary] = handler;
if (secondary != null) newCopy[secondary] = handler;
}
typeHandlers = newCopy;
}
......@@ -413,7 +413,7 @@ public static DbType LookupDbType(Type type, string name, bool demand, out IType
return DbType.Object;
}
#endif
if(demand)
if (demand)
throw new NotSupportedException($"The member {name} of type {type.FullName} cannot be used as a parameter value");
return DbType.Object;
}
......@@ -509,7 +509,7 @@ private static IEnumerable GetMultiExec(object param)
&& !(param is string
|| param is IEnumerable<KeyValuePair<string, object>>
|| param is IDynamicParameters)
) ? (IEnumerable) param : null;
) ? (IEnumerable)param : null;
}
private static int ExecuteImpl(this IDbConnection cnn, ref CommandDefinition command)
......@@ -520,7 +520,7 @@ private static int ExecuteImpl(this IDbConnection cnn, ref CommandDefinition com
CacheInfo info = null;
if (multiExec != null)
{
if((command.Flags & CommandFlags.Pipelined) != 0)
if ((command.Flags & CommandFlags.Pipelined) != 0)
{
// this includes all the code for concurrent/overlapped query
return ExecuteMultiImplAsync(cnn, command, multiExec).Result;
......@@ -553,7 +553,8 @@ private static int ExecuteImpl(this IDbConnection cnn, ref CommandDefinition com
}
}
command.OnCompleted();
} finally
}
finally
{
if (wasClosed) cnn.Close();
}
......@@ -1089,7 +1090,7 @@ private static IEnumerable<T> QueryImpl<T>(this IDbConnection cnn, CommandDefini
if (reader.FieldCount == 0) //https://code.google.com/p/dapper-dot-net/issues/detail?id=57
yield break;
tuple = info.Deserializer = new DeserializerState(hash, GetDeserializer(effectiveType, reader, 0, -1, false));
if(command.AddToCache) SetQueryCache(identity, info);
if (command.AddToCache) SetQueryCache(identity, info);
}
var func = tuple.Func;
......@@ -1097,9 +1098,12 @@ private static IEnumerable<T> QueryImpl<T>(this IDbConnection cnn, CommandDefini
while (reader.Read())
{
object val = func(reader);
if (val == null || val is T) {
if (val == null || val is T)
{
yield return (T)val;
} else {
}
else
{
yield return (T)Convert.ChangeType(val, convertToType, CultureInfo.InvariantCulture);
}
}
......@@ -1425,10 +1429,10 @@ public static IEnumerable<TReturn> Query<TReturn>(this IDbConnection cnn, string
int hash = GetColumnHash(reader);
if ((deserializer = cinfo.Deserializer).Func == null || (otherDeserializers = cinfo.OtherDeserializers) == null || hash != deserializer.Hash)
{
var deserializers = GenerateDeserializers(new [] { typeof(TFirst), typeof(TSecond), typeof(TThird), typeof(TFourth), typeof(TFifth), typeof(TSixth), typeof(TSeventh) }, splitOn, reader);
var deserializers = GenerateDeserializers(new[] { typeof(TFirst), typeof(TSecond), typeof(TThird), typeof(TFourth), typeof(TFifth), typeof(TSixth), typeof(TSeventh) }, splitOn, reader);
deserializer = cinfo.Deserializer = new DeserializerState(hash, deserializers[0]);
otherDeserializers = cinfo.OtherDeserializers = deserializers.Skip(1).ToArray();
if(command.AddToCache) SetQueryCache(identity, cinfo);
if (command.AddToCache) SetQueryCache(identity, cinfo);
}
Func<IDataReader, TReturn> mapIt = GenerateMapper<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh, TReturn>(deserializer.Func, otherDeserializers, map);
......@@ -1607,7 +1611,7 @@ private static IEnumerable<TReturn> MultiMapImpl<TReturn>(this IDbConnection cnn
for (var typeIdx = types.Length - 1; typeIdx >= 0; --typeIdx)
{
var type = types[typeIdx];
if (type == typeof (DontMap))
if (type == typeof(DontMap))
{
continue;
}
......@@ -1729,7 +1733,7 @@ private static void PassByPosition(IDbCommand cmd)
Dictionary<string, IDbDataParameter> parameters = new Dictionary<string, IDbDataParameter>(StringComparer.Ordinal);
foreach(IDbDataParameter param in cmd.Parameters)
foreach (IDbDataParameter param in cmd.Parameters)
{
if (!string.IsNullOrEmpty(param.ParameterName)) parameters[param.ParameterName] = param;
}
......@@ -1923,7 +1927,7 @@ public static IDbDataParameter FindOrAddParameter(IDataParameterCollection param
internal static int GetListPaddingExtraCount(int count)
{
switch(count)
switch (count)
{
case 0:
case 1:
......@@ -1995,7 +1999,7 @@ public static void PackListParameters(IDbCommand command, string namePrefix, obj
{
if (++count == 1) // first item: fetch some type info
{
if(item == null)
if (item == null)
{
throw new NotSupportedException("The first item in a list-expansion cannot be null");
}
......@@ -2042,7 +2046,7 @@ public static void PackListParameters(IDbCommand command, string namePrefix, obj
count++;
var padParam = command.CreateParameter();
padParam.ParameterName = namePrefix + count.ToString();
if(isString) padParam.Size = DbString.DefaultLength;
if (isString) padParam.Size = DbString.DefaultLength;
padParam.DbType = dbType;
padParam.Value = lastValue;
command.Parameters.Add(padParam);
......@@ -2050,7 +2054,7 @@ public static void PackListParameters(IDbCommand command, string namePrefix, obj
}
}
if(viaSplit)
if (viaSplit)
{
// already done
}
......@@ -2097,7 +2101,7 @@ public static void PackListParameters(IDbCommand command, string namePrefix, obj
else
{
var sb = GetStringBuilder().Append('(').Append(variableName);
if(!byPosition) sb.Append(1);
if (!byPosition) sb.Append(1);
for (int i = 2; i <= count; i++)
{
sb.Append(',').Append(variableName);
......@@ -2165,11 +2169,11 @@ private static bool TryStringSplit(ref IEnumerable list, int splitAt, string nam
string val;
using (var iter = typed.GetEnumerator())
{
if(iter.MoveNext())
if (iter.MoveNext())
{
var sb = GetStringBuilder();
append(sb, iter.Current);
while(iter.MoveNext())
while (iter.MoveNext())
{
append(sb.Append(','), iter.Current);
}
......@@ -2293,13 +2297,13 @@ public static string Format(object value)
return ((decimal)value).ToString(CultureInfo.InvariantCulture);
default:
var multiExec = GetMultiExec(value);
if(multiExec != null)
if (multiExec != null)
{
StringBuilder sb = null;
bool first = true;
foreach (object subval in multiExec)
{
if(first)
if (first)
{
sb = GetStringBuilder().Append('(');
first = false;
......@@ -2310,7 +2314,7 @@ public static string Format(object value)
}
sb.Append(Format(subval));
}
if(first)
if (first)
{
return "(select null where 1=0)";
}
......@@ -2346,10 +2350,10 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
var matches = literalTokens.Matches(sql);
var found = new HashSet<string>(StringComparer.Ordinal);
List<LiteralToken> list = new List<LiteralToken>(matches.Count);
foreach(Match match in matches)
foreach (Match match in matches)
{
string token = match.Value;
if(found.Add(match.Value))
if (found.Add(match.Value))
{
list.Add(new LiteralToken(token, match.Groups[1].Value));
}
......@@ -2372,13 +2376,13 @@ private static List<IMemberMap> GetValueTupleMembers(Type type, string[] names)
{
var fields = type.GetFields(BindingFlags.Public | BindingFlags.Instance);
var result = new List<IMemberMap>(names.Length);
for(int i = 0; i < names.Length; i++)
for (int i = 0; i < names.Length; i++)
{
FieldInfo field = null;
string name = "Item" + (i + 1).ToString(CultureInfo.InvariantCulture);
foreach(var test in fields)
foreach (var test in fields)
{
if(test.Name == name)
if (test.Name == name)
{
field = test;
break;
......@@ -2427,7 +2431,7 @@ private static List<IMemberMap> GetValueTupleMembers(Type type, string[] names)
var allTypeProps = type.GetProperties();
var propsList = new List<PropertyInfo>(allTypeProps.Length);
for(int i = 0; i < allTypeProps.Length; ++i)
for (int i = 0; i < allTypeProps.Length; ++i)
{
var p = allTypeProps[i];
if (p.GetIndexParameters().Length == 0)
......@@ -2451,14 +2455,15 @@ private static List<IMemberMap> GetValueTupleMembers(Type type, string[] names)
break;
}
}
if(ok)
if (ok)
{
// pre-sorted; the reflection gods have smiled upon us
props = propsList;
}
else { // might still all be accounted for; check the hard way
var positionByName = new Dictionary<string,int>(StringComparer.OrdinalIgnoreCase);
foreach(var param in ctorParams)
else
{ // might still all be accounted for; check the hard way
var positionByName = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
foreach (var param in ctorParams)
{
positionByName[param.Name] = param.Position;
}
......@@ -2478,12 +2483,12 @@ private static List<IMemberMap> GetValueTupleMembers(Type type, string[] names)
if (ok)
{
props = propsList.ToArray();
Array.Sort(positions, (PropertyInfo[]) props);
Array.Sort(positions, (PropertyInfo[])props);
}
}
}
}
if(props == null)
if (props == null)
{
propsList.Sort(new PropertyInfoByNameComparer());
props = propsList;
......@@ -2573,9 +2578,9 @@ private static List<IMemberMap> GetValueTupleMembers(Type type, string[] names)
var nullType = Nullable.GetUnderlyingType(propType);
bool callSanitize = false;
if((nullType ?? propType).IsEnum())
if ((nullType ?? propType).IsEnum())
{
if(nullType != null)
if (nullType != null)
{
// Nullable<SomeEnum>; we want to box as the underlying type; that's just *hard*; for
// simplicity, box as Nullable<SomeEnum> and call SanitizeParameterValue
......@@ -2609,7 +2614,8 @@ private static List<IMemberMap> GetValueTupleMembers(Type type, string[] names)
il.EmitCall(OpCodes.Call, typeof(SqlMapper).GetMethod(nameof(SanitizeParameterValue)), null);
// stack is [parameters] [[parameters]] [parameter] [parameter] [boxed-value]
}
} else
}
else
{
checkForNull = true; // if not a value-type, need to check
}
......@@ -2699,7 +2705,7 @@ private static List<IMemberMap> GetValueTupleMembers(Type type, string[] names)
// stack is currently [parameters]
il.Emit(OpCodes.Pop); // stack is now empty
if(literals.Count != 0 && propsList != null)
if (literals.Count != 0 && propsList != null)
{
il.Emit(OpCodes.Ldarg_0); // command
il.Emit(OpCodes.Ldarg_0); // command, command
......@@ -2712,13 +2718,13 @@ private static List<IMemberMap> GetValueTupleMembers(Type type, string[] names)
// find the best member, preferring case-sensitive
PropertyInfo exact = null, fallback = null;
string huntName = literal.Member;
for(int i = 0; i < propsList.Count; i++)
for (int i = 0; i < propsList.Count; i++)
{
string thisName = propsList[i].Name;
if(string.Equals(thisName, huntName, StringComparison.OrdinalIgnoreCase))
if (string.Equals(thisName, huntName, StringComparison.OrdinalIgnoreCase))
{
fallback = propsList[i];
if(string.Equals(thisName, huntName, StringComparison.Ordinal))
if (string.Equals(thisName, huntName, StringComparison.Ordinal))
{
exact = fallback;
break;
......@@ -2727,7 +2733,7 @@ private static List<IMemberMap> GetValueTupleMembers(Type type, string[] names)
}
var prop = exact ?? fallback;
if(prop != null)
if (prop != null)
{
il.Emit(OpCodes.Ldstr, literal.Token);
il.Emit(OpCodes.Ldloc_0); // command, sql, typed parameter
......@@ -2846,7 +2852,7 @@ private static T ExecuteScalarImpl<T>(IDbConnection cnn, ref CommandDefinition c
{
cmd = command.SetupCommand(cnn, paramReader);
if (wasClosed) cnn.Open();
result =cmd.ExecuteScalar();
result = cmd.ExecuteScalar();
command.OnCompleted();
}
finally
......@@ -2922,7 +2928,7 @@ private static IDataReader ExecuteReaderImpl(IDbConnection cnn, ref CommandDefin
return r =>
{
var val = r.GetValue(index);
if(val is float || val is double || val is decimal)
if (val is float || val is double || val is decimal)
{
val = Convert.ChangeType(val, Enum.GetUnderlyingType(effectiveType), CultureInfo.InvariantCulture);
}
......@@ -2995,7 +3001,7 @@ public static ITypeMap GetTypeMap(Type type)
if (map == null)
{
map = TypeMapProvider( type );
map = TypeMapProvider(type);
_typeMaps[type] = map;
}
}
......@@ -3119,9 +3125,9 @@ private static LocalBuilder GetTempLocal(ILGenerator il, ref Dictionary<Type, Lo
if (explicitConstr != null)
{
var consPs = explicitConstr.GetParameters();
foreach(var p in consPs)
foreach (var p in consPs)
{
if(!p.ParameterType.IsValueType())
if (!p.ParameterType.IsValueType())
{
il.Emit(OpCodes.Ldnull);
}
......@@ -3181,7 +3187,7 @@ private static LocalBuilder GetTempLocal(ILGenerator il, ref Dictionary<Type, Lo
il.Emit(OpCodes.Ldloc_1);// [target]
}
var members = IsValueTuple(type) ? GetValueTupleMembers(type, names) :((specializedConstructor != null
var members = IsValueTuple(type) ? GetValueTupleMembers(type, names) : ((specializedConstructor != null
? names.Select(n => typeMap.GetConstructorParameter(specializedConstructor, n))
: names.Select(n => typeMap.GetMember(n))).ToList());
......@@ -3229,7 +3235,7 @@ private static LocalBuilder GetTempLocal(ILGenerator il, ref Dictionary<Type, Lo
if (unboxType.IsEnum())
{
Type numericType = Enum.GetUnderlyingType(unboxType);
if(colType == typeof(string))
if (colType == typeof(string))
{
if (enumDeclareLocal == -1)
{
......@@ -3318,7 +3324,7 @@ private static LocalBuilder GetTempLocal(ILGenerator il, ref Dictionary<Type, Lo
il.Emit(OpCodes.Ldnull);
}
}
else if(applyNullSetting && (!memberType.IsValueType() || Nullable.GetUnderlyingType(memberType) != null))
else if (applyNullSetting && (!memberType.IsValueType() || Nullable.GetUnderlyingType(memberType) != null))
{
il.Emit(OpCodes.Pop); // stack is now [target][target]
// can load a null with this value
......@@ -3402,11 +3408,11 @@ private static LocalBuilder GetTempLocal(ILGenerator il, ref Dictionary<Type, Lo
private static void FlexibleConvertBoxedFromHeadOfStack(ILGenerator il, Type from, Type to, Type via)
{
MethodInfo op;
if(from == (via ?? to))
if (from == (via ?? to))
{
il.Emit(OpCodes.Unbox_Any, to); // stack is now [target][target][typed-value]
}
else if ((op = GetOperator(from,to)) != null)
else if ((op = GetOperator(from, to)) != null)
{
// this is handy for things like decimal <===> double
il.Emit(OpCodes.Unbox_Any, from); // stack is now [target][target][data-typed-value]
......
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