Skip to content

Commit

Permalink
Applied cleanup for IDE0017 to the solution.
Browse files Browse the repository at this point in the history
  • Loading branch information
MiYanni committed Sep 22, 2023
1 parent bb86103 commit 299de03
Show file tree
Hide file tree
Showing 56 changed files with 445 additions and 304 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ public PollingFileWatcher(string watchedDirectory)
_watchedDirectory = new DirectoryInfo(watchedDirectory);
BasePath = _watchedDirectory.FullName;

_pollingThread = new Thread(new ThreadStart(PollingLoop));
_pollingThread.IsBackground = true;
_pollingThread.Name = nameof(PollingFileWatcher);
_pollingThread = new Thread(new ThreadStart(PollingLoop))
{
IsBackground = true,
Name = nameof(PollingFileWatcher)
};

CreateKnownFilesSnapshot();

Expand Down
21 changes: 14 additions & 7 deletions src/Cli/Microsoft.DotNet.Cli.Sln.Internal/SlnFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@ public SlnFile()

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

using (var sr = new StreamReader(new FileStream(file, FileMode.Open, FileAccess.Read)))
{
Expand Down Expand Up @@ -429,8 +431,10 @@ public SlnPropertySet Properties
{
if (_properties == null)
{
_properties = new SlnPropertySet();
_properties.ParentSection = this;
_properties = new SlnPropertySet
{
ParentSection = this
};
if (_sectionLines != null)
{
foreach (var line in _sectionLines)
Expand Down Expand Up @@ -1066,8 +1070,11 @@ public SlnSection GetOrCreateSection(string id, SlnSectionType sectionType)
var sec = this.FirstOrDefault(s => s.Id == id);
if (sec == null)
{
sec = new SlnSection { Id = id };
sec.SectionType = sectionType;
sec = new SlnSection
{
Id = id,
SectionType = sectionType
};
Add(sec);
}
return sec;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@ public static int ExecuteAndCaptureOutput(this ProcessStartInfo startInfo, out s

var process = new Process
{
StartInfo = startInfo
StartInfo = startInfo,
EnableRaisingEvents = true
};

process.EnableRaisingEvents = true;

using (var reaper = new ProcessReaper(process))
{
process.Start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ public TemplateCommand(
AllowScriptsOption = new CliOption<AllowRunScripts>("--allow-scripts")
{
Description = SymbolStrings.TemplateCommand_Option_AllowScripts,
Arity = new ArgumentArity(1, 1)
Arity = new ArgumentArity(1, 1),
DefaultValueFactory = (_) => AllowRunScripts.Prompt
};
AllowScriptsOption.DefaultValueFactory = (_) => AllowRunScripts.Prompt;
Options.Add(AllowScriptsOption);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ private TemplateResult(TemplateCommand templateCommand, ParseResult parseResult)

internal static TemplateResult FromParseResult(TemplateCommand templateCommand, ParseResult parseResult)
{
TemplateResult result = new TemplateResult(templateCommand, parseResult);
result.IsLanguageMatch = templateCommand.LanguageOption == null || !parseResult.HasErrorFor(templateCommand.LanguageOption, out _);
result.IsTypeMatch = templateCommand.TypeOption == null || !parseResult.HasErrorFor(templateCommand.TypeOption, out _);
result.IsBaselineMatch = templateCommand.BaselineOption == null || !parseResult.HasErrorFor(templateCommand.BaselineOption, out _);
TemplateResult result = new TemplateResult(templateCommand, parseResult)
{
IsLanguageMatch = templateCommand.LanguageOption == null || !parseResult.HasErrorFor(templateCommand.LanguageOption, out _),
IsTypeMatch = templateCommand.TypeOption == null || !parseResult.HasErrorFor(templateCommand.TypeOption, out _),
IsBaselineMatch = templateCommand.BaselineOption == null || !parseResult.HasErrorFor(templateCommand.BaselineOption, out _)
};

if (templateCommand.LanguageOption != null && result.IsTemplateMatch)
{
Expand Down
6 changes: 4 additions & 2 deletions src/Cli/dotnet/Telemetry/Telemetry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,10 @@ private void InitializeTelemetry()
{
try
{
var persistenceChannel = new PersistenceChannel.PersistenceChannel(sendersCount: _senderCount);
persistenceChannel.SendingInterval = TimeSpan.FromMilliseconds(1);
var persistenceChannel = new PersistenceChannel.PersistenceChannel(sendersCount: _senderCount)
{
SendingInterval = TimeSpan.FromMilliseconds(1)
};

var config = TelemetryConfiguration.CreateDefault();
config.TelemetryChannel = persistenceChannel;
Expand Down
6 changes: 4 additions & 2 deletions src/Cli/dotnet/ToolManifest/ToolManifestEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,10 @@ private SerializableLocalToolsManifest DeserializeLocalToolsManifest(FilePath po

foreach (var toolJson in tools.EnumerateObject())
{
var serializableLocalToolSinglePackage = new SerializableLocalToolSinglePackage();
serializableLocalToolSinglePackage.PackageId = toolJson.Name;
var serializableLocalToolSinglePackage = new SerializableLocalToolSinglePackage
{
PackageId = toolJson.Name
};
if (toolJson.Value.TryGetStringValue(JsonPropertyVersion, out var versionJson))
{
serializableLocalToolSinglePackage.Version = versionJson;
Expand Down
15 changes: 9 additions & 6 deletions src/Cli/dotnet/commands/dotnet-nuget/NuGetCommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ public static CliCommand GetCommand()

private static CliCommand ConstructCommand()
{
var command = new DocumentedCommand("nuget", DocsLink);

// some subcommands are not defined here and just forwarded to NuGet app
command.TreatUnmatchedTokensAsErrors = false;
var command = new DocumentedCommand("nuget", DocsLink)
{
// some subcommands are not defined here and just forwarded to NuGet app
TreatUnmatchedTokensAsErrors = false
};

command.Options.Add(new CliOption<bool>("--version"));
command.Options.Add(new CliOption<string>("--verbosity", "-v"));
Expand Down Expand Up @@ -167,8 +168,10 @@ private static CliCommand GetTrustCommand()
};

CliCommand CertificateCommand() {
CliOption<string> algorithm = new("--algorithm");
algorithm.DefaultValueFactory = (_argResult) => "SHA256";
CliOption<string> algorithm = new("--algorithm")
{
DefaultValueFactory = (_argResult) => "SHA256"
};
algorithm.AcceptOnlyFromAmong("SHA256", "SHA384", "SHA512");

return new CliCommand("certificate") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ internal class ProjectLaunchSettingsProvider : ILaunchSettingsProvider

public LaunchSettingsApplyResult TryGetLaunchSettings(string? launchProfileName, JsonElement model)
{
var config = new ProjectLaunchSettingsModel();
config.LaunchProfileName = launchProfileName;
var config = new ProjectLaunchSettingsModel
{
LaunchProfileName = launchProfileName
};

foreach (var property in model.EnumerateObject())
{
Expand Down
6 changes: 4 additions & 2 deletions src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,10 @@ public static CliCommand GetCommand()

private static CliCommand ConstructCommand()
{
DocumentedCommand command = new("test", DocsLink, LocalizableStrings.AppFullName);
command.TreatUnmatchedTokensAsErrors = false;
DocumentedCommand command = new("test", DocsLink, LocalizableStrings.AppFullName)
{
TreatUnmatchedTokensAsErrors = false
};

// We are on purpose not capturing the solution, project or directory here. We want to pass it to the
// MSBuild command so we are letting it flow.
Expand Down
7 changes: 4 additions & 3 deletions src/Cli/dotnet/commands/dotnet-vstest/VSTestCommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ public static CliCommand GetCommand()

private static CliCommand ConstructCommand()
{
DocumentedCommand command = new("vstest", DocsLink);

command.TreatUnmatchedTokensAsErrors = false;
DocumentedCommand command = new("vstest", DocsLink)
{
TreatUnmatchedTokensAsErrors = false
};

command.Options.Add(CommonOptions.TestPlatformOption);
command.Options.Add(CommonOptions.TestFrameworkOption);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ public class CreationResult

public static CreationResult Create(CreationParameters parameters)
{
var result = new CreationResult();

result.InstalledSdkVersion = new ReleaseVersion(parameters.VersionForTesting ?? Product.Version);
var result = new CreationResult
{
InstalledSdkVersion = new ReleaseVersion(parameters.VersionForTesting ?? Product.Version)
};

bool manifestsNeedValidation;
if (string.IsNullOrEmpty(parameters.SdkVersionFromOption))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,17 @@ private void UpdateWorkloadsWithInstallRecord(
DirectoryPath? offlineCache = null)
{

var transaction = new CliTransaction();

transaction.RollbackStarted = () =>
{
Reporter.WriteLine(LocalizableStrings.RollingBackInstall);
};
// Don't hide the original error if roll back fails, but do log the rollback failure
transaction.RollbackFailed = ex =>
var transaction = new CliTransaction
{
Reporter.WriteLine(string.Format(LocalizableStrings.RollBackFailedMessage, ex.Message));
RollbackStarted = () =>
{
Reporter.WriteLine(LocalizableStrings.RollingBackInstall);
},
// Don't hide the original error if roll back fails, but do log the rollback failure
RollbackFailed = ex =>
{
Reporter.WriteLine(string.Format(LocalizableStrings.RollBackFailedMessage, ex.Message));
}
};

transaction.Run(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@ public async Task LoadAsync(BuiltImage image, SourceImageReference sourceReferen
string commandPath = await FindFullCommandPath(cancellationToken);

// call `docker load` and get it ready to receive input
ProcessStartInfo loadInfo = new(commandPath, $"load");
loadInfo.RedirectStandardInput = true;
loadInfo.RedirectStandardOutput = true;
loadInfo.RedirectStandardError = true;
ProcessStartInfo loadInfo = new(commandPath, $"load")
{
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true
};

using Process? loadProcess = Process.Start(loadInfo);

Expand Down
23 changes: 12 additions & 11 deletions src/StaticWebAssetsSdk/Tasks/ReferencedProjectConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,18 @@ public ITaskItem ToTaskItem()

internal static ReferencedProjectConfiguration FromTaskItem(ITaskItem arg)
{
var result = new ReferencedProjectConfiguration();

result.Identity = arg.GetMetadata("FullPath");
result.Version = int.Parse(arg.GetMetadata(nameof(Version)), CultureInfo.InvariantCulture);
result.Source = arg.GetMetadata(nameof(Source));
result.GetBuildAssetsTargets = arg.GetMetadata(nameof(GetBuildAssetsTargets));
result.AdditionalBuildProperties = arg.GetMetadata(nameof(AdditionalBuildProperties));
result.AdditionalBuildPropertiesToRemove = arg.GetMetadata(nameof(AdditionalBuildPropertiesToRemove));
result.GetPublishAssetsTargets = arg.GetMetadata(nameof(GetPublishAssetsTargets));
result.AdditionalPublishProperties = arg.GetMetadata(nameof(AdditionalPublishProperties));
result.AdditionalPublishPropertiesToRemove = arg.GetMetadata(nameof(AdditionalPublishPropertiesToRemove));
var result = new ReferencedProjectConfiguration
{
Identity = arg.GetMetadata("FullPath"),
Version = int.Parse(arg.GetMetadata(nameof(Version)), CultureInfo.InvariantCulture),
Source = arg.GetMetadata(nameof(Source)),
GetBuildAssetsTargets = arg.GetMetadata(nameof(GetBuildAssetsTargets)),
AdditionalBuildProperties = arg.GetMetadata(nameof(AdditionalBuildProperties)),
AdditionalBuildPropertiesToRemove = arg.GetMetadata(nameof(AdditionalBuildPropertiesToRemove)),
GetPublishAssetsTargets = arg.GetMetadata(nameof(GetPublishAssetsTargets)),
AdditionalPublishProperties = arg.GetMetadata(nameof(AdditionalPublishProperties)),
AdditionalPublishPropertiesToRemove = arg.GetMetadata(nameof(AdditionalPublishPropertiesToRemove))
};

return result;
}
Expand Down
15 changes: 8 additions & 7 deletions src/StaticWebAssetsSdk/Tasks/StaticWebAssetsDiscoveryPattern.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,14 @@ internal static bool HasSourceId(string candidate, string source) =>

internal static StaticWebAssetsDiscoveryPattern FromTaskItem(ITaskItem pattern)
{
var result = new StaticWebAssetsDiscoveryPattern();

result.Name = pattern.ItemSpec;
result.Source = pattern.GetMetadata(nameof(Source));
result.BasePath = pattern.GetMetadata(nameof(BasePath));
result.ContentRoot = pattern.GetMetadata(nameof(ContentRoot));
result.Pattern = pattern.GetMetadata(nameof(Pattern));
var result = new StaticWebAssetsDiscoveryPattern
{
Name = pattern.ItemSpec,
Source = pattern.GetMetadata(nameof(Source)),
BasePath = pattern.GetMetadata(nameof(BasePath)),
ContentRoot = pattern.GetMetadata(nameof(ContentRoot)),
Pattern = pattern.GetMetadata(nameof(Pattern))
};

return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ private readonly MockTaskItem _apphost
[WindowsOnlyFact]
public void It_can_expand_OutputPath()
{
var task = new GetPublishItemsOutputGroupOutputs();

task.PublishDir = @"bin\Debug\net5.0\publish\";
task.ResolvedFileToPublish = new[]
var task = new GetPublishItemsOutputGroupOutputs
{
PublishDir = @"bin\Debug\net5.0\publish\",
ResolvedFileToPublish = new[]
{
_apphost, _dll, _dll
}
};

task.Execute().Should().BeTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ public void ItBuildsDependencyContextsFromProjectLockFiles(

using (JsonTextWriter writer = new JsonTextWriter(File.CreateText($"result-{baselineFileName}.deps.json")))
{
JsonSerializer serializer = new JsonSerializer();
serializer.Formatting = Formatting.Indented;
JsonSerializer serializer = new JsonSerializer
{
Formatting = Formatting.Indented
};
serializer.Serialize(writer, result);
}

Expand Down
Loading

0 comments on commit 299de03

Please sign in to comment.