Skip to content

Commit

Permalink
#371 Standardize use of "new" expressions.
Browse files Browse the repository at this point in the history
  • Loading branch information
adamjstone committed Dec 2, 2020
1 parent f469981 commit d5655a8
Show file tree
Hide file tree
Showing 34 changed files with 49 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Copyright (c) RapidField LLC. Licensed under the MIT License. See LICENSE.txt in the project root for license information.
// =================================================================================================================================

using Microsoft.AspNetCore.Identity;
using RapidField.SolidInstruments.Command;
using RapidField.SolidInstruments.Core.ArgumentValidation;
using RapidField.SolidInstruments.Core.Concurrency;
Expand Down Expand Up @@ -71,7 +70,7 @@ protected override void Process(DomainModel model, IEnumerable<String> labels, G

if (identityUser is null)
{
identityUser = new IdentityUser()
identityUser = new()
{
AccessFailedCount = 0,
Email = model.EmailAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Copyright (c) RapidField LLC. Licensed under the MIT License. See LICENSE.txt in the project root for license information.
// =================================================================================================================================

using Microsoft.AspNetCore.Identity;
using RapidField.SolidInstruments.Command;
using RapidField.SolidInstruments.Core.ArgumentValidation;
using RapidField.SolidInstruments.Core.Concurrency;
Expand Down Expand Up @@ -71,7 +70,7 @@ protected override void Process(DomainModel model, IEnumerable<String> labels, G

if (identityRole is null)
{
identityRole = new IdentityRole()
identityRole = new()
{
Id = model.Identifier.ToString(),
Name = model.Name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Copyright (c) RapidField LLC. Licensed under the MIT License. See LICENSE.txt in the project root for license information.
// =================================================================================================================================

using Microsoft.AspNetCore.Identity;
using RapidField.SolidInstruments.Command;
using RapidField.SolidInstruments.Core.ArgumentValidation;
using RapidField.SolidInstruments.Core.Concurrency;
Expand Down Expand Up @@ -71,7 +70,7 @@ protected override void Process(DomainModel model, IEnumerable<String> labels, G

if (identityUserRole is null)
{
identityUserRole = new IdentityUserRole<String>()
identityUserRole = new()
{
RoleId = model.UserRoleIdentifier.ToString(),
UserId = model.UserIdentifier.ToString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public ICollection<UserRoleAssignmentModel> UserRoleAssignments
{
if (UserRoleAssignmentsList is null)
{
UserRoleAssignmentsList = new List<UserRoleAssignmentModel>();
UserRoleAssignmentsList = new();
}

return UserRoleAssignmentsList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using RapidField.SolidInstruments.Core.ArgumentValidation;
using System;
using System.Linq;
using UserRoleAssignmentModel = RapidField.SolidInstruments.Example.Domain.Models.UserRoleAssignment.DomainModel;
using UserRoleModel = RapidField.SolidInstruments.Example.Domain.Models.UserRole.DomainModel;

namespace RapidField.SolidInstruments.Example.Domain.Models.User
Expand Down Expand Up @@ -43,7 +42,7 @@ public void AssignRole(UserRoleModel userRole)
return;
}

UserRoleAssignments.Add(new UserRoleAssignmentModel(Guid.NewGuid())
UserRoleAssignments.Add(new(Guid.NewGuid())
{
User = this,
UserRole = userRole
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public ICollection<UserRoleAssignmentModel> UserRoleAssignments
{
if (UserRoleAssignmentsList is null)
{
UserRoleAssignmentsList = new List<UserRoleAssignmentModel>();
UserRoleAssignmentsList = new();
}

return UserRoleAssignmentsList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public void Reset()
{
lock (SyncRoot)
{
CalculatedTerms = new List<T>(CalculatedTerms.Take(SeedTermCount));
CalculatedTerms = new(CalculatedTerms.Take(SeedTermCount));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public PinnedMemory(T[] field, Boolean overwriteWithZerosOnDispose)
/// <param name="target">
/// The object to cast from.
/// </param>
public static implicit operator PinnedMemory<T>(T[] target) => target is null ? null : new PinnedMemory<T>(target);
public static implicit operator PinnedMemory<T>(T[] target) => target is null ? null : new(target);

/// <summary>
/// Facilitates implicit <see cref="PinnedMemory{T}" /> to <see cref="ReadOnlySpan{T}" /> casting.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public ReadOnlyPinnedMemory(T[] field)
/// <param name="target">
/// The object to cast from.
/// </param>
public static implicit operator ReadOnlyPinnedMemory<T>(T[] target) => target is null ? null : new ReadOnlyPinnedMemory<T>(target);
public static implicit operator ReadOnlyPinnedMemory<T>(T[] target) => target is null ? null : new(target);

/// <summary>
/// Facilitates implicit <see cref="ReadOnlyPinnedMemory{T}" /> to <see cref="ReadOnlySpan{T}" /> casting.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static class LazyExtensions
public static void Dispose<T>(this Lazy<T> target)
where T : IDisposable
{
if ((target?.IsValueCreated).GetValueOrDefault(false))
if (target?.IsValueCreated ?? false)
{
target.Value.Dispose();
}
Expand All @@ -36,7 +36,7 @@ public static void Dispose<T>(this Lazy<T> target)
public static Task DisposeAsync<T>(this Lazy<T> target)
where T : IAsyncDisposable
{
if ((target?.IsValueCreated).GetValueOrDefault(false))
if (target?.IsValueCreated ?? false)
{
return target.Value.DisposeAsync().AsTask();
}
Expand Down
2 changes: 1 addition & 1 deletion src/RapidField.SolidInstruments.Core/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ private static void HydrateModel(IModel sourceModel, IModel targetModel, MappedM
var targetModelType = targetModel.RejectIf().IsNull(nameof(targetModel)).TargetArgument.GetType();
var sourceModelProperties = sourceModelType.GetProperties(PropertyBindingFlags).ToDictionary(property => property.Name, property => property);
var targetModelProperties = targetModelType.GetProperties(PropertyBindingFlags).ToDictionary(property => property.Name, property => property);
mappedModels.RejectIf().IsNull(nameof(mappedModels)).TargetArgument.AddModelPair(new MappedModel(sourceModel, targetModel));
mappedModels.RejectIf().IsNull(nameof(mappedModels)).TargetArgument.AddModelPair(new(sourceModel, targetModel));

foreach (var sourcePropertyElement in sourceModelProperties)
{
Expand Down
2 changes: 1 addition & 1 deletion src/RapidField.SolidInstruments.Core/ReferenceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ private T Target
set
{
StrongReference = value;
WeakReference = value is null ? null : new WeakReference(value);
WeakReference = value is null ? null : new(value);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ private Rfc2898DeriveBytes InitializePbkdf2Algorithm()
iterationCount += iterationSumValue;
}

algorithm = new Rfc2898DeriveBytes(passwordBytes.ToArray(), saltBytes.ToArray(), iterationCount);
algorithm = new(passwordBytes.ToArray(), saltBytes.ToArray(), iterationCount);
});

return algorithm;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2207,7 +2207,7 @@ private static void GenerateUInt64(RandomNumberGenerator target, out UInt64 rand
[DebuggerHidden]
private static void GenerateUInt64(RandomNumberGenerator target, UInt64 floor, UInt64 ceiling, out UInt64 randomValue)
{
var range = BigInteger.Subtract(new BigInteger(ceiling), new BigInteger(floor));
var range = BigInteger.Subtract(new(ceiling), new(floor));
GenerateRangePosition(target, (Decimal)range, out var rangePosition);
randomValue = Convert.ToUInt64(floor + rangePosition.RoundedTo(0));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ private Byte[] CalculateHash(Byte[] firstHashValue, Byte[] secondHashValue)
/// The new node.
/// </returns>
[DebuggerHidden]
private HashTreeNode CreateNode(HashTreeNode leftChild, HashTreeNode rightChild) => new HashTreeNode(CalculateHash(leftChild.Value, rightChild.Value), leftChild, rightChild);
private HashTreeNode CreateNode(HashTreeNode leftChild, HashTreeNode rightChild) => new(CalculateHash(leftChild.Value, rightChild.Value), leftChild, rightChild);

/// <summary>
/// Processes the specified row in the tree recursively toward the root node.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ internal ExportedSecretVault(String identifier, IEnumerable<ExportedSecret> secr
: base()
{
Identifier = identifier.RejectIf().IsNullOrEmpty(nameof(identifier));
Secrets = new List<ExportedSecret>(secrets.RejectIf().IsNull(nameof(secrets)).OrIf(collection => collection.Any(secret => secret is null), nameof(secrets), "The specified secret collection contains one or more null elements.").TargetArgument);
Secrets = new(secrets.RejectIf().IsNull(nameof(secrets)).OrIf(collection => collection.Any(secret => secret is null), nameof(secrets), "The specified secret collection contains one or more null elements.").TargetArgument);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1223,14 +1223,14 @@ private static async Task<EncryptedExportedSecret> ExportEncryptedSecretAsync(Ex
{
await ((SymmetricKeySecret)keySecret).ReadAsync((SymmetricKey key) =>
{
encryptedExportedSecret = new EncryptedExportedSecret(exportedSecret, key, keyName);
encryptedExportedSecret = new(exportedSecret, key, keyName);
}).ConfigureAwait(false);
}
else if (keySecret.ValueType == typeof(CascadingSymmetricKey))
{
await ((CascadingSymmetricKeySecret)keySecret).ReadAsync((CascadingSymmetricKey key) =>
{
encryptedExportedSecret = new EncryptedExportedSecret(exportedSecret, key, keyName);
encryptedExportedSecret = new(exportedSecret, key, keyName);
}).ConfigureAwait(false);
}

Expand Down Expand Up @@ -1262,14 +1262,14 @@ private static async Task<EncryptedExportedSecretVault> ExportEncryptedSecretVau
{
await ((SymmetricKeySecret)keySecret).ReadAsync((SymmetricKey key) =>
{
encryptedExportedSecretVault = new EncryptedExportedSecretVault(exportedSecretVault, key, keyName);
encryptedExportedSecretVault = new(exportedSecretVault, key, keyName);
}).ConfigureAwait(false);
}
else if (keySecret.ValueType == typeof(CascadingSymmetricKey))
{
await ((CascadingSymmetricKeySecret)keySecret).ReadAsync((CascadingSymmetricKey key) =>
{
encryptedExportedSecretVault = new EncryptedExportedSecretVault(exportedSecretVault, key, keyName);
encryptedExportedSecretVault = new(exportedSecretVault, key, keyName);
}).ConfigureAwait(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,6 @@ internal static AutofacDependencyEngine New<TPackage>(IConfiguration application
/// <returns>
/// A new service injector.
/// </returns>
protected override AutofacServiceInjector CreateServiceInjector(IServiceCollection serviceDescriptors) => new AutofacServiceInjector(serviceDescriptors);
protected override AutofacServiceInjector CreateServiceInjector(IServiceCollection serviceDescriptors) => new(serviceDescriptors);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ protected AutofacDependencyPackage()
/// <paramref name="applicationConfiguration" /> is <see langword="null" /> -or- <paramref name="package" /> is
/// <see langword="null" /> -or- <paramref name="serviceDescriptors" /> is <see langword="null" /> .
/// </exception>
protected sealed override AutofacDependencyEngine CreateEngine(IConfiguration applicationConfiguration, IServiceCollection serviceDescriptors, IDependencyPackage<ContainerBuilder> package) => new AutofacDependencyEngine(applicationConfiguration, package, serviceDescriptors);
protected sealed override AutofacDependencyEngine CreateEngine(IConfiguration applicationConfiguration, IServiceCollection serviceDescriptors, IDependencyPackage<ContainerBuilder> package) => new(applicationConfiguration, package, serviceDescriptors);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,6 @@ internal static DotNetNativeDependencyEngine New<TPackage>(IConfiguration applic
/// <returns>
/// A new service injector.
/// </returns>
protected override DotNetNativeServiceInjector CreateServiceInjector(IServiceCollection serviceDescriptors) => new DotNetNativeServiceInjector(serviceDescriptors);
protected override DotNetNativeServiceInjector CreateServiceInjector(IServiceCollection serviceDescriptors) => new(serviceDescriptors);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ protected DotNetNativeDependencyPackage()
/// <paramref name="applicationConfiguration" /> is <see langword="null" /> -or- <paramref name="package" /> is
/// <see langword="null" /> -or- <paramref name="serviceDescriptors" /> is <see langword="null" /> .
/// </exception>
protected sealed override DotNetNativeDependencyEngine CreateEngine(IConfiguration applicationConfiguration, IServiceCollection serviceDescriptors, IDependencyPackage<ServiceCollection> package) => new DotNetNativeDependencyEngine(applicationConfiguration, package, serviceDescriptors);
protected sealed override DotNetNativeDependencyEngine CreateEngine(IConfiguration applicationConfiguration, IServiceCollection serviceDescriptors, IDependencyPackage<ServiceCollection> package) => new(applicationConfiguration, package, serviceDescriptors);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1666,12 +1666,12 @@ private static Int32[] DetermineMedianIndices(Int32 elementCount)
else if (elementCount.IsOdd())
{
// Return the index at the midpoint.
return new Int32[] { Convert.ToInt32(Math.Round((Single)(elementCount / 2), 0, MidpointRounding.AwayFromZero)) };
return new[] { Convert.ToInt32(Math.Round((Single)(elementCount / 2), 0, MidpointRounding.AwayFromZero)) };
}

// Return the pair of indices sharing the midpoint.
var firstIndex = (elementCount / 2) - 1;
return new Int32[] { firstIndex, firstIndex + 1 };
return new[] { firstIndex, firstIndex + 1 };
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public abstract class CommandMessage<TCommand> : Message, ICommandMessage<TComma
/// Initializes a new instance of the <see cref="CommandMessage{TCommand}" /> class.
/// </summary>
protected CommandMessage()
: this(new TCommand())
: this(new())
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public MessageProcessingInformation()
/// </exception>
public MessageProcessingInformation(MessageListeningFailurePolicy failurePolicy)
{
AttemptResults = new List<MessageProcessingAttemptResult>();
AttemptResults = new();
FailurePolicy = failurePolicy.RejectIf().IsNull(nameof(failurePolicy));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void RegisterQueueHandler(IMessagingEntityPath queuePath, Action<Primitiv

if (Transport.QueueExists(queuePath))
{
Handlers.Add(new Handler(queuePath, MessagingEntityType.Queue, null, handleMessageAction));
Handlers.Add(new(queuePath, MessagingEntityType.Queue, null, handleMessageAction));
BeginPolling();
return;
}
Expand Down Expand Up @@ -134,7 +134,7 @@ public void RegisterSubscriptionHandler(IMessagingEntityPath topicPath, String s

if (Transport.SubscriptionExists(topicPath, subscriptionName))
{
Handlers.Add(new Handler(topicPath, MessagingEntityType.Topic, subscriptionName, handleMessageAction));
Handlers.Add(new(topicPath, MessagingEntityType.Topic, subscriptionName, handleMessageAction));
BeginPolling();
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public IObjectContainerBuilder Configure<TRequest, TProduct>(Func<TProduct> prod
throw new ArgumentException($"The builder is already configured for the request-product type pair: {requestType.FullName}, {productType.FullName}.", nameof(TProduct));
}

DefinitionConfigurationActions.Add(definitionKey, new Action<IObjectContainerConfigurationDefinitions>((definitions) =>
DefinitionConfigurationActions.Add(definitionKey, new((definitions) =>
{
definitions.Add<TRequest, TProduct>();
}));
Expand All @@ -138,7 +138,7 @@ public IObjectContainerBuilder Configure<TRequest, TProduct>(Func<TProduct> prod
return this;
}

FunctionConfigurationActions.Add(definitionKey, new Action<IObjectFactoryConfigurationProductionFunctions>((functions) =>
FunctionConfigurationActions.Add(definitionKey, new((functions) =>
{
functions.Add(productionFunction);
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public DynamicSerializer(SerializationFormat format)
/// An XML serializer.
/// </returns>
[DebuggerHidden]
private static DataContractJsonSerializer InitializeJsonSerializer() => new DataContractJsonSerializer(ContractType, JsonSerializerSettings);
private static DataContractJsonSerializer InitializeJsonSerializer() => new(ContractType, JsonSerializerSettings);

/// <summary>
/// Initializes an XML serializer.
Expand All @@ -158,7 +158,7 @@ public DynamicSerializer(SerializationFormat format)
/// An XML serializer.
/// </returns>
[DebuggerHidden]
private static DataContractSerializer InitializeXmlSerializer() => new DataContractSerializer(ContractType, XmlSerializerSettings);
private static DataContractSerializer InitializeXmlSerializer() => new(ContractType, XmlSerializerSettings);

/// <summary>
/// Converts the specified JSON bit field to its typed equivalent.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,6 @@ public Boolean IsAlive
/// Represents an event that can be triggered to signal the end of an associated service's lifetime.
/// </summary>
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly ManualResetEvent EndOfLifeEvent = new ManualResetEvent(false);
private readonly ManualResetEvent EndOfLifeEvent = new(false);
}
}
Loading

0 comments on commit d5655a8

Please sign in to comment.