mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
[Feature] Address Feedback: style changes and fixing typo
This commit is contained in:
@@ -665,7 +665,8 @@ namespace System.Management.Automation
|
||||
/// </summary>
|
||||
private ExperimentAction EffectiveAction
|
||||
{
|
||||
get {
|
||||
get
|
||||
{
|
||||
if (_effectiveAction == ExperimentAction.None)
|
||||
{
|
||||
_effectiveAction = ExperimentalFeature.GetActionToTake(ExperimentName, ExperimentAction);
|
||||
|
||||
@@ -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
|
||||
|
||||
+4
-8
@@ -26,7 +26,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// Search module paths to find all available experimental features.
|
||||
/// </summary>
|
||||
[Parameter()]
|
||||
[Parameter]
|
||||
public SwitchParameter ListAvailable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -66,10 +66,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
return "0:" + feature.Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "1:" + feature.Name;
|
||||
}
|
||||
return "1:" + feature.Name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -103,8 +100,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
var featuresFromGivenModules = new Dictionary<string, ExperimentalFeature>(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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1503,16 +1503,18 @@ namespace System.Management.Automation
|
||||
{
|
||||
try
|
||||
{
|
||||
var expAttribute = member.GetCustomAttributes<ExperimentalAttribute>(false).FirstOrDefault();
|
||||
var expAttribute = member.GetCustomAttributes<ExperimentalAttribute>(inherit: false).FirstOrDefault();
|
||||
if (expAttribute != null && expAttribute.ToHide) { return false; }
|
||||
|
||||
var hasAnyVisibleParamAttributes = false;
|
||||
var paramAttributes = member.GetCustomAttributes<ParameterAttribute>(false);
|
||||
var paramAttributes = member.GetCustomAttributes<ParameterAttribute>(inherit: false);
|
||||
foreach (var paramAttribute in paramAttributes)
|
||||
{
|
||||
if (paramAttribute.ToHide) { continue; }
|
||||
hasAnyVisibleParamAttributes = true;
|
||||
break;
|
||||
if (!paramAttribute.ToHide)
|
||||
{
|
||||
hasAnyVisibleParamAttributes = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return hasAnyVisibleParamAttributes;
|
||||
}
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -213,4 +213,4 @@ namespace ExperimentalFeatureTest
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user