Skip to content

Commit

Permalink
Remove some redundant casts (#6167)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Dec 4, 2024
1 parent 3ca108d commit 2762484
Show file tree
Hide file tree
Showing 16 changed files with 30 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/NuGet.Clients/NuGet.CommandLine/MsBuildToolset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private static DateTime ConvertFILETIMEToDateTime(FILETIME time)
{
long highBits = time.dwHighDateTime;
highBits = highBits << 32;
return DateTime.FromFileTimeUtc(highBits | (long)(uint)time.dwLowDateTime);
return DateTime.FromFileTimeUtc(highBits | (uint)time.dwLowDateTime);
}

public static string GetMsBuildDirFromVsDir(string vsDir)
Expand Down
7 changes: 1 addition & 6 deletions src/NuGet.Clients/NuGet.CommandLine/MsBuildUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -928,18 +928,13 @@ private static List<MsBuildToolset> GetInstalledSxsToolsets()
ISetupConfiguration configuration;
try
{
configuration = new SetupConfiguration() as ISetupConfiguration2;
configuration = new SetupConfiguration();
}
catch (Exception)
{
return null; // No COM class
}

if (configuration == null)
{
return null;
}

var enumerator = configuration.EnumInstances();
if (enumerator == null)
{
Expand Down
10 changes: 5 additions & 5 deletions src/NuGet.Clients/NuGet.Console/WpfConsole/WpfConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ private async Task WriteProgressAsync(string operation, int percentComplete)
1 /* in progress */,
operation,
(uint)percentComplete,
(uint)100);
100);
}
}

Expand All @@ -648,8 +648,8 @@ private void HideProgress()
ref _pdwCookieForStatusBar,
0 /* completed */,
string.Empty,
(uint)100,
(uint)100);
100,
100);
}

private async Task HideProgressAsync()
Expand All @@ -660,8 +660,8 @@ private async Task HideProgressAsync()
ref _pdwCookieForStatusBar,
0 /* completed */,
string.Empty,
(uint)100,
(uint)100);
100,
100);
}

public void SetExecutionMode(bool isExecuting)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ private void ExecuteAddMapping(object parameter)
var viewModel = new SourceMappingViewModel(packageId, packageSources);
_parent.SourceMappingsCollection.Add(viewModel);

(_parent.ShowAddDialogCommand as DelegateCommand).RaiseCanExecuteChanged();
(_parent.RemoveMappingCommand as DelegateCommand).RaiseCanExecuteChanged();
(_parent.RemoveAllMappingsCommand as DelegateCommand).RaiseCanExecuteChanged();
_parent.ShowAddDialogCommand.RaiseCanExecuteChanged();
_parent.RemoveMappingCommand.RaiseCanExecuteChanged();
_parent.RemoveAllMappingsCommand.RaiseCanExecuteChanged();

bool isGlobbing = packageId.Contains("*");
var evt = NavigatedTelemetryEvent.CreateWithAddPackageSourceMapping(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ private async Task ShowOptionsPageAsync(string optionsPageGuid)
IVsUIShell vsUIShell = await _vsUIShell.GetValueAsync();
vsUIShell.PostExecCommand(
ref toolsGroupGuid,
(uint)VSConstants.cmdidToolsOptions,
(uint)0,
VSConstants.cmdidToolsOptions,
0,
ref targetGuid);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class RecommenderPackageFeed : IPackageFeed
private readonly IPackageMetadataProvider _metadataProvider;
private readonly Common.ILogger _logger;

public (string modelVersion, string vsixVersion) VersionInfo { get; set; } = (modelVersion: (string)null, vsixVersion: (string)null);
public (string modelVersion, string vsixVersion) VersionInfo { get; set; } = (modelVersion: null, vsixVersion: null);

private readonly AsyncLazyNuGetRecommender _nuGetRecommender;

Expand Down Expand Up @@ -137,8 +137,8 @@ private async Task<SearchResult<IPackageSearchMetadata>> RecommendPackagesAsync(
if (!(NuGetRecommender is null))
{
var VersionDict = NuGetRecommender.GetVersionInfo();
VersionInfo = (modelVersion: VersionDict.ContainsKey("Model") ? VersionDict["Model"] : (string)null,
vsixVersion: VersionDict.ContainsKey("Vsix") ? VersionDict["Vsix"] : (string)null);
VersionInfo = (modelVersion: VersionDict.ContainsKey("Model") ? VersionDict["Model"] : null,
vsixVersion: VersionDict.ContainsKey("Vsix") ? VersionDict["Vsix"] : null);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/NuGet.Clients/NuGet.Tools/PackageManagerLaunchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public void LaunchSolutionPackageManager()
var guidNuGetDialog = GuidList.guidNuGetDialogCmdSet;
vsUIShell.PostExecCommand(
ref guidNuGetDialog,
(uint)PkgCmdIDList.cmdidAddPackageDialogForSolution,
(uint)0,
PkgCmdIDList.cmdidAddPackageDialogForSolution,
0,
ref targetGuid);
}).PostOnFailure(nameof(PackageManagerLaunchService));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using System.Threading.Tasks;
using Microsoft;
using NuGet.PackageManagement.VisualStudio;
using NuGet.ProjectManagement.Projects;
using NuGet.VisualStudio.Etw;
using NuGet.VisualStudio.Implementation.Resources;
using NuGet.VisualStudio.Telemetry;
Expand Down Expand Up @@ -93,8 +92,7 @@ private async Task<object> MigrateProjectToPackageRefAsync(string projectUniqueN
project, optionalContext: null);
Assumes.Present(legacyPackageRefBasedProject);

await ProjectJsonToPackageRefMigrator.MigrateAsync(
legacyPackageRefBasedProject as BuildIntegratedNuGetProject);
await ProjectJsonToPackageRefMigrator.MigrateAsync(legacyPackageRefBasedProject);
var result = new VsProjectJsonToPackageReferenceMigrateResult(success: true, errorMessage: null);
await nuGetProject.SaveAsync(CancellationToken.None);
await _solutionManager.Value.UpgradeProjectToPackageReferenceAsync(nuGetProject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ internal static IEnumerable<FormattedCell> BuildPackagesTable(
// Include "Requested" version column for top level package list
if (!printingTransitive)
{
valueSelectors.Add(p => new FormattedCell((p as ListReportPackage)?.RequestedVersion));
valueSelectors.Add(p => new FormattedCell(p?.RequestedVersion));
}

// "Resolved" version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ internal override void Update(SettingItem other)
}
else if (cert is SettingItem item)
{
item.Update(otherChild as SettingItem);
item.Update(otherChild);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/NuGet.Core/NuGet.PackageManagement/NuGetPackageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ private async Task<IEnumerable<NuGetProjectAction>> PreviewUpdatePackagesForClas
if (packageIdentity.HasVersion)
{
preferredVersions[packageIdentity.Id] = packageIdentity;
((List<PackageIdentity>)primaryTargets).Add(packageIdentity);
primaryTargets.Add(packageIdentity);
}
// Otherwise we just have the Id and so we wil explicitly not prefer the one currently installed
else
Expand Down Expand Up @@ -3477,7 +3477,7 @@ await BuildIntegratedRestoreUtility.ExecuteInitPs1ScriptsAsync(
if (dgSpecForParents.Restore.Count > 0)
{
// Restore and commit the lock file to disk regardless of the result
// This will restore all parents in a single restore
// This will restore all parents in a single restore
await DependencyGraphRestoreUtility.RestoreAsync(
dgSpecForParents,
referenceContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ private async Task UpdateFrameworkAsync(JObject json)
{
// project.json can have only one target framework
JsonConfigUtility.ClearFrameworks(json);
JsonConfigUtility.AddFramework(json, newTargetFramework as NuGetFramework);
JsonConfigUtility.AddFramework(json, newTargetFramework);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public IEnumerable<PackagingLogMessage> Validate(PackageArchiveReader package)

internal IEnumerable<PackagingLogMessage> GenerateWarnings(HashSet<NuGetFramework> compatNotExactMatches, HashSet<NuGetFramework> noExactMatchesFromFile, HashSet<NuGetFramework> noExactMatchesFromNuspec)
{
(string noExactMatchString, string compatMatchString) = GenerateWarningString(noExactMatchesFromFile, noExactMatchesFromNuspec, (ICollection<NuGetFramework>)compatNotExactMatches);
(string noExactMatchString, string compatMatchString) = GenerateWarningString(noExactMatchesFromFile, noExactMatchesFromNuspec, compatNotExactMatches);

var issues = new List<PackagingLogMessage>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private bool IsSignatureAllowed(
if (IsSignatureTargeted(certificateHashEntry.Target, repositoryCountersignature.Value) &&
StringComparer.OrdinalIgnoreCase.Equals(certificateHashEntry.Fingerprint, countersignatureCertificateFingerprint))
{
if (ShouldVerifyOwners(certificateHashEntry as TrustedSignerAllowListEntry, repositoryCountersignature.Value as IRepositorySignature, out var allowedOwners, out var actualOwners))
if (ShouldVerifyOwners(certificateHashEntry as TrustedSignerAllowListEntry, repositoryCountersignature.Value, out var allowedOwners, out var actualOwners))
{
if (allowedOwners.Intersect(actualOwners).Any())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ internal static PackageSpec GetPackageSpec(ref Utf8JsonStreamReader jsonReader,
{
ReadScripts(ref jsonReader, packageSpec);
}
#pragma warning restore CS0612 // Type or member is
#pragma warning restore CS0612 // Type or member is
else if (jsonReader.ValueTextEquals(DependenciesPropertyName))
{
ReadDependencies(
Expand Down Expand Up @@ -881,7 +881,7 @@ private static void ReadMappings(ref Utf8JsonStreamReader jsonReader, string map
{
var files = new IncludeExcludeFiles()
{
Include = new[] { (string)jsonReader.GetString() }
Include = new[] { jsonReader.GetString() }
};

mappings.Add(mappingKey, files);
Expand Down Expand Up @@ -1671,7 +1671,7 @@ private static void ReadScripts(ref Utf8JsonStreamReader jsonReader, PackageSpec
{
if (jsonReader.TokenType == JsonTokenType.String)
{
packageSpec.Scripts[propertyName] = new string[] { (string)jsonReader.GetString() };
packageSpec.Scripts[propertyName] = new string[] { jsonReader.GetString() };
}
else if (jsonReader.TokenType == JsonTokenType.StartArray)
{
Expand Down
4 changes: 2 additions & 2 deletions src/NuGet.Core/NuGet.ProjectModel/Utf8JsonStreamReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ internal IReadOnlyList<string> ReadNextStringOrArrayOfStringsAsReadOnlyList()
switch (_reader.TokenType)
{
case JsonTokenType.String:
return new[] { (string)_reader.GetString() };
return new[] { _reader.GetString() };

case JsonTokenType.StartArray:
return ReadStringArrayAsReadOnlyListFromArrayStart();
Expand Down Expand Up @@ -312,7 +312,7 @@ private void GetMoreBytesFromStream()
}

/// <summary>
/// Loops through the stream and reads it into the buffer until the buffer is full or the stream is empty, creates the Utf8JsonReader.
/// Loops through the stream and reads it into the buffer until the buffer is full or the stream is empty, creates the Utf8JsonReader.
/// </summary>
private void ReadStreamIntoBuffer(JsonReaderState jsonReaderState)
{
Expand Down

0 comments on commit 2762484

Please sign in to comment.