Skip to content

Commit

Permalink
Use target-typed new (#23871)
Browse files Browse the repository at this point in the history
  • Loading branch information
roji authored Jan 14, 2021
1 parent eba7d1f commit da00fb6
Show file tree
Hide file tree
Showing 465 changed files with 1,366 additions and 1,522 deletions.
2 changes: 1 addition & 1 deletion src/EFCore.Analyzers/InternalUsageDiagnosticAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public const string MessageFormat
private static readonly int EFLen = "EntityFrameworkCore".Length;

private static readonly DiagnosticDescriptor _descriptor
= new DiagnosticDescriptor(
= new(
Id,
title: DefaultTitle,
messageFormat: MessageFormat,
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore.Cosmos/Diagnostics/CosmosEventId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private enum Id
/// </para>
/// </summary>
public static readonly EventId ExecutingSqlQuery
= new EventId((int)Id.ExecutingSqlQuery, _commandPrefix + Id.ExecutingSqlQuery);
= new((int)Id.ExecutingSqlQuery, _commandPrefix + Id.ExecutingSqlQuery);

/// <summary>
/// <para>
Expand All @@ -54,6 +54,6 @@ public static readonly EventId ExecutingSqlQuery
/// </para>
/// </summary>
public static readonly EventId ExecutingReadItem
= new EventId((int)Id.ExecutingReadItem, _commandPrefix + Id.ExecutingReadItem);
= new((int)Id.ExecutingReadItem, _commandPrefix + Id.ExecutingReadItem);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ public virtual CosmosOptionsExtension WithExecutionStrategyFactory(
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
protected virtual CosmosOptionsExtension Clone()
=> new CosmosOptionsExtension(this);
=> new(this);

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Internal
/// </summary>
public class CosmosMemberTranslatorProvider : IMemberTranslatorProvider
{
private readonly List<IMemberTranslator> _plugins = new List<IMemberTranslator>();
private readonly List<IMemberTranslator> _translators = new List<IMemberTranslator>();
private readonly List<IMemberTranslator> _plugins = new();
private readonly List<IMemberTranslator> _translators = new();

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Internal
/// </summary>
public class CosmosMethodCallTranslatorProvider : IMethodCallTranslatorProvider
{
private readonly List<IMethodCallTranslator> _plugins = new List<IMethodCallTranslator>();
private readonly List<IMethodCallTranslator> _translators = new List<IMethodCallTranslator>();
private readonly List<IMethodCallTranslator> _plugins = new();
private readonly List<IMethodCallTranslator> _translators = new();

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ private static readonly MethodInfo _getParameterValueMethodInfo
private readonly IDictionary<ProjectionMember, Expression> _projectionMapping
= new Dictionary<ProjectionMember, Expression>();

private readonly Stack<ProjectionMember> _projectionMembers = new Stack<ProjectionMember>();
private readonly Stack<ProjectionMember> _projectionMembers = new();

private readonly IDictionary<ParameterExpression, CollectionShaperExpression> _collectionShaperMapping
= new Dictionary<ParameterExpression, CollectionShaperExpression>();

private readonly Stack<INavigation> _includedNavigations
= new Stack<INavigation>();
= new();

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ protected override ShapedQueryExpression CreateShapedQueryExpression(IEntityType
}

private ShapedQueryExpression CreateShapedQueryExpression(Expression queryExpression, IEntityType entityType)
=> new ShapedQueryExpression(
=> new(
queryExpression,
new EntityShaperExpression(
entityType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private readonly IDictionary<Expression, Expression> _ordinalParameterBindings
= new Dictionary<Expression, Expression>();

private List<IncludeExpression> _pendingIncludes
= new List<IncludeExpression>();
= new();

private static readonly MethodInfo _toObjectMethodInfo
= typeof(CosmosProjectionBindingRemovingExpressionVisitorBase)
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Cosmos/Query/Internal/InExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected override Expression VisitChildren(ExpressionVisitor visitor)
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual InExpression Negate()
=> new InExpression(Item, !IsNegated, Values, TypeMapping!);
=> new(Item, !IsNegated, Values, TypeMapping!);

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Cosmos/Query/Internal/QuerySqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Internal
/// </summary>
public class QuerySqlGenerator : SqlExpressionVisitor
{
private readonly StringBuilder _sqlBuilder = new StringBuilder();
private readonly StringBuilder _sqlBuilder = new();
private IReadOnlyDictionary<string, object> _parameterValues;
private List<SqlParameter> _sqlParameters;
private bool _useValueProjection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public class QuerySqlGeneratorFactory : IQuerySqlGeneratorFactory
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual QuerySqlGenerator Create()
=> new QuerySqlGenerator();
=> new();
}
}
4 changes: 2 additions & 2 deletions src/EFCore.Cosmos/Query/Internal/SelectExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public class SelectExpression : Expression
private const string RootAlias = "c";

private IDictionary<ProjectionMember, Expression> _projectionMapping = new Dictionary<ProjectionMember, Expression>();
private readonly List<ProjectionExpression> _projection = new List<ProjectionExpression>();
private readonly List<OrderingExpression> _orderings = new List<OrderingExpression>();
private readonly List<ProjectionExpression> _projection = new();
private readonly List<OrderingExpression> _orderings = new();

private ValueConverter _partitionKeyValueConverter;
private Expression _partitionKeyValue;
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Cosmos/Query/Internal/SqlExpressionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ public virtual InExpression In(SqlExpression item, SqlExpression values, bool ne
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual SqlConstantExpression Constant(object value, CoreTypeMapping typeMapping = null)
=> new SqlConstantExpression(Expression.Constant(value), typeMapping);
=> new(Expression.Constant(value), typeMapping);

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
6 changes: 1 addition & 5 deletions src/EFCore.Cosmos/Query/Internal/SqlFunctionExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,7 @@ protected override Expression VisitChildren(ExpressionVisitor visitor)
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual SqlFunctionExpression ApplyTypeMapping([CanBeNull] CoreTypeMapping? typeMapping)
=> new SqlFunctionExpression(
Name,
Arguments,
Type,
typeMapping ?? TypeMapping);
=> new(Name, Arguments, Type, typeMapping ?? TypeMapping);

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
6 changes: 3 additions & 3 deletions src/EFCore.Cosmos/Storage/Internal/CosmosConcurrencyToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private CosmosConcurrencyToken(string value, CosmosConcurrencyMode mode)
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public static CosmosConcurrencyToken None { get; } = new CosmosConcurrencyToken(null, CosmosConcurrencyMode.None);
public static CosmosConcurrencyToken None { get; } = new(null, CosmosConcurrencyMode.None);

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand All @@ -50,7 +50,7 @@ private CosmosConcurrencyToken(string value, CosmosConcurrencyMode mode)
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public static CosmosConcurrencyToken IfMatch([CanBeNull] string value)
=> new CosmosConcurrencyToken(value, CosmosConcurrencyMode.IfMatch);
=> new(value, CosmosConcurrencyMode.IfMatch);

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand All @@ -59,6 +59,6 @@ public static CosmosConcurrencyToken IfMatch([CanBeNull] string value)
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public static CosmosConcurrencyToken IfNotMatch([CanBeNull] string value)
=> new CosmosConcurrencyToken(value, CosmosConcurrencyMode.IfNoneMatch);
=> new(value, CosmosConcurrencyMode.IfNoneMatch);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ private void GenerateComment(string comment)
private sealed class AttributeWriter
{
private readonly string _attributeName;
private readonly List<string> _parameters = new List<string>();
private readonly List<string> _parameters = new();

public AttributeWriter([NotNull] string attributeName)
{
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Design/Scaffolding/Internal/CSharpNamer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class CSharpNamer<T>
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
protected readonly Dictionary<T, string> NameCache = new Dictionary<T, string>();
protected readonly Dictionary<T, string> NameCache = new();

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
/// </summary>
public class CSharpUniqueNamer<T> : CSharpNamer<T>
{
private readonly HashSet<string> _usedNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
private readonly HashSet<string> _usedNames = new(StringComparer.OrdinalIgnoreCase);

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore.Design/Scaffolding/Internal/CSharpUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal
/// </summary>
public class CSharpUtilities : ICSharpUtilities
{
private static readonly HashSet<string> _cSharpKeywords = new HashSet<string>
private static readonly HashSet<string> _cSharpKeywords = new()
{
"abstract",
"as",
Expand Down Expand Up @@ -100,7 +100,7 @@ public class CSharpUtilities : ICSharpUtilities
};

private static readonly Regex _invalidCharsRegex
= new Regex(
= new(
@"[^\p{Ll}\p{Lu}\p{Lt}\p{Lo}\p{Nd}\p{Nl}\p{Mn}\p{Mc}\p{Cf}\p{Pc}\p{Lm}]",
default,
TimeSpan.FromMilliseconds(1000.0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ public class RelationalScaffoldingModelFactory : IScaffoldingModelFactory
private readonly ICandidateNamingService _candidateNamingService;
private Dictionary<DatabaseTable, CSharpUniqueNamer<DatabaseColumn>> _columnNamers;
private ModelReverseEngineerOptions _options;
private readonly DatabaseTable _nullTable = new DatabaseTable();
private readonly DatabaseTable _nullTable = new();
private CSharpUniqueNamer<DatabaseTable> _tableNamer;
private CSharpUniqueNamer<DatabaseTable> _dbSetNamer;
private readonly HashSet<DatabaseColumn> _unmappedColumns = new HashSet<DatabaseColumn>();
private readonly HashSet<DatabaseColumn> _unmappedColumns = new();
private readonly IPluralizer _pluralizer;
private readonly ICSharpUtilities _cSharpUtilities;
private readonly IScaffoldingTypeMapper _scaffoldingTypeMapper;
Expand Down Expand Up @@ -929,7 +929,7 @@ protected virtual void AddNavigationProperties([NotNull] IMutableForeignKey fore

// Stores the names of the EntityType itself and its Properties, but does not include any Navigation Properties
private readonly Dictionary<IEntityType, List<string>> _entityTypeAndPropertyIdentifiers =
new Dictionary<IEntityType, List<string>>();
new();

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore.InMemory/Diagnostics/InMemoryEventId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private enum Id
private static readonly string _transactionPrefix = DbLoggerCategory.Database.Transaction.Name + ".";

private static EventId MakeTransactionId(Id id)
=> new EventId((int)id, _transactionPrefix + id);
=> new((int)id, _transactionPrefix + id);

/// <summary>
/// <para>
Expand All @@ -51,7 +51,7 @@ private static EventId MakeTransactionId(Id id)
private static readonly string _updatePrefix = DbLoggerCategory.Update.Name + ".";

private static EventId MakeUpdateId(Id id)
=> new EventId((int)id, _updatePrefix + id);
=> new((int)id, _updatePrefix + id);

/// <summary>
/// <para>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public virtual DbContextOptionsExtensionInfo Info
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
protected virtual InMemoryOptionsExtension Clone()
=> new InMemoryOptionsExtension(this);
=> new(this);

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class InMemoryProjectionBindingExpressionVisitor : ExpressionVisitor
private readonly IDictionary<ProjectionMember, Expression> _projectionMapping
= new Dictionary<ProjectionMember, Expression>();

private readonly Stack<ProjectionMember> _projectionMembers = new Stack<ProjectionMember>();
private readonly Stack<ProjectionMember> _projectionMembers = new();

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down Expand Up @@ -502,7 +502,7 @@ private CollectionShaperExpression AddCollectionProjection(
ShapedQueryExpression subquery,
INavigationBase? navigation,
Type elementType)
=> new CollectionShaperExpression(
=> new(
new ProjectionBindingExpression(
_queryExpression,
_queryExpression.AddSubqueryProjection(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private static readonly ConstructorInfo _valueBufferConstructor
private static readonly PropertyInfo _valueBufferCountMemberInfo
= typeof(ValueBuffer).GetRequiredProperty(nameof(ValueBuffer.Count));

private readonly List<Expression> _valueBufferSlots = new List<Expression>();
private readonly List<Expression> _valueBufferSlots = new();

private readonly IDictionary<EntityProjectionExpression, IDictionary<IProperty, int>> _entityProjectionCache
= new Dictionary<EntityProjectionExpression, IDictionary<IProperty, int>>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public class ShaperExpressionProcessingExpressionVisitor : ExpressionVisitor
private readonly ParameterExpression _valueBufferParameter;

private readonly IDictionary<Expression, ParameterExpression> _mapping = new Dictionary<Expression, ParameterExpression>();
private readonly List<ParameterExpression> _variables = new List<ParameterExpression>();
private readonly List<Expression> _expressions = new List<Expression>();
private readonly List<ParameterExpression> _variables = new();
private readonly List<Expression> _expressions = new();

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore.InMemory/Storage/Internal/InMemoryStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class InMemoryStore : IInMemoryStore
private readonly IInMemoryTableFactory _tableFactory;
private readonly bool _useNameMatching;

private readonly object _lock = new object();
private readonly object _lock = new();

private Dictionary<object, IInMemoryTable> _tables;

Expand Down Expand Up @@ -120,7 +120,7 @@ public virtual bool Clear()
}

private static Dictionary<object, IInMemoryTable> CreateTables()
=> new Dictionary<object, IInMemoryTable>();
=> new();

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class InMemoryTableFactory : IInMemoryTableFactory
private readonly bool _nullabilityCheckEnabled;

private readonly ConcurrentDictionary<(IEntityType EntityType, IInMemoryTable BaseTable), Func<IInMemoryTable>> _factories
= new ConcurrentDictionary<(IEntityType, IInMemoryTable), Func<IInMemoryTable>>();
= new();

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace Microsoft.EntityFrameworkCore.InMemory.Storage.Internal
/// </summary>
public class InMemoryTransactionManager : IDbContextTransactionManager, ITransactionEnlistmentManager
{
private static readonly InMemoryTransaction _stubTransaction = new InMemoryTransaction();
private static readonly InMemoryTransaction _stubTransaction = new();

private readonly IDiagnosticsLogger<DbLoggerCategory.Database.Transaction> _logger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public virtual DbContextOptionsExtensionInfo Info
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
protected virtual ProxiesOptionsExtension Clone()
=> new ProxiesOptionsExtension(this);
=> new(this);

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Proxies/Proxies/Internal/ProxyFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class ProxyFactory : IProxyFactory
private static readonly Type _notifyPropertyChangedInterface = typeof(INotifyPropertyChanged);
private static readonly Type _notifyPropertyChangingInterface = typeof(INotifyPropertyChanging);

private readonly ProxyGenerator _generator = new ProxyGenerator();
private readonly ProxyGenerator _generator = new();

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
5 changes: 1 addition & 4 deletions src/EFCore.Relational/Design/MethodCallCodeFragment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ public virtual MethodCallCodeFragment Chain([NotNull] string method, [NotNull] p
/// <param name="call"> The next method. </param>
/// <returns> A new fragment representing the method chain. </returns>
public virtual MethodCallCodeFragment Chain([NotNull] MethodCallCodeFragment call)
=> new MethodCallCodeFragment(
Method,
_arguments.ToArray(),
ChainedCall?.Chain(call) ?? call);
=> new(Method, _arguments.ToArray(), ChainedCall?.Chain(call) ?? call);
}
}
Loading

0 comments on commit da00fb6

Please sign in to comment.