Skip to content

Commit

Permalink
Applied cleanup for IDE0090 to the solution.
Browse files Browse the repository at this point in the history
  • Loading branch information
MiYanni committed Sep 23, 2023
1 parent bb86103 commit 171723b
Show file tree
Hide file tree
Showing 385 changed files with 1,065 additions and 1,061 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Watch.BrowserRefresh
{
public class BrowserRefreshMiddleware
{
private static readonly MediaTypeHeaderValue _textHtmlMediaType = new MediaTypeHeaderValue("text/html");
private static readonly MediaTypeHeaderValue _textHtmlMediaType = new("text/html");
private readonly RequestDelegate _next;
private readonly ILogger _logger;

Expand Down
2 changes: 1 addition & 1 deletion src/BuiltInTools/BrowserRefresh/ResponseStreamWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Watch.BrowserRefresh
/// </summary>
public class ResponseStreamWrapper : Stream
{
private static readonly MediaTypeHeaderValue _textHtmlMediaType = new MediaTypeHeaderValue("text/html");
private static readonly MediaTypeHeaderValue _textHtmlMediaType = new("text/html");
private readonly Stream _baseStream;
private readonly HttpContext _context;
private readonly ILogger _logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.DotNet.Watcher.Tools
{
internal sealed class LaunchBrowserFilter : IWatchFilter, IAsyncDisposable
{
private static readonly Regex NowListeningRegex = new Regex(@"Now listening on: (?<url>.*)\s*$", RegexOptions.None | RegexOptions.Compiled, TimeSpan.FromSeconds(10));
private static readonly Regex NowListeningRegex = new(@"Now listening on: (?<url>.*)\s*$", RegexOptions.None | RegexOptions.Compiled, TimeSpan.FromSeconds(10));
private readonly DotNetWatchOptions _options;
private readonly string? _browserPath;
private bool _attemptedBrowserLaunch;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ internal sealed class Keywords
[Event(2, Message = "Hot reload finished for {0}", Level = EventLevel.Informational, Keywords = Keywords.Perf)]
public void HotReloadEnd(StartType handlerType) { WriteEvent(2, handlerType); }

public static readonly HotReloadEventSource Log = new HotReloadEventSource();
public static readonly HotReloadEventSource Log = new();
}
}
2 changes: 1 addition & 1 deletion src/BuiltInTools/dotnet-watch/Internal/ConsoleReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.Extensions.Tools.Internal
/// </summary>
internal sealed class ConsoleReporter : IReporter
{
private readonly object _writeLock = new object();
private readonly object _writeLock = new();

public ConsoleReporter(IConsole console)
: this(console, verbose: false, quiet: false, suppressEmojis: false)
Expand Down
2 changes: 1 addition & 1 deletion src/BuiltInTools/dotnet-watch/Internal/ConsoleRequester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.Extensions.Tools.Internal
/// </summary>
internal sealed class ConsoleRequester : IRequester
{
private readonly object _writeLock = new object();
private readonly object _writeLock = new();

public ConsoleRequester(IConsole console, bool quiet, bool suppressEmojis)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal class DotnetFileWatcher : IFileSystemWatcher

private FileSystemWatcher _fileSystemWatcher;

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

public DotnetFileWatcher(string watchedDirectory)
: this(watchedDirectory, DefaultWatcherFactory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ internal class PollingFileWatcher : IFileSystemWatcher

private readonly DirectoryInfo _watchedDirectory;

private Dictionary<string, FileMeta> _knownEntities = new Dictionary<string, FileMeta>();
private Dictionary<string, FileMeta> _tempDictionary = new Dictionary<string, FileMeta>();
private HashSet<string> _changes = new HashSet<string>();
private Dictionary<string, FileMeta> _knownEntities = new();
private Dictionary<string, FileMeta> _tempDictionary = new();
private HashSet<string> _changes = new();

private Thread _pollingThread;
private bool _raiseEvents;
Expand Down
2 changes: 1 addition & 1 deletion src/BuiltInTools/dotnet-watch/Internal/OutputCapture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Microsoft.DotNet.Watcher.Internal
{
internal sealed class OutputCapture
{
private readonly List<string> _lines = new List<string>();
private readonly List<string> _lines = new();
public IEnumerable<string> Lines => _lines;
public void AddLine(string line) => _lines.Add(line);
}
Expand Down
2 changes: 1 addition & 1 deletion src/BuiltInTools/dotnet-watch/Internal/ProcessRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private class ProcessState : IDisposable
{
private readonly IReporter _reporter;
private readonly Process _process;
private readonly TaskCompletionSource _tcs = new TaskCompletionSource();
private readonly TaskCompletionSource _tcs = new();
private volatile bool _disposed;

public ProcessState(Process process, IReporter reporter)
Expand Down
4 changes: 2 additions & 2 deletions src/BuiltInTools/dotnet-watch/ProjectInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ internal sealed record ProjectInfo
string RunWorkingDirectory
)
{
private static readonly Version Version3_1 = new Version(3, 1);
private static readonly Version Version6_0 = new Version(6, 0);
private static readonly Version Version3_1 = new(3, 1);
private static readonly Version Version6_0 = new(6, 0);

public bool IsNetCoreApp31OrNewer()
{
Expand Down
16 changes: 8 additions & 8 deletions src/Cli/Microsoft.DotNet.Cli.Sln.Internal/SlnFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ namespace Microsoft.DotNet.Cli.Sln.Internal
{
public class SlnFile
{
private SlnProjectCollection _projects = new SlnProjectCollection();
private SlnSectionCollection _sections = new SlnSectionCollection();
private SlnPropertySet _metadata = new SlnPropertySet(true);
private SlnProjectCollection _projects = new();
private SlnSectionCollection _sections = new();
private SlnPropertySet _metadata = new(true);
private int _prefixBlankLines = 1;
private TextFormatInfo _format = new TextFormatInfo();
private TextFormatInfo _format = new();

public string FormatVersion { get; set; }
public string ProductDescription { get; set; }
Expand Down Expand Up @@ -105,7 +105,7 @@ public SlnFile()

public static SlnFile Read(string file)
{
SlnFile slnFile = new SlnFile();
SlnFile slnFile = new();
slnFile.FullPath = Path.GetFullPath(file);
slnFile._format = FileUtil.GetTextFormatInfo(file);

Expand Down Expand Up @@ -152,7 +152,7 @@ private void Read(TextReader reader)
}
else if (line.StartsWith("Project", StringComparison.Ordinal))
{
SlnProject p = new SlnProject();
SlnProject p = new();
p.Read(reader, line, ref curLineNum);
_projects.Add(p);
}
Expand Down Expand Up @@ -241,7 +241,7 @@ private void Write(TextWriter writer)

public class SlnProject
{
private SlnSectionCollection _sections = new SlnSectionCollection();
private SlnSectionCollection _sections = new();

private SlnFile _parentFile;

Expand Down Expand Up @@ -635,7 +635,7 @@ internal void Write(TextWriter writer, string sectionTag)
/// </summary>
public class SlnPropertySet : IDictionary<string, string>
{
private OrderedDictionary _values = new OrderedDictionary();
private OrderedDictionary _values = new();
private bool _isMetadata;

internal bool Processed { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/Microsoft.DotNet.Cli.Utils/AnsiExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Microsoft.DotNet.Cli.Utils
{
public static class AnsiExtensions
{
private static readonly Lazy<bool> _xtermEnabled = new Lazy<bool>(
private static readonly Lazy<bool> _xtermEnabled = new(
() =>
{
var environment = Environment.GetEnvironmentVariable("TERM");
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/Microsoft.DotNet.Cli.Utils/BlockingMemoryStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.DotNet.Cli.Utils
/// </summary>
public sealed class BlockingMemoryStream : Stream
{
private readonly BlockingCollection<byte[]> _buffers = new BlockingCollection<byte[]>();
private readonly BlockingCollection<byte[]> _buffers = new();
private ArraySegment<byte> _remaining;

public override void Write(byte[] buffer, int offset, int count)
Expand Down
6 changes: 3 additions & 3 deletions src/Cli/Microsoft.DotNet.Cli.Utils/BuiltInCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public CommandResult Execute()
{
// redirecting the standard out and error so we can forward
// the output to the caller
using (BlockingMemoryStream outStream = new BlockingMemoryStream())
using (BlockingMemoryStream errorStream = new BlockingMemoryStream())
using (BlockingMemoryStream outStream = new())
using (BlockingMemoryStream errorStream = new())
{
_environment.SetConsoleOut(new StreamWriter(outStream) { AutoFlush = true });
_environment.SetConsoleError(new StreamWriter(errorStream) { AutoFlush = true });
Expand All @@ -71,7 +71,7 @@ public CommandResult Execute()
Task.WaitAll(taskOut, taskErr);

// fake out a ProcessStartInfo using the Muxer command name, since this is a built-in command
ProcessStartInfo startInfo = new ProcessStartInfo(new Muxer().MuxerPath, $"{CommandName} {CommandArgs}");
ProcessStartInfo startInfo = new(new Muxer().MuxerPath, $"{CommandName} {CommandArgs}");
return new CommandResult(startInfo, exitCode, null, null);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/Microsoft.DotNet.Cli.Utils/CommandResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Microsoft.DotNet.Cli.Utils
{
public struct CommandResult
{
public static readonly CommandResult Empty = new CommandResult();
public static readonly CommandResult Empty = new();

public ProcessStartInfo StartInfo { get; }
public int ExitCode { get; }
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/Microsoft.DotNet.Cli.Utils/DotnetFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal static class DotnetFiles
private static string SdkRootFolder => Path.Combine(typeof(DotnetFiles).GetTypeInfo().Assembly.Location, "..");

private static Lazy<DotnetVersionFile> s_versionFileObject =
new Lazy<DotnetVersionFile>(() => new DotnetVersionFile(VersionFile));
new(() => new DotnetVersionFile(VersionFile));

/// <summary>
/// The SDK ships with a .version file that stores the commit information and SDK version
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/Microsoft.DotNet.Cli.Utils/EnvironmentProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class EnvironmentProvider : IEnvironmentProvider
private static char[] s_pathSeparator = new char[] { Path.PathSeparator };
private static char[] s_quote = new char[] { '"' };
private IEnumerable<string> _searchPaths;
private readonly Lazy<string> _userHomeDirectory = new Lazy<string>(() => Environment.GetEnvironmentVariable("HOME") ?? string.Empty);
private readonly Lazy<string> _userHomeDirectory = new(() => Environment.GetEnvironmentVariable("HOME") ?? string.Empty);
private IEnumerable<string> _executableExtensions;

public IEnumerable<string> ExecutableExtensions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ internal static bool TryGetMostFitRuntimeIdentifier(
private DependencyContext CreateDependencyContext()
{
using (Stream depsFileStream = File.OpenRead(_depsFilePath))
using (DependencyContextJsonReader reader = new DependencyContextJsonReader())
using (DependencyContextJsonReader reader = new())
{
return reader.Read(depsFileStream);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal class MSBuildForwardingAppWithoutLogging
public bool ExecuteMSBuildOutOfProc => _forwardingApp != null;

private readonly Dictionary<string, string> _msbuildRequiredEnvironmentVariables =
new Dictionary<string, string>
new()
{
{ "MSBuildExtensionsPath", MSBuildExtensionsPathTestHook ?? AppContext.BaseDirectory },
{ "MSBuildSDKsPath", GetMSBuildSDKsPath() },
Expand Down Expand Up @@ -133,7 +133,7 @@ public int Execute()
public int ExecuteInProc(string[] arguments)
{
// Save current environment variables before overwriting them.
Dictionary<string, string> savedEnvironmentVariables = new Dictionary<string, string>();
Dictionary<string, string> savedEnvironmentVariables = new();
try
{
foreach (KeyValuePair<string, string> kvp in _msbuildRequiredEnvironmentVariables)
Expand Down
4 changes: 2 additions & 2 deletions src/Cli/Microsoft.DotNet.Cli.Utils/MSBuildPropertyParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public static class MSBuildPropertyParser
public static IEnumerable<(string key, string value)> ParseProperties(string input)
{
var currentPos = 0;
StringBuilder currentKey = new StringBuilder();
StringBuilder currentValue = new StringBuilder();
StringBuilder currentKey = new();
StringBuilder currentValue = new();

(string key, string value) EmitAndReset()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/Microsoft.DotNet.Cli.Utils/PathUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public static string GetAbsolutePath(string basePath, string relativePath)
throw new ArgumentNullException(nameof(relativePath));
}

Uri resultUri = new Uri(new Uri(basePath), new Uri(relativePath, UriKind.Relative));
Uri resultUri = new(new Uri(basePath), new Uri(relativePath, UriKind.Relative));
return resultUri.LocalPath;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Cli/Microsoft.DotNet.Cli.Utils/RuntimeEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ internal enum Platform

internal static class RuntimeEnvironment
{
private static readonly Lazy<Platform> _platform = new Lazy<Platform>(DetermineOSPlatform);
private static readonly Lazy<DistroInfo> _distroInfo = new Lazy<DistroInfo>(LoadDistroInfo);
private static readonly Lazy<Platform> _platform = new(DetermineOSPlatform);
private static readonly Lazy<DistroInfo> _distroInfo = new(LoadDistroInfo);

public static Platform OperatingSystemPlatform { get; } = GetOSPlatform();
public static string OperatingSystemVersion { get; } = GetOSVersion();
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/Microsoft.DotNet.Cli.Utils/Uuid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Uuid
public static Guid Create(string name)
{
// Any fixed GUID will do for a namespace.
Guid namespaceId = new Guid("28F1468D-672B-489A-8E0C-7C5B3030630C");
Guid namespaceId = new("28F1468D-672B-489A-8E0C-7C5B3030630C");

using (SHA1 hasher = SHA1.Create())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static class CliFolderPathCalculator
ToolPackageFolderPathCalculator.GetToolPackageFolderPath(ToolsShimPath);

public static BashPathUnderHomeDirectory ToolsShimPathInUnix =>
new BashPathUnderHomeDirectory(
new(
DotnetHomePath,
Path.Combine(DotnetProfileDirectoryName, ToolsShimFolderName));

Expand Down
8 changes: 4 additions & 4 deletions src/Cli/Microsoft.TemplateEngine.Cli/Alias/AliasRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ internal AliasManipulationResult TryCreateOrRemoveAlias(string aliasName, IReadO
}

//ensure loaded sets aliases
Dictionary<string, IReadOnlyList<string>> aliasesWithCandidate = new Dictionary<string, IReadOnlyList<string>>(_aliases!.CommandAliases);
Dictionary<string, IReadOnlyList<string>> aliasesWithCandidate = new(_aliases!.CommandAliases);
aliasesWithCandidate[aliasName] = aliasTokens;
if (!TryExpandCommandAliases(aliasesWithCandidate, aliasTokens, out IReadOnlyList<string>? expandedInputTokens))
{
Expand Down Expand Up @@ -92,7 +92,7 @@ internal bool TryExpandCommandAliases(IReadOnlyList<string> inputTokens, out IRe
private static bool TryExpandCommandAliases(IReadOnlyDictionary<string, IReadOnlyList<string>> aliases, IReadOnlyList<string> inputTokens, out IReadOnlyList<string>? expandedTokens)
{
bool expansionOccurred = false;
HashSet<string> seenAliases = new HashSet<string>();
HashSet<string> seenAliases = new();
expandedTokens = new List<string>(inputTokens);

do
Expand Down Expand Up @@ -156,7 +156,7 @@ private void Save()
// reads a dictionary whose values can either be string literals, or arrays of strings.
private IReadOnlyDictionary<string, IReadOnlyList<string>> ToStringListDictionary(JToken token, StringComparer? comparer = null, string? propertyName = null)
{
Dictionary<string, IReadOnlyList<string>> result = new Dictionary<string, IReadOnlyList<string>>(comparer ?? StringComparer.Ordinal);
Dictionary<string, IReadOnlyList<string>> result = new(comparer ?? StringComparer.Ordinal);
JObject? jObj = token as JObject;
if (jObj == null || propertyName == null || !jObj.TryGetValue(propertyName, StringComparison.OrdinalIgnoreCase, out JToken? element))
{
Expand Down Expand Up @@ -188,7 +188,7 @@ private IReadOnlyDictionary<string, IReadOnlyList<string>> ToStringListDictionar
}
else
{
List<string> values = new List<string>();
List<string> values = new();
foreach (JToken item in arr)
{
if (item != null && item.Type == JTokenType.String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Microsoft.TemplateEngine.Cli
/// </summary>
internal class ChoiceTemplateParameter : CliTemplateParameter
{
private Dictionary<string, ParameterChoice> _choices = new Dictionary<string, ParameterChoice>(StringComparer.OrdinalIgnoreCase);
private Dictionary<string, ParameterChoice> _choices = new(StringComparer.OrdinalIgnoreCase);

internal ChoiceTemplateParameter(ITemplateParameter parameter, HostSpecificTemplateData data) : base(parameter, data)
{
Expand Down Expand Up @@ -177,7 +177,7 @@ private static bool TryConvertValueToChoice(IEnumerable<string> values, ChoiceTe
parsedValue = string.Empty;
error = string.Empty;

List<string> parsedValues = new List<string>();
List<string> parsedValues = new();
foreach (string val in values)
{
if (!TryConvertSingleValueToChoice(val, parameter, out string value, out error))
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/Microsoft.TemplateEngine.Cli/CliEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal class CliEnvironment : IEnvironment

public CliEnvironment()
{
Dictionary<string, string> variables = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
Dictionary<string, string> variables = new(StringComparer.OrdinalIgnoreCase)
{
{ "TEMPLATE_ENGINE_DISABLE_FILEWATCHER", "1" }
};
Expand Down
6 changes: 3 additions & 3 deletions src/Cli/Microsoft.TemplateEngine.Cli/CliTemplateParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ internal enum ParameterType
/// </summary>
internal class CliTemplateParameter
{
private readonly List<string> _shortNameOverrides = new List<string>();
private readonly List<string> _shortNameOverrides = new();

private readonly List<string> _longNameOverrides = new List<string>();
private readonly List<string> _longNameOverrides = new();

private readonly TemplateParameterPrecedence _precedence;

Expand Down Expand Up @@ -458,7 +458,7 @@ private static Func<ArgumentResult, T> GetParseArgument<T>(CliTemplateParameter

private string GetOptionDescription()
{
StringBuilder displayValue = new StringBuilder(255);
StringBuilder displayValue = new(255);
displayValue.AppendLine(Description);

string? precedenceValue = GetPrecedenceInfo(_precedence);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ internal class AliasAssignmentCoordinator

foreach (var parameter in parameters)
{
HashSet<string> aliases = new HashSet<string>(StringComparer.Ordinal);
List<string> errors = new List<string>();
HashSet<string> aliases = new(StringComparer.Ordinal);
List<string> errors = new();
if (parameter.Name.Contains(':'))
{
// Colon is reserved, template param names cannot have any.
Expand Down
Loading

0 comments on commit 171723b

Please sign in to comment.