Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions Dapper.SqlBuilder/SqlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class SqlBuilder
private readonly Dictionary<string, Clauses> _data = new Dictionary<string, Clauses>();
private int _seq;

private class Clause
private sealed class Clause
{
public Clause(string sql, object? parameters, bool isInclusive)
{
Expand All @@ -23,7 +23,7 @@ public Clause(string sql, object? parameters, bool isInclusive)
public bool IsInclusive { get; }
}

private class Clauses : List<Clause>
private sealed class Clauses : List<Clause>
{
private readonly string _joiner, _prefix, _postfix;

Expand All @@ -36,11 +36,9 @@ public Clauses(string joiner, string prefix = "", string postfix = "")

public string ResolveClauses(DynamicParameters p)
{
foreach (var item in this)
{
p.AddDynamicParams(item.Parameters);
}
return this.Any(a => a.IsInclusive)
ForEach(item => p.AddDynamicParams(item.Parameters));

return Exists(a => a.IsInclusive)
? _prefix +
string.Join(_joiner,
this.Where(a => !a.IsInclusive)
Expand Down
24 changes: 12 additions & 12 deletions Dapper/DefaultTypeMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Dapper
/// </summary>
public sealed class DefaultTypeMap : SqlMapper.ITypeMap
{
private readonly List<FieldInfo> _fields;
private readonly FieldInfo[] _fields;
private readonly Type _type;

/// <summary>
Expand Down Expand Up @@ -42,7 +42,7 @@ internal static MethodInfo GetPropertySetterOrThrow(PropertyInfo propertyInfo, T
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance,
Type.DefaultBinder,
propertyInfo.PropertyType,
propertyInfo.GetIndexParameters().Select(p => p.ParameterType).ToArray(),
Array.ConvertAll(propertyInfo.GetIndexParameters(), p => p.ParameterType),
null)!.GetSetMethod(true);
}

Expand All @@ -54,9 +54,9 @@ internal static List<PropertyInfo> GetSettableProps(Type t)
.ToList();
}

internal static List<FieldInfo> GetSettableFields(Type t)
private static FieldInfo[] GetSettableFields(Type t)
{
return t.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).ToList();
return t.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
}

/// <summary>
Expand Down Expand Up @@ -156,20 +156,20 @@ public SqlMapper.IMemberMap GetConstructorParameter(ConstructorInfo constructor,

// preference order is:
// exact match over underscore match, exact case over wrong case, backing fields over regular fields, match-inc-underscores over match-exc-underscores
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));
var field = Array.Find(_fields, p => string.Equals(p.Name, columnName, StringComparison.Ordinal))
?? Array.Find(_fields, p => string.Equals(p.Name, backingFieldName, StringComparison.Ordinal))
?? Array.Find(_fields, p => string.Equals(p.Name, columnName, StringComparison.OrdinalIgnoreCase))
?? Array.Find(_fields, p => string.Equals(p.Name, backingFieldName, StringComparison.OrdinalIgnoreCase));

if (field is null && MatchNamesWithUnderscores)
{
var effectiveColumnName = columnName.Replace("_", "");
backingFieldName = "<" + effectiveColumnName + ">k__BackingField";

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));
field = Array.Find(_fields, p => string.Equals(p.Name, effectiveColumnName, StringComparison.Ordinal))
?? Array.Find(_fields, p => string.Equals(p.Name, backingFieldName, StringComparison.Ordinal))
?? Array.Find(_fields, p => string.Equals(p.Name, effectiveColumnName, StringComparison.OrdinalIgnoreCase))
?? Array.Find(_fields, p => string.Equals(p.Name, backingFieldName, StringComparison.OrdinalIgnoreCase));
}

if (field is not null)
Expand Down
14 changes: 2 additions & 12 deletions Dapper/DynamicParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ public void AddDynamicParams(object? param)
if (subDynamic.templates is not null)
{
templates ??= new List<object>();
foreach (var t in subDynamic.templates)
{
templates.Add(t);
}
templates.AddRange(subDynamic.templates);
}
}
else
Expand Down Expand Up @@ -212,14 +209,7 @@ protected void AddParameters(IDbCommand command, SqlMapper.Identity identity)
}

// Now that the parameters are added to the command, let's place our output callbacks
var tmp = outputCallbacks;
if (tmp is not null)
{
foreach (var generator in tmp)
{
generator();
}
}
outputCallbacks?.ForEach(generator => generator());
}

foreach (var param in parameters.Values)
Expand Down
2 changes: 1 addition & 1 deletion Dapper/FeatureSupport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Dapper
/// <summary>
/// Handles variances in features per DBMS
/// </summary>
internal class FeatureSupport
internal sealed class FeatureSupport
{
private static readonly FeatureSupport
Default = new FeatureSupport(false),
Expand Down
2 changes: 1 addition & 1 deletion Dapper/SqlMapper.CacheInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Dapper
{
public static partial class SqlMapper
{
private class CacheInfo
private sealed class CacheInfo
{
public DeserializerState Deserializer { get; set; }
public Func<DbDataReader, object>[]? OtherDeserializers { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion Dapper/SqlMapper.DontMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ public static partial class SqlMapper
/// <summary>
/// Dummy type for excluding from multi-map
/// </summary>
private class DontMap { /* hiding constructor */ }
private sealed class DontMap { /* hiding constructor */ }
}
}
2 changes: 1 addition & 1 deletion Dapper/SqlMapper.Link.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static partial class SqlMapper
/// </summary>
/// <typeparam name="TKey">The type to cache.</typeparam>
/// <typeparam name="TValue">The value type of the cache.</typeparam>
internal class Link<TKey, TValue> where TKey : class
internal sealed class Link<TKey, TValue> where TKey : class
{
public static void Clear(ref Link<TKey, TValue>? head) => Interlocked.Exchange(ref head, null);
public static bool TryGet(Link<TKey, TValue>? link, TKey key, [NotNullWhen(true)] out TValue? value)
Expand Down
2 changes: 1 addition & 1 deletion Dapper/SqlMapper.TypeDeserializerCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Dapper
{
public static partial class SqlMapper
{
private class TypeDeserializerCache
private sealed class TypeDeserializerCache
{
private TypeDeserializerCache(Type type)
{
Expand Down
8 changes: 4 additions & 4 deletions Dapper/SqlMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace Dapper
/// </summary>
public static partial class SqlMapper
{
private class PropertyInfoByNameComparer : IComparer<PropertyInfo>
private sealed class PropertyInfoByNameComparer : IComparer<PropertyInfo>
{
public int Compare(PropertyInfo? x, PropertyInfo? y) => string.CompareOrdinal(x?.Name, y?.Name);
}
Expand Down Expand Up @@ -3530,9 +3530,9 @@ private static void GenerateDeserializerFromMap(Type type, DbDataReader reader,
il.Emit(OpCodes.Ldloc, returnValueLocal); // [target]
}

var members = (specializedConstructor is not null
? names.Select(n => typeMap.GetConstructorParameter(specializedConstructor, n))
: names.Select(n => typeMap.GetMember(n))).ToList();
var members = Array.ConvertAll<string, IMemberMap?>(names, specializedConstructor is not null
? n => typeMap.GetConstructorParameter(specializedConstructor, n)
: n => typeMap.GetMember(n));

// stack is now [target]
bool first = true;
Expand Down
1 change: 0 additions & 1 deletion benchmarks/Dapper.Tests.Performance/Massive/Massive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ public virtual DbCommand CreateUpdateCommand(object o, object key)
var settings = (IDictionary<string, object>)expando;
var sbKeys = new StringBuilder();
const string stub = "UPDATE {0} SET {1} WHERE {2} = @{3}";
var args = new List<object>();
var result = CreateCommand(stub, null);
int counter = 0;
foreach (var item in settings)
Expand Down
9 changes: 4 additions & 5 deletions benchmarks/Dapper.Tests.Performance/PetaPoco/PetaPoco.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1020,10 +1020,9 @@ public string LastCommand
{
get
{
var sb = new StringBuilder();
if (_lastSql == null)
return "";
sb.Append(_lastSql);
var sb = new StringBuilder(_lastSql);
if (_lastArgs != null)
{
sb.Append("\r\n\r\n");
Expand All @@ -1038,14 +1037,14 @@ public string LastCommand

public static IMapper Mapper { get; set; }

internal class PocoColumn
internal sealed class PocoColumn
{
public string ColumnName;
public PropertyInfo PropertyInfo;
public bool ResultColumn;
}

internal class PocoData
internal sealed class PocoData
{
public static PocoData ForType(Type t)
{
Expand Down Expand Up @@ -1272,7 +1271,7 @@ public Func<IDataReader, T> GetFactory<T>(string key, bool ForceDateTimesToUtc,
// ShareableConnection represents either a shared connection used by a transaction,
// or a one-off connection if not in a transaction.
// Non-shared connections are disposed
private class ShareableConnection : IDisposable
private sealed class ShareableConnection : IDisposable
{
public ShareableConnection(Database db)
{
Expand Down