Skip to content

Commit

Permalink
#371 Standardize use of "new" expression.
Browse files Browse the repository at this point in the history
  • Loading branch information
adamjstone committed Dec 1, 2020
1 parent aeebee4 commit f469981
Show file tree
Hide file tree
Showing 125 changed files with 359 additions and 362 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static class Named
/// <returns>
/// A collection of all known <see cref="DomainModel" /> instances.
/// </returns>
public static IEnumerable<DomainModel> All() => new DomainModel[]
public static IEnumerable<DomainModel> All() => new[]
{
StevenCallahan,
TomSmith
Expand Down Expand Up @@ -71,7 +71,7 @@ private static String GetPasswordHash(String plaintextPassword)
/// <summary>
/// Gets the Steven Callahan user.
/// </summary>
public static DomainModel StevenCallahan => new DomainModel(Guid.Parse("a04fc5b0-1a67-43ff-89af-750128398d8a"))
public static DomainModel StevenCallahan => new(Guid.Parse("a04fc5b0-1a67-43ff-89af-750128398d8a"))
{
EmailAddress = "[email protected]",
Name = nameof(StevenCallahan),
Expand All @@ -81,7 +81,7 @@ private static String GetPasswordHash(String plaintextPassword)
/// <summary>
/// Gets the Tom Smith user.
/// </summary>
public static DomainModel TomSmith => new DomainModel(Guid.Parse("3d46470a-1c90-4e94-bc5c-3cbde44ba6ac"))
public static DomainModel TomSmith => new(Guid.Parse("3d46470a-1c90-4e94-bc5c-3cbde44ba6ac"))
{
EmailAddress = "[email protected]",
Name = nameof(TomSmith),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static class Named
/// <returns>
/// A collection of all known <see cref="DomainModel" /> instances.
/// </returns>
public static IEnumerable<DomainModel> All() => new DomainModel[]
public static IEnumerable<DomainModel> All() => new[]
{
EndUser,
SystemAdministrator
Expand All @@ -46,7 +46,7 @@ public static class Named
/// <summary>
/// Gets the end user role.
/// </summary>
public static DomainModel EndUser => new DomainModel(Guid.Parse("816e7126-2034-49b3-af08-d07cab150d93"))
public static DomainModel EndUser => new(Guid.Parse("816e7126-2034-49b3-af08-d07cab150d93"))
{
Description = "A standard end user.",
Name = nameof(EndUser)
Expand All @@ -55,7 +55,7 @@ public static class Named
/// <summary>
/// Gets the system administrator user role.
/// </summary>
public static DomainModel SystemAdministrator => new DomainModel(Guid.Parse("b13c7a39-0c65-4515-a4af-2e3f60d289ba"))
public static DomainModel SystemAdministrator => new(Guid.Parse("b13c7a39-0c65-4515-a4af-2e3f60d289ba"))
{
Description = "A user with full administrative privileges.",
Name = nameof(SystemAdministrator)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static class Named
/// <returns>
/// A collection of all known <see cref="DomainModel" /> instances.
/// </returns>
public static IEnumerable<DomainModel> All() => new DomainModel[]
public static IEnumerable<DomainModel> All() => new[]
{
StevenCallahanSystemAdministrator,
TomSmithEndUser
Expand All @@ -48,7 +48,7 @@ public static class Named
/// <summary>
/// Gets the system administrator role assignment for Steven Callahan.
/// </summary>
public static DomainModel StevenCallahanSystemAdministrator => new DomainModel(Guid.Parse("3af59674-efe9-46ad-b8b3-847e1a74c53c"))
public static DomainModel StevenCallahanSystemAdministrator => new(Guid.Parse("3af59674-efe9-46ad-b8b3-847e1a74c53c"))
{
User = UserModel.Named.StevenCallahan,
UserRole = UserRoleModel.Named.SystemAdministrator
Expand All @@ -57,7 +57,7 @@ public static class Named
/// <summary>
/// Gets the end user role assignment for Tom Smith.
/// </summary>
public static DomainModel TomSmithEndUser => new DomainModel(Guid.Parse("472ceca5-e06b-4ae7-8022-ecb160822137"))
public static DomainModel TomSmithEndUser => new(Guid.Parse("472ceca5-e06b-4ae7-8022-ecb160822137"))
{
User = UserModel.Named.TomSmith,
UserRole = UserRoleModel.Named.EndUser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,12 @@ public T[] ToArray(Int32 startIndex, Int32 count)
/// Represents an object that can be used to synchronize access to the current <see cref="InfiniteSequence{T}" />.
/// </summary>
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly Object SyncRoot = new Object();
private readonly Object SyncRoot = new();

/// <summary>
/// Represents the ordered, calculated terms for the current <see cref="InfiniteSequence{T}" />.
/// </summary>
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private List<T> CalculatedTerms = new List<T>();
private List<T> CalculatedTerms = new();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public ReadOnlyPinnedMemory(T[] field)
Handle = GCHandle.Alloc(field.RejectIf().IsNull(nameof(field)).TargetArgument, GCHandleType.Pinned);
Field = (T[])Handle.Target;
HandleIsActive = true;
LazyFieldMemory = new Lazy<Memory<T>>(InitializeFieldMemory, LazyThreadSafetyMode.ExecutionAndPublication);
LazyFieldMemory = new(InitializeFieldMemory, LazyThreadSafetyMode.ExecutionAndPublication);
Length = field.Length;
Pointer = Handle.AddrOfPinnedObject();
}
Expand Down Expand Up @@ -230,7 +230,7 @@ protected override void Dispose(Boolean disposing)
/// Initializes the lazily-initialized structure collection as a <see cref="Memory{T}" />.
/// </summary>
[DebuggerHidden]
private Memory<T> InitializeFieldMemory() => new Memory<T>(Field);
private Memory<T> InitializeFieldMemory() => new(Field);

/// <summary>
/// Gets a value indicating whether or not the memory field is empty.
Expand Down
2 changes: 1 addition & 1 deletion src/RapidField.SolidInstruments.Collections/TreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ public T Value
/// Represents an object that is used to synchronize access to the associated resource(s).
/// </summary>
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly Object SyncRoot = new Object();
private readonly Object SyncRoot = new();

/// <summary>
/// Represents the parent node of the current <see cref="TreeNode{T}" />, or <see langword="null" /> if the current
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static class ICommandRegisterExtensions
/// <returns>
/// A new <see cref="TextualCommand" />.
/// </returns>
public static TextualCommand FromText(this ICommandRegister target, String value) => new TextualCommand(value);
public static TextualCommand FromText(this ICommandRegister target, String value) => new(value);

/// <summary>
/// Creates a new <see cref="TextualCommand" />.
Expand All @@ -49,7 +49,7 @@ public static class ICommandRegisterExtensions
/// <returns>
/// A new <see cref="TextualCommand" />.
/// </returns>
public static TextualCommand FromText(this ICommandRegister target, String value, IEnumerable<String> labels) => new TextualCommand(value, labels);
public static TextualCommand FromText(this ICommandRegister target, String value, IEnumerable<String> labels) => new(value, labels);

/// <summary>
/// Creates a new <see cref="GetConfigurationSectionCommand" />.
Expand All @@ -69,7 +69,7 @@ public static class ICommandRegisterExtensions
/// <exception cref="ArgumentNullException">
/// <paramref name="key" /> is <see langword="null" />.
/// </exception>
public static GetConfigurationSectionCommand GetConfigurationSection(this ICommandRegister target, String key) => new GetConfigurationSectionCommand(key);
public static GetConfigurationSectionCommand GetConfigurationSection(this ICommandRegister target, String key) => new(key);

/// <summary>
/// Creates a new <see cref="GetConfigurationValueCommand" />.
Expand All @@ -89,7 +89,7 @@ public static class ICommandRegisterExtensions
/// <exception cref="ArgumentNullException">
/// <paramref name="key" /> is <see langword="null" />.
/// </exception>
public static GetConfigurationValueCommand GetConfigurationValue(this ICommandRegister target, String key) => new GetConfigurationValueCommand(key);
public static GetConfigurationValueCommand GetConfigurationValue(this ICommandRegister target, String key) => new(key);

/// <summary>
/// Creates a new <see cref="GetConnectionStringCommand" />.
Expand All @@ -109,6 +109,6 @@ public static class ICommandRegisterExtensions
/// <exception cref="ArgumentNullException">
/// <paramref name="name" /> is <see langword="null" />.
/// </exception>
public static GetConnectionStringCommand GetConnectionString(this ICommandRegister target, String name) => new GetConnectionStringCommand(name);
public static GetConnectionStringCommand GetConnectionString(this ICommandRegister target, String name) => new(name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static class ObjectExtensions
/// </returns>
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ValidationTarget<TArgument> RejectIf<TArgument>(this TArgument target) => new ValidationTarget<TArgument>(target);
public static ValidationTarget<TArgument> RejectIf<TArgument>(this TArgument target) => new(target);

/// <summary>
/// Raises a new <see cref="ArgumentException" /> if the target argument satisfies the specified predicate.
Expand Down Expand Up @@ -114,7 +114,7 @@ public static ValidationResult<TArgument> RejectIf<TArgument>(this TArgument tar
throw new ArgumentException(exceptionMessage, targetParameterName);
}

return new ValidationResult<TArgument>(new ValidationTarget<TArgument>(target));
return new(new(target));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public ValidationResult<TArgument> OrIf(Predicate<TArgument> predicate, String t
throw new ArgumentException(exceptionMessage, targetParameterName);
}

return new ValidationResult<TArgument>(Target);
return new(Target);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal ValidationTarget(TArgument argument)
/// Gets the result of the validation operation.
/// </summary>
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
internal ValidationResult<TArgument> Result => new ValidationResult<TArgument>(this);
internal ValidationResult<TArgument> Result => new(this);

/// <summary>
/// Represents the target argument.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,9 @@ private IDistributedCache Cache
/// Represents settings used by <see cref="Serialize(DataContractJsonSerializer, Object)" /> to serialize objects.
/// </summary>
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private static readonly DataContractJsonSerializerSettings SerializerSettings = new DataContractJsonSerializerSettings
private static readonly DataContractJsonSerializerSettings SerializerSettings = new()
{
DateTimeFormat = new DateTimeFormat(DateTimeSerializationFormatString),
DateTimeFormat = new(DateTimeSerializationFormatString),
EmitTypeInformation = EmitTypeInformation.AsNeeded,
SerializeReadOnlyTypes = false
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public InMemoryCacheClient(InMemoryCachingStrategy strategy)
: base(strategy == InMemoryCachingStrategy.NoCaching ? ConcurrencyControlMode.Unconstrained : ConcurrencyControlMode.ProcessorCountSemaphore)
{
Strategy = strategy.RejectIf().IsEqualToValue(InMemoryCachingStrategy.Unspecified, nameof(strategy));
LazyCache = IsOperative ? new Lazy<MemoryCache>(InitializeCache, LazyThreadSafetyMode.ExecutionAndPublication) : null;
LazyCacheOptions = IsOperative ? new Lazy<IOptions<MemoryCacheOptions>>(InitializeCacheOptions, LazyThreadSafetyMode.ExecutionAndPublication) : null;
LazyCache = IsOperative ? new(InitializeCache, LazyThreadSafetyMode.ExecutionAndPublication) : null;
LazyCacheOptions = IsOperative ? new(InitializeCacheOptions, LazyThreadSafetyMode.ExecutionAndPublication) : null;
}

/// <summary>
Expand Down Expand Up @@ -183,7 +183,7 @@ protected override void Write<TValue>(String key, TValue value, IConcurrencyCont
/// A new <see cref="MemoryCache" />.
/// </returns>
[DebuggerHidden]
private MemoryCache InitializeCache() => new MemoryCache(CacheOptions);
private MemoryCache InitializeCache() => new(CacheOptions);

/// <summary>
/// Initializes the configuration options for <see cref="Cache" />.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void Dispose()
/// <returns>
/// A task representing the asynchronous operation.
/// </returns>
public ValueTask DisposeAsync() => new ValueTask(Task.Factory.StartNew(Dispose));
public ValueTask DisposeAsync() => new(Task.Factory.StartNew(Dispose));

/// <summary>
/// Informs the control that a thread is entering a block of code or that it is beginning to consuming a resource.
Expand Down Expand Up @@ -222,7 +222,7 @@ protected virtual void Dispose(Boolean disposing)
return;
}

lock (DisposalSyncRoot ?? new Object())
lock (DisposalSyncRoot ?? new())
{
if (IsDisposed)
{
Expand Down Expand Up @@ -354,13 +354,13 @@ public ConcurrencyControlConsumptionState ConsumptionState
/// Represents an object that can be used to synchronize object disposal.
/// </summary>
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly Object DisposalSyncRoot = new Object();
private readonly Object DisposalSyncRoot = new();

/// <summary>
/// Represents currently-in-use tokens that were issued by the current <see cref="ConcurrencyControl" />.
/// </summary>
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly ConcurrentDictionary<Int32, IConcurrencyControlToken> Tokens = new ConcurrentDictionary<Int32, IConcurrencyControlToken>();
private readonly ConcurrentDictionary<Int32, IConcurrencyControlToken> Tokens = new();

/// <summary>
/// Represents the consumption state of the current <see cref="ConcurrencyControl" />.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public void Dispose()
/// <returns>
/// A task representing the asynchronous operation.
/// </returns>
public ValueTask DisposeAsync() => new ValueTask(Task.Factory.StartNew(Dispose));
public ValueTask DisposeAsync() => new(Task.Factory.StartNew(Dispose));

/// <summary>
/// Determines whether or not the current <see cref="ConcurrencyControlToken" /> is equal to the specified
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected SemaphoreControl(Int32 maximumConcurrencyLimit, TimeSpan blockTimeoutT
: base(blockTimeoutThreshold)
{
MaximumConcurrencyLimit = maximumConcurrencyLimit.RejectIf().IsLessThan(1, nameof(maximumConcurrencyLimit));
Semaphore = new SemaphoreSlim(MaximumConcurrencyLimit);
Semaphore = new(MaximumConcurrencyLimit);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected ConfigurableInstrument(IConfiguration applicationConfiguration)
: base()
{
ApplicationConfiguration = applicationConfiguration.RejectIf().IsNull(nameof(applicationConfiguration)).TargetArgument;
LazyConfiguration = new Lazy<TConfiguration>(Configure, LazyThreadSafetyMode.PublicationOnly);
LazyConfiguration = new(Configure, LazyThreadSafetyMode.PublicationOnly);
}

/// <summary>
Expand Down Expand Up @@ -134,7 +134,7 @@ private TConfiguration Configure()
/// Represents a lazily-initialized default <see cref="IConfiguration" /> instance.
/// </summary>
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private static readonly Lazy<IConfiguration> LazyDefaultConfiguration = new Lazy<IConfiguration>(InitializeDefaultConfiguration, LazyThreadSafetyMode.PublicationOnly);
private static readonly Lazy<IConfiguration> LazyDefaultConfiguration = new(InitializeDefaultConfiguration, LazyThreadSafetyMode.PublicationOnly);

/// <summary>
/// Represents configuration information for the application.
Expand Down
24 changes: 12 additions & 12 deletions src/RapidField.SolidInstruments.Core/DateTimeRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public static DateTimeRange Parse(String input)
{
if (Parse(input, out var start, out var end, out var granularity, true))
{
return new DateTimeRange(start, end, granularity);
return new(start, end, granularity);
}

return null;
Expand Down Expand Up @@ -201,7 +201,7 @@ public static Boolean TryParse(String input, out DateTimeRange result)
return false;
}

result = new DateTimeRange(start, end, granularity);
result = new(start, end, granularity);
return true;
}

Expand Down Expand Up @@ -587,7 +587,7 @@ private void CalculateLengthInMonthsAndYears(out Int32 lengthInMonths, out Int32
else if (End.Month == Start.Month)
{
// The end months and start month are the same, but the end day and time precedes the start day and time.
endPrecedesStartDuringYear = endPrecedesStartDuringMonth == true;
endPrecedesStartDuringYear = endPrecedesStartDuringMonth is true;
}
else
{
Expand Down Expand Up @@ -733,15 +733,15 @@ private void Initialize(DateTime start, DateTime end, DateTimeRangeGranularity g
Start = start.Quantize(granularity);
End = end.Quantize(granularity);
Length = End - Start;
LazyLengthInDays = new Lazy<Int32>(CalculateLengthInDays, LazyThreadSafetyMode.PublicationOnly);
LazyLengthInHours = new Lazy<Int32>(CalculateLengthInHours, LazyThreadSafetyMode.PublicationOnly);
LazyLengthInMilliseconds = new Lazy<Int64>(CalculateLengthInMilliseconds, LazyThreadSafetyMode.PublicationOnly);
LazyLengthInMinutes = new Lazy<Int64>(CalculateLengthInMinutes, LazyThreadSafetyMode.PublicationOnly);
LazyLengthInMonths = new Lazy<Int32>(CalculateLengthInMonths, LazyThreadSafetyMode.PublicationOnly);
LazyLengthInSeconds = new Lazy<Int64>(CalculateLengthInSeconds, LazyThreadSafetyMode.PublicationOnly);
LazyLengthInWeeks = new Lazy<Int32>(CalculateLengthInWeeks, LazyThreadSafetyMode.PublicationOnly);
LazyLengthInYears = new Lazy<Int32>(CalculateLengthInYears, LazyThreadSafetyMode.PublicationOnly);
LazyMidpoint = new Lazy<DateTime>(CalculateMidpoint, LazyThreadSafetyMode.PublicationOnly);
LazyLengthInDays = new(CalculateLengthInDays, LazyThreadSafetyMode.PublicationOnly);
LazyLengthInHours = new(CalculateLengthInHours, LazyThreadSafetyMode.PublicationOnly);
LazyLengthInMilliseconds = new(CalculateLengthInMilliseconds, LazyThreadSafetyMode.PublicationOnly);
LazyLengthInMinutes = new(CalculateLengthInMinutes, LazyThreadSafetyMode.PublicationOnly);
LazyLengthInMonths = new(CalculateLengthInMonths, LazyThreadSafetyMode.PublicationOnly);
LazyLengthInSeconds = new(CalculateLengthInSeconds, LazyThreadSafetyMode.PublicationOnly);
LazyLengthInWeeks = new(CalculateLengthInWeeks, LazyThreadSafetyMode.PublicationOnly);
LazyLengthInYears = new(CalculateLengthInYears, LazyThreadSafetyMode.PublicationOnly);
LazyMidpoint = new(CalculateMidpoint, LazyThreadSafetyMode.PublicationOnly);
}

/// <summary>
Expand Down
Loading

0 comments on commit f469981

Please sign in to comment.