From b616cf578aed6c6e3d36c51c5c89bc86533f4621 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Mon, 9 Jul 2018 17:17:12 -0700 Subject: [PATCH] [Feature] Address Feedback: style changes and fixing typo --- .../engine/Attributes.cs | 3 ++- .../engine/CommandProcessorBase.cs | 2 +- .../GetExperimentalFeatureCommand.cs | 12 ++++------ .../engine/Modules/AnalysisCache.cs | 4 ++-- .../engine/PseudoParameters.cs | 2 +- .../engine/SessionState.cs | 22 +++++++++---------- .../engine/TypeMetadata.cs | 12 +++++----- .../engine/parser/ast.cs | 4 ++-- .../ExperimentalFeature.Basic.Tests.ps1 | 2 +- .../assets/ExpTest/ExpTest.cs | 2 +- 10 files changed, 32 insertions(+), 33 deletions(-) diff --git a/src/System.Management.Automation/engine/Attributes.cs b/src/System.Management.Automation/engine/Attributes.cs index 92b3923143..e22e597585 100644 --- a/src/System.Management.Automation/engine/Attributes.cs +++ b/src/System.Management.Automation/engine/Attributes.cs @@ -665,7 +665,8 @@ namespace System.Management.Automation /// private ExperimentAction EffectiveAction { - get { + get + { if (_effectiveAction == ExperimentAction.None) { _effectiveAction = ExperimentalFeature.GetActionToTake(ExperimentName, ExperimentAction); diff --git a/src/System.Management.Automation/engine/CommandProcessorBase.cs b/src/System.Management.Automation/engine/CommandProcessorBase.cs index 475718f619..38c364ea2b 100644 --- a/src/System.Management.Automation/engine/CommandProcessorBase.cs +++ b/src/System.Management.Automation/engine/CommandProcessorBase.cs @@ -43,7 +43,7 @@ namespace System.Management.Automation if (commandInfo is IScriptCommandInfo scriptCommand) { - var expAttribute = scriptCommand.ScriptBlock.ExperimentalAttribute; + ExperimentalAttribute expAttribute = scriptCommand.ScriptBlock.ExperimentalAttribute; if (expAttribute != null && expAttribute.ToHide) { string errorTemplate = expAttribute.ExperimentAction == ExperimentAction.Hide diff --git a/src/System.Management.Automation/engine/ExperimentalFeature/GetExperimentalFeatureCommand.cs b/src/System.Management.Automation/engine/ExperimentalFeature/GetExperimentalFeatureCommand.cs index 2ab20492d1..f526870288 100644 --- a/src/System.Management.Automation/engine/ExperimentalFeature/GetExperimentalFeatureCommand.cs +++ b/src/System.Management.Automation/engine/ExperimentalFeature/GetExperimentalFeatureCommand.cs @@ -26,7 +26,7 @@ namespace Microsoft.PowerShell.Commands /// /// Search module paths to find all available experimental features. /// - [Parameter()] + [Parameter] public SwitchParameter ListAvailable { get; set; } /// @@ -66,10 +66,7 @@ namespace Microsoft.PowerShell.Commands { return "0:" + feature.Name; } - else - { - return "1:" + feature.Name; - } + return "1:" + feature.Name; } /// @@ -103,8 +100,7 @@ namespace Microsoft.PowerShell.Commands var featuresFromGivenModules = new Dictionary(StringComparer.OrdinalIgnoreCase); foreach (string moduleFile in GetValidModuleFiles(moduleNames)) { - ExperimentalFeature[] features = ModuleIntrinsics.GetExperimentalFeature(moduleFile); - foreach (var feature in features) + foreach (var feature in ModuleIntrinsics.GetExperimentalFeature(moduleFile)) { featuresFromGivenModules.TryAdd(feature.Name, feature); } @@ -177,4 +173,4 @@ namespace Microsoft.PowerShell.Commands } } } -} \ No newline at end of file +} diff --git a/src/System.Management.Automation/engine/Modules/AnalysisCache.cs b/src/System.Management.Automation/engine/Modules/AnalysisCache.cs index d9b6d243d5..35aa09e4ab 100644 --- a/src/System.Management.Automation/engine/Modules/AnalysisCache.cs +++ b/src/System.Management.Automation/engine/Modules/AnalysisCache.cs @@ -1048,13 +1048,13 @@ namespace System.Management.Automation // to generate the cache file name. int index = 0; string[] featureNames = new string[ExperimentalFeature.EnabledExperimentalFeatureNames.Count]; - foreach (var featureName in ExperimentalFeature.EnabledExperimentalFeatureNames) + foreach (string featureName in ExperimentalFeature.EnabledExperimentalFeatureNames) { featureNames[index++] = featureName.ToLowerInvariant(); } Array.Sort(featureNames); - string allNames = String.Join(Environment.NewLine, featureNames); + string allNames = string.Join(Environment.NewLine, featureNames); // Use SHA1 because it's faster. // It's very unlikely to get colision from hashing the combinations of enabled features names. diff --git a/src/System.Management.Automation/engine/PseudoParameters.cs b/src/System.Management.Automation/engine/PseudoParameters.cs index e73ea5fb79..06d4a0cca6 100644 --- a/src/System.Management.Automation/engine/PseudoParameters.cs +++ b/src/System.Management.Automation/engine/PseudoParameters.cs @@ -174,7 +174,7 @@ namespace System.Management.Automation bool hasEnabledParamAttribute = false; bool hasSeenExpAttribute = false; - foreach (var attr in Attributes) + foreach (Attribute attr in Attributes) { if (!hasSeenExpAttribute && attr is ExperimentalAttribute expAttribute) { diff --git a/src/System.Management.Automation/engine/SessionState.cs b/src/System.Management.Automation/engine/SessionState.cs index 311b904ccb..64a4838a63 100644 --- a/src/System.Management.Automation/engine/SessionState.cs +++ b/src/System.Management.Automation/engine/SessionState.cs @@ -301,7 +301,7 @@ namespace System.Management.Automation ExecutionContext.EngineHostInterface, ScopedItemOptions.Constant | ScopedItemOptions.AllScope, RunspaceInit.PSHostDescription); - this.GlobalScope.SetVariable(v.Name, v, false, true, this, CommandOrigin.Internal, fastPath: true); + this.GlobalScope.SetVariable(v.Name, v, asValue: false, force: true, this, CommandOrigin.Internal, fastPath: true); // $HOME - indicate where a user's home directory is located in the file system. // -- %USERPROFILE% on windows @@ -311,28 +311,28 @@ namespace System.Management.Automation home, ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope, RunspaceInit.HOMEDescription); - this.GlobalScope.SetVariable(v.Name, v, false, true, this, CommandOrigin.Internal, fastPath: true); + this.GlobalScope.SetVariable(v.Name, v, asValue: false, force: true, this, CommandOrigin.Internal, fastPath: true); // $ExecutionContext v = new PSVariable(SpecialVariables.ExecutionContext, ExecutionContext.EngineIntrinsics, ScopedItemOptions.Constant | ScopedItemOptions.AllScope, RunspaceInit.ExecutionContextDescription); - this.GlobalScope.SetVariable(v.Name, v, false, true, this, CommandOrigin.Internal, fastPath: true); + this.GlobalScope.SetVariable(v.Name, v, asValue: false, force: true, this, CommandOrigin.Internal, fastPath: true); // $PSVersionTable v = new PSVariable(SpecialVariables.PSVersionTable, PSVersionInfo.GetPSVersionTable(), ScopedItemOptions.Constant | ScopedItemOptions.AllScope, RunspaceInit.PSVersionTableDescription); - this.GlobalScope.SetVariable(v.Name, v, false, true, this, CommandOrigin.Internal, fastPath: true); + this.GlobalScope.SetVariable(v.Name, v, asValue: false, force: true, this, CommandOrigin.Internal, fastPath: true); // $PSEdition v = new PSVariable(SpecialVariables.PSEdition, PSVersionInfo.PSEditionValue, ScopedItemOptions.Constant | ScopedItemOptions.AllScope, RunspaceInit.PSEditionDescription); - this.GlobalScope.SetVariable(v.Name, v, false, true, this, CommandOrigin.Internal, fastPath: true); + this.GlobalScope.SetVariable(v.Name, v, asValue: false, force: true, this, CommandOrigin.Internal, fastPath: true); // $PID Process currentProcess = Process.GetCurrentProcess(); @@ -341,15 +341,15 @@ namespace System.Management.Automation currentProcess.Id, ScopedItemOptions.Constant | ScopedItemOptions.AllScope, RunspaceInit.PIDDescription); - this.GlobalScope.SetVariable(v.Name, v, false, true, this, CommandOrigin.Internal, fastPath: true); + this.GlobalScope.SetVariable(v.Name, v, asValue: false, force: true, this, CommandOrigin.Internal, fastPath: true); // $PSCulture v = new PSCultureVariable(); - this.GlobalScope.SetVariable(v.Name, v, false, true, this, CommandOrigin.Internal, fastPath: true); + this.GlobalScope.SetVariable(v.Name, v, asValue: false, force: true, this, CommandOrigin.Internal, fastPath: true); // $PSUICulture v = new PSUICultureVariable(); - this.GlobalScope.SetVariable(v.Name, v, false, true, this, CommandOrigin.Internal, fastPath: true); + this.GlobalScope.SetVariable(v.Name, v, asValue: false, force: true, this, CommandOrigin.Internal, fastPath: true); // $? v = new QuestionMarkVariable(this.ExecutionContext); @@ -360,21 +360,21 @@ namespace System.Management.Automation v = new PSVariable(SpecialVariables.ShellId, shellId, ScopedItemOptions.Constant | ScopedItemOptions.AllScope, RunspaceInit.MshShellIdDescription); - this.GlobalScope.SetVariable(v.Name, v, false, true, this, CommandOrigin.Internal, fastPath: true); + this.GlobalScope.SetVariable(v.Name, v, asValue: false, force: true, this, CommandOrigin.Internal, fastPath: true); // $PSHOME string applicationBase = Utils.DefaultPowerShellAppBase; v = new PSVariable(SpecialVariables.PSHome, applicationBase, ScopedItemOptions.Constant | ScopedItemOptions.AllScope, RunspaceInit.PSHOMEDescription); - this.GlobalScope.SetVariable(v.Name, v, false, true, this, CommandOrigin.Internal, fastPath: true); + this.GlobalScope.SetVariable(v.Name, v, asValue: false, force: true, this, CommandOrigin.Internal, fastPath: true); // $EnabledExperimentalFeatures v = new PSVariable(SpecialVariables.EnabledExperimentalFeatures, ExperimentalFeature.EnabledExperimentalFeatureNames, ScopedItemOptions.Constant | ScopedItemOptions.AllScope, RunspaceInit.EnabledExperimentalFeatures); - this.GlobalScope.SetVariable(v.Name, v, false, true, this, CommandOrigin.Internal, fastPath: true); + this.GlobalScope.SetVariable(v.Name, v, asValue: false, force: true, this, CommandOrigin.Internal, fastPath: true); } /// diff --git a/src/System.Management.Automation/engine/TypeMetadata.cs b/src/System.Management.Automation/engine/TypeMetadata.cs index 074a306a5f..b07501d7dd 100644 --- a/src/System.Management.Automation/engine/TypeMetadata.cs +++ b/src/System.Management.Automation/engine/TypeMetadata.cs @@ -1503,16 +1503,18 @@ namespace System.Management.Automation { try { - var expAttribute = member.GetCustomAttributes(false).FirstOrDefault(); + var expAttribute = member.GetCustomAttributes(inherit: false).FirstOrDefault(); if (expAttribute != null && expAttribute.ToHide) { return false; } var hasAnyVisibleParamAttributes = false; - var paramAttributes = member.GetCustomAttributes(false); + var paramAttributes = member.GetCustomAttributes(inherit: false); foreach (var paramAttribute in paramAttributes) { - if (paramAttribute.ToHide) { continue; } - hasAnyVisibleParamAttributes = true; - break; + if (!paramAttribute.ToHide) + { + hasAnyVisibleParamAttributes = true; + break; + } } return hasAnyVisibleParamAttributes; } diff --git a/src/System.Management.Automation/engine/parser/ast.cs b/src/System.Management.Automation/engine/parser/ast.cs index 2a9757b54b..66722983b2 100644 --- a/src/System.Management.Automation/engine/parser/ast.cs +++ b/src/System.Management.Automation/engine/parser/ast.cs @@ -1375,8 +1375,8 @@ namespace System.Management.Automation.Language { for (int index = 0; index < Attributes.Count; index++) { - var attributeAst = Attributes[index]; - var expAttr = GetExpAttributeHelper(attributeAst); + AttributeAst attributeAst = Attributes[index]; + ExperimentalAttribute expAttr = GetExpAttributeHelper(attributeAst); if (expAttr != null) { yield return expAttr; } } diff --git a/test/powershell/engine/ExperimentalFeature/ExperimentalFeature.Basic.Tests.ps1 b/test/powershell/engine/ExperimentalFeature/ExperimentalFeature.Basic.Tests.ps1 index aef45ceea6..21baa4646e 100644 --- a/test/powershell/engine/ExperimentalFeature/ExperimentalFeature.Basic.Tests.ps1 +++ b/test/powershell/engine/ExperimentalFeature/ExperimentalFeature.Basic.Tests.ps1 @@ -34,7 +34,7 @@ Describe "Experimental Feature Basic Tests - Feature-Disabled" -tags "CI" { } } - It "No experimental features is enabled" { + It "No experimental feature is enabled" { $EnabledExperimentalFeatures.Count | Should -Be 0 } diff --git a/test/powershell/engine/ExperimentalFeature/assets/ExpTest/ExpTest.cs b/test/powershell/engine/ExperimentalFeature/assets/ExpTest/ExpTest.cs index af6fdb5c3f..20e25bbd85 100644 --- a/test/powershell/engine/ExperimentalFeature/assets/ExpTest/ExpTest.cs +++ b/test/powershell/engine/ExperimentalFeature/assets/ExpTest/ExpTest.cs @@ -213,4 +213,4 @@ namespace ExperimentalFeatureTest } #endregion -} \ No newline at end of file +}