Skip to content

Commit 1621924

Browse files
committed
Use explicit type instead of var
1 parent ef76f87 commit 1621924

31 files changed

+193
-191
lines changed

src/code/ContainerRegistryServerAPICalls.cs

Lines changed: 33 additions & 33 deletions
Large diffs are not rendered by default.

src/code/FindHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,7 @@ internal IEnumerable<PSResourceInfo> FindDependencyPackages(
10931093
{
10941094
if (currentPkg.Dependencies.Length > 0)
10951095
{
1096-
foreach (var dep in currentPkg.Dependencies)
1096+
foreach (Dependency dep in currentPkg.Dependencies)
10971097
{
10981098
PSResourceInfo depPkg = null;
10991099

src/code/FindPSResource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ protected override void BeginProcessing()
117117
{
118118
_cancellationTokenSource = new CancellationTokenSource();
119119

120-
var networkCred = Credential != null ? new NetworkCredential(Credential.UserName, Credential.Password) : null;
120+
NetworkCredential networkCred = Credential != null ? new NetworkCredential(Credential.UserName, Credential.Password) : null;
121121

122122
_findHelper = new FindHelper(
123123
cancellationToken: _cancellationTokenSource.Token,

src/code/GetHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public IEnumerable<PSResourceInfo> GetInstalledPackages(
4444
List<string> pathsToSearch)
4545
{
4646
_cmdletPassedIn.WriteDebug("In GetHelper::GetInstalledPackages()");
47-
foreach (var pkg in pkgs)
47+
foreach (PSResourceInfo pkg in pkgs)
4848
{
4949
// Parse Normalized version if present, if not use Version property of the package
5050
NuGetVersion nugetVersion = null;
@@ -69,7 +69,7 @@ public IEnumerable<PSResourceInfo> GetInstalledPackages(
6969
includeMaxVersion: true);
7070

7171
// Search by package name.
72-
var foundPkgPaths = FilterPkgPathsByName(
72+
List<string> foundPkgPaths = FilterPkgPathsByName(
7373
names: new string[] { pkg.Name },
7474
pathsToSearch);
7575

src/code/GetInstalledPSResource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ protected override void BeginProcessing()
8484
if (Path != null)
8585
{
8686
WriteDebug($"Provided path is: '{Path}'");
87-
var resolvedPaths = GetResolvedProviderPathFromPSPath(Path, out ProviderInfo provider);
87+
System.Collections.ObjectModel.Collection<string> resolvedPaths = GetResolvedProviderPathFromPSPath(Path, out ProviderInfo provider);
8888
if (resolvedPaths.Count != 1)
8989
{
9090
ThrowTerminatingError(new ErrorRecord(

src/code/GetPSScriptFileInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected override void EndProcessing()
3838
this));
3939
}
4040

41-
var resolvedPaths = GetResolvedProviderPathFromPSPath(Path, out ProviderInfo provider);
41+
System.Collections.ObjectModel.Collection<string> resolvedPaths = GetResolvedProviderPathFromPSPath(Path, out ProviderInfo provider);
4242
if (resolvedPaths.Count != 1)
4343
{
4444
ThrowTerminatingError(new ErrorRecord(

src/code/GroupPolicyRepositoryEnforcement.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static bool IsGroupPolicyEnabled()
4242
return InternalHooks.GPEnabledStatus;
4343
}
4444

45-
var values = ReadGPFromRegistry();
45+
List<KeyValuePair<string, Uri>>? values = ReadGPFromRegistry();
4646

4747
if (values is not null && values.Count > 0)
4848
{
@@ -78,11 +78,11 @@ public static bool IsGroupPolicyEnabled()
7878
{
7979
List<Uri> allowedUris = new List<Uri>();
8080

81-
var allowedRepositories = ReadGPFromRegistry();
81+
List<KeyValuePair<string, Uri>>? allowedRepositories = ReadGPFromRegistry();
8282

8383
if (allowedRepositories is not null && allowedRepositories.Count > 0)
8484
{
85-
foreach (var allowedRepository in allowedRepositories)
85+
foreach (KeyValuePair<string, Uri> allowedRepository in allowedRepositories)
8686
{
8787
allowedUris.Add(allowedRepository.Value);
8888
}
@@ -98,7 +98,7 @@ internal static bool IsRepositoryAllowed(Uri repositoryUri)
9898

9999
if (GroupPolicyRepositoryEnforcement.IsGroupPolicyEnabled())
100100
{
101-
var allowedList = GroupPolicyRepositoryEnforcement.GetAllowedRepositoryURIs();
101+
Uri[]? allowedList = GroupPolicyRepositoryEnforcement.GetAllowedRepositoryURIs();
102102

103103
if (allowedList != null && allowedList.Length > 0)
104104
{
@@ -117,7 +117,7 @@ internal static bool IsRepositoryAllowed(Uri repositoryUri)
117117
{
118118
List<KeyValuePair<string, Uri>> allowedRepositories = new List<KeyValuePair<string, Uri>>();
119119

120-
using (var key = Registry.CurrentUser.OpenSubKey(gpRootPath))
120+
using (RegistryKey? key = Registry.CurrentUser.OpenSubKey(gpRootPath))
121121
{
122122
if (key is null)
123123
{
@@ -138,7 +138,7 @@ internal static bool IsRepositoryAllowed(Uri repositoryUri)
138138
continue;
139139
}
140140

141-
using (var psrgKey = key.OpenSubKey(subKey + "\\" + psresourcegetGPPath))
141+
using (RegistryKey? psrgKey = key.OpenSubKey(subKey + "\\" + psresourcegetGPPath))
142142
{
143143
if (psrgKey is null)
144144
{
@@ -170,7 +170,7 @@ internal static bool IsRepositoryAllowed(Uri repositoryUri)
170170
}
171171

172172
string valueString = value.ToString();
173-
var kvRegValue = ConvertRegValue(valueString);
173+
KeyValuePair<string, Uri> kvRegValue = ConvertRegValue(valueString);
174174
allowedRepositories.Add(kvRegValue);
175175
}
176176
}

src/code/InstallHelper.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ private List<PSResourceInfo> ProcessRepositories(
257257
return allPkgsInstalled;
258258
}
259259

260-
var listOfRepositories = RepositorySettings.Read(repository, out string[] _);
260+
List<PSRepositoryInfo> listOfRepositories = RepositorySettings.Read(repository, out string[] _);
261261
var yesToAll = false;
262262
var noToAll = false;
263263

@@ -866,12 +866,12 @@ private string CreateInstallationTempPath()
866866

867867
try
868868
{
869-
var dir = Directory.CreateDirectory(tempInstallPath); // should check it gets created properly
870-
// To delete file attributes from the existing ones get the current file attributes first and use AND (&) operator
871-
// with a mask (bitwise complement of desired attributes combination).
872-
// TODO: check the attributes and if it's read only then set it
873-
// attribute may be inherited from the parent
874-
// TODO: are there Linux accommodations we need to consider here?
869+
DirectoryInfo dir = Directory.CreateDirectory(tempInstallPath); // should check it gets created properly
870+
// To delete file attributes from the existing ones get the current file attributes first and use AND (&) operator
871+
// with a mask (bitwise complement of desired attributes combination).
872+
// TODO: check the attributes and if it's read only then set it
873+
// attribute may be inherited from the parent
874+
// TODO: are there Linux accommodations we need to consider here?
875875
dir.Attributes &= ~FileAttributes.ReadOnly;
876876
}
877877
catch (Exception e)
@@ -926,7 +926,7 @@ private bool TryInstallToTempPath(
926926
try
927927
{
928928
var pathToFile = Path.Combine(tempInstallPath, $"{pkgName}.{normalizedPkgVersion}.zip");
929-
using var fs = File.Create(pathToFile);
929+
using FileStream fs = File.Create(pathToFile);
930930
responseStream.Seek(0, System.IO.SeekOrigin.Begin);
931931
responseStream.CopyTo(fs);
932932
fs.Close();
@@ -1105,7 +1105,7 @@ private bool TrySaveNupkgToTempPath(
11051105
try
11061106
{
11071107
var pathToFile = Path.Combine(tempInstallPath, $"{pkgName}.{normalizedPkgVersion}.zip");
1108-
using var fs = File.Create(pathToFile);
1108+
using FileStream fs = File.Create(pathToFile);
11091109
responseStream.Seek(0, System.IO.SeekOrigin.Begin);
11101110
responseStream.CopyTo(fs);
11111111
fs.Close();
@@ -1419,7 +1419,7 @@ private bool DetectClobber(string pkgName, Hashtable parsedMetadataHashtable, ou
14191419
}
14201420
}
14211421

1422-
foreach (var pkg in pkgsAlreadyInstalled)
1422+
foreach (PSResourceInfo pkg in pkgsAlreadyInstalled)
14231423
{
14241424
List<string> duplicateCmdlets = new();
14251425
List<string> duplicateCmds = new();

src/code/InstallPSResource.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ protected override void BeginProcessing()
270270
// Only need to find packages installed if -Reinstall is not passed in
271271
_packagesOnMachine = Reinstall ? new HashSet<string>(StringComparer.CurrentCultureIgnoreCase) : Utils.GetInstalledPackages(pathsToSearch, this);
272272

273-
var networkCred = Credential != null ? new NetworkCredential(Credential.UserName, Credential.Password) : null;
273+
NetworkCredential networkCred = Credential != null ? new NetworkCredential(Credential.UserName, Credential.Password) : null;
274274

275275
_installHelper = new InstallHelper(cmdletPassedIn: this, networkCredential: networkCred);
276276
}
@@ -290,7 +290,7 @@ protected override void ProcessRecord()
290290
break;
291291

292292
case InputObjectParameterSet:
293-
foreach (var inputObj in InputObject)
293+
foreach (PSResourceInfo inputObj in InputObject)
294294
{
295295
string normalizedVersionString = Utils.GetNormalizedVersionString(inputObj.Version.ToString(), inputObj.Prerelease);
296296
ProcessInstallHelper(
@@ -468,7 +468,7 @@ private void RequiredResourceHelper(Hashtable reqResourceHash)
468468
// Install-PSResource -RequiredResource @ { MyPackage = @{ version = '1.2.3', repository = 'PSGallery' } }
469469
if (pkgInstallInfo.Count != 0)
470470
{
471-
var pkgParamNames = pkgInstallInfo.Keys;
471+
ICollection pkgParamNames = pkgInstallInfo.Keys;
472472

473473
foreach (string paramName in pkgParamNames)
474474
{
@@ -550,7 +550,7 @@ private void ProcessInstallHelper(string[] pkgNames, string pkgVersion, bool pkg
550550
this));
551551
}
552552

553-
var installedPkgs = _installHelper.BeginInstallPackages(
553+
IEnumerable<PSResourceInfo> installedPkgs = _installHelper.BeginInstallPackages(
554554
names: pkgNames,
555555
versionRange: versionRange,
556556
nugetVersion: nugetVersion,

src/code/InternalHooks.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public class InternalHooks
1919

2020
public static void SetTestHook(string property, object value)
2121
{
22-
var fieldInfo = typeof(InternalHooks).GetField(property, BindingFlags.Static | BindingFlags.NonPublic);
22+
FieldInfo fieldInfo = typeof(InternalHooks).GetField(property, BindingFlags.Static | BindingFlags.NonPublic);
2323
fieldInfo?.SetValue(null, value);
2424
}
2525
}
26-
}
26+
}

0 commit comments

Comments
 (0)