mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Fix IDE0090: Simplify new expression part 4.6 (#14260)
https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0090
This commit is contained in:
@@ -341,9 +341,9 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
private void ProcessExpressionParameter()
|
||||
{
|
||||
TerminatingErrorContext invocationContext = new TerminatingErrorContext(this);
|
||||
TerminatingErrorContext invocationContext = new(this);
|
||||
ParameterProcessor processor =
|
||||
new ParameterProcessor(new SelectObjectExpressionParameterDefinition());
|
||||
new(new SelectObjectExpressionParameterDefinition());
|
||||
if ((Property != null) && (Property.Length != 0))
|
||||
{
|
||||
// Build property list taking into account the wildcards and @{name=;expression=}
|
||||
@@ -382,7 +382,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
|
||||
// If property parameter is mentioned
|
||||
List<PSNoteProperty> matchedProperties = new List<PSNoteProperty>();
|
||||
List<PSNoteProperty> matchedProperties = new();
|
||||
foreach (MshParameter p in _propertyMshParameterList)
|
||||
{
|
||||
ProcessParameter(p, inputObject, matchedProperties);
|
||||
@@ -390,10 +390,10 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
if (string.IsNullOrEmpty(ExpandProperty))
|
||||
{
|
||||
PSObject result = new PSObject();
|
||||
PSObject result = new();
|
||||
if (matchedProperties.Count != 0)
|
||||
{
|
||||
HashSet<string> propertyNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
HashSet<string> propertyNames = new(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
foreach (PSNoteProperty noteProperty in matchedProperties)
|
||||
{
|
||||
@@ -431,7 +431,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
string name = p.GetEntry(NameEntryDefinition.NameEntryKey) as string;
|
||||
|
||||
PSPropertyExpression ex = p.GetEntry(FormatParameterDefinitionKeys.ExpressionEntryKey) as PSPropertyExpression;
|
||||
List<PSPropertyExpressionResult> expressionResults = new List<PSPropertyExpressionResult>();
|
||||
List<PSPropertyExpressionResult> expressionResults = new();
|
||||
foreach (PSPropertyExpression resolvedName in ex.ResolveNames(inputObject))
|
||||
{
|
||||
if (_exclusionFilter == null || !_exclusionFilter.IsMatch(resolvedName))
|
||||
@@ -456,7 +456,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
else if (!string.IsNullOrEmpty(name) && expressionResults.Count > 1)
|
||||
{
|
||||
string errorMsg = SelectObjectStrings.RenamingMultipleResults;
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
ErrorRecord errorRecord = new(
|
||||
new InvalidOperationException(errorMsg),
|
||||
"RenamingMultipleResults",
|
||||
ErrorCategory.InvalidOperation,
|
||||
@@ -506,7 +506,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
if (expressionResults.Count == 0)
|
||||
{
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
ErrorRecord errorRecord = new(
|
||||
PSTraceSource.NewArgumentException("ExpandProperty", SelectObjectStrings.PropertyNotFound, ExpandProperty),
|
||||
"ExpandPropertyNotFound",
|
||||
ErrorCategory.InvalidArgument,
|
||||
@@ -516,7 +516,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
if (expressionResults.Count > 1)
|
||||
{
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
ErrorRecord errorRecord = new(
|
||||
PSTraceSource.NewArgumentException("ExpandProperty", SelectObjectStrings.MutlipleExpandProperties, ExpandProperty),
|
||||
"MutlipleExpandProperties",
|
||||
ErrorCategory.InvalidArgument,
|
||||
@@ -563,7 +563,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
else
|
||||
{
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
ErrorRecord errorRecord = new(
|
||||
r.Exception,
|
||||
"PropertyEvaluationExpand",
|
||||
ErrorCategory.InvalidResult,
|
||||
@@ -596,7 +596,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
private void WriteAlreadyExistingPropertyError(string name, object inputObject, string errorId)
|
||||
{
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
ErrorRecord errorRecord = new(
|
||||
PSTraceSource.NewArgumentException("Property", SelectObjectStrings.AlreadyExistingProperty, name),
|
||||
errorId,
|
||||
ErrorCategory.InvalidOperation,
|
||||
@@ -624,7 +624,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
bool isObjUnique = true;
|
||||
foreach (UniquePSObjectHelper uniqueObj in _uniques)
|
||||
{
|
||||
ObjectCommandComparer comparer = new ObjectCommandComparer(true, CultureInfo.CurrentCulture, true);
|
||||
ObjectCommandComparer comparer = new(true, CultureInfo.CurrentCulture, true);
|
||||
if ((comparer.Compare(obj.BaseObject, uniqueObj.WrittenObject.BaseObject) == 0) &&
|
||||
(uniqueObj.NotePropertyCount == addedNoteProperties.Count))
|
||||
{
|
||||
|
||||
@@ -173,7 +173,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
#region Private variables and methods
|
||||
|
||||
// Instantiate a new instance of MailMessage
|
||||
private readonly MailMessage _mMailMessage = new MailMessage();
|
||||
private readonly MailMessage _mMailMessage = new();
|
||||
|
||||
private SmtpClient _mSmtpClient = null;
|
||||
|
||||
@@ -216,7 +216,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
catch (FormatException e)
|
||||
{
|
||||
ErrorRecord er = new ErrorRecord(e, "FormatException", ErrorCategory.InvalidType, null);
|
||||
ErrorRecord er = new(e, "FormatException", ErrorCategory.InvalidType, null);
|
||||
WriteError(er);
|
||||
continue;
|
||||
}
|
||||
@@ -239,7 +239,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
catch (FormatException e)
|
||||
{
|
||||
ErrorRecord er = new ErrorRecord(e, "FormatException", ErrorCategory.InvalidType, From);
|
||||
ErrorRecord er = new(e, "FormatException", ErrorCategory.InvalidType, From);
|
||||
ThrowTerminatingError(er);
|
||||
}
|
||||
|
||||
@@ -294,7 +294,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
if (string.IsNullOrEmpty(SmtpServer))
|
||||
{
|
||||
ErrorRecord er = new ErrorRecord(new InvalidOperationException(SendMailMessageStrings.HostNameValue), null, ErrorCategory.InvalidArgument, null);
|
||||
ErrorRecord er = new(new InvalidOperationException(SendMailMessageStrings.HostNameValue), null, ErrorCategory.InvalidArgument, null);
|
||||
this.ThrowTerminatingError(er);
|
||||
}
|
||||
|
||||
@@ -344,7 +344,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
PathUtils.ReportFileOpenFailure(this, filepath, e);
|
||||
}
|
||||
|
||||
Attachment mailAttachment = new Attachment(filepath);
|
||||
Attachment mailAttachment = new(filepath);
|
||||
_mMailMessage.Attachments.Add(mailAttachment);
|
||||
}
|
||||
}
|
||||
@@ -362,30 +362,30 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
catch (SmtpFailedRecipientsException ex)
|
||||
{
|
||||
ErrorRecord er = new ErrorRecord(ex, "SmtpFailedRecipientsException", ErrorCategory.InvalidOperation, _mSmtpClient);
|
||||
ErrorRecord er = new(ex, "SmtpFailedRecipientsException", ErrorCategory.InvalidOperation, _mSmtpClient);
|
||||
WriteError(er);
|
||||
}
|
||||
catch (SmtpException ex)
|
||||
{
|
||||
if (ex.InnerException != null)
|
||||
{
|
||||
ErrorRecord er = new ErrorRecord(new SmtpException(ex.InnerException.Message), "SmtpException", ErrorCategory.InvalidOperation, _mSmtpClient);
|
||||
ErrorRecord er = new(new SmtpException(ex.InnerException.Message), "SmtpException", ErrorCategory.InvalidOperation, _mSmtpClient);
|
||||
WriteError(er);
|
||||
}
|
||||
else
|
||||
{
|
||||
ErrorRecord er = new ErrorRecord(ex, "SmtpException", ErrorCategory.InvalidOperation, _mSmtpClient);
|
||||
ErrorRecord er = new(ex, "SmtpException", ErrorCategory.InvalidOperation, _mSmtpClient);
|
||||
WriteError(er);
|
||||
}
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
ErrorRecord er = new ErrorRecord(ex, "InvalidOperationException", ErrorCategory.InvalidOperation, _mSmtpClient);
|
||||
ErrorRecord er = new(ex, "InvalidOperationException", ErrorCategory.InvalidOperation, _mSmtpClient);
|
||||
WriteError(er);
|
||||
}
|
||||
catch (System.Security.Authentication.AuthenticationException ex)
|
||||
{
|
||||
ErrorRecord er = new ErrorRecord(ex, "AuthenticationException", ErrorCategory.InvalidOperation, _mSmtpClient);
|
||||
ErrorRecord er = new(ex, "AuthenticationException", ErrorCategory.InvalidOperation, _mSmtpClient);
|
||||
WriteError(er);
|
||||
}
|
||||
finally
|
||||
|
||||
@@ -123,7 +123,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
protected override void ProcessRecord()
|
||||
{
|
||||
// If there is a script, resolve its path
|
||||
Collection<string> scripts = new Collection<string>();
|
||||
Collection<string> scripts = new();
|
||||
|
||||
if (Script != null)
|
||||
{
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
// Create the alias info
|
||||
|
||||
AliasInfo aliasToSet =
|
||||
new AliasInfo(
|
||||
new(
|
||||
Name,
|
||||
Value,
|
||||
Context,
|
||||
|
||||
@@ -77,7 +77,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
#else
|
||||
// build up the SystemTime struct to pass to SetSystemTime
|
||||
NativeMethods.SystemTime systemTime = new NativeMethods.SystemTime();
|
||||
NativeMethods.SystemTime systemTime = new();
|
||||
systemTime.Year = (UInt16)dateToUse.Year;
|
||||
systemTime.Month = (UInt16)dateToUse.Month;
|
||||
systemTime.Day = (UInt16)dateToUse.Day;
|
||||
@@ -102,8 +102,8 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
|
||||
// output DateTime object wrapped in an PSObject with DisplayHint attached
|
||||
PSObject outputObj = new PSObject(dateToUse);
|
||||
PSNoteProperty note = new PSNoteProperty("DisplayHint", DisplayHint);
|
||||
PSObject outputObj = new(dateToUse);
|
||||
PSNoteProperty note = new("DisplayHint", DisplayHint);
|
||||
outputObj.Properties.Add(note);
|
||||
|
||||
WriteObject(outputObj);
|
||||
|
||||
+7
-7
@@ -50,7 +50,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// Record the EndProcessing error.
|
||||
/// </summary>
|
||||
private PSDataCollection<ErrorRecord> _errors = new PSDataCollection<ErrorRecord>();
|
||||
private PSDataCollection<ErrorRecord> _errors = new();
|
||||
|
||||
/// <summary>
|
||||
/// Field used for the NoCommonParameter parameter.
|
||||
@@ -174,7 +174,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
if (_showCommandProxy.ScreenHeight < this.Height)
|
||||
{
|
||||
ErrorRecord error = new ErrorRecord(
|
||||
ErrorRecord error = new(
|
||||
new NotSupportedException(string.Format(CultureInfo.CurrentUICulture, FormatAndOut_out_gridview.PropertyValidate, "Height", _showCommandProxy.ScreenHeight)),
|
||||
"PARAMETER_DATA_ERROR",
|
||||
ErrorCategory.InvalidData,
|
||||
@@ -184,7 +184,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
if (_showCommandProxy.ScreenWidth < this.Width)
|
||||
{
|
||||
ErrorRecord error = new ErrorRecord(
|
||||
ErrorRecord error = new(
|
||||
new NotSupportedException(string.Format(CultureInfo.CurrentUICulture, FormatAndOut_out_gridview.PropertyValidate, "Width", _showCommandProxy.ScreenWidth)),
|
||||
"PARAMETER_DATA_ERROR",
|
||||
ErrorCategory.InvalidData,
|
||||
@@ -233,7 +233,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
StringBuilder errorString = new StringBuilder();
|
||||
StringBuilder errorString = new();
|
||||
|
||||
for (int i = 0; i < _errors.Count; i++)
|
||||
{
|
||||
@@ -268,7 +268,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
private void RunScriptSilentlyAndWithErrorHookup(string script)
|
||||
{
|
||||
// errors are not created here, because there is a field for it used in the final pop up
|
||||
PSDataCollection<object> output = new PSDataCollection<object>();
|
||||
PSDataCollection<object> output = new();
|
||||
|
||||
output.DataAdded += this.Output_DataAdded;
|
||||
_errors.DataAdded += this.Error_DataAdded;
|
||||
@@ -286,7 +286,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// </summary>
|
||||
private void IssueErrorForNoCommand()
|
||||
{
|
||||
InvalidOperationException errorException = new InvalidOperationException(
|
||||
InvalidOperationException errorException = new(
|
||||
string.Format(
|
||||
CultureInfo.CurrentUICulture,
|
||||
FormatAndOut_out_gridview.CommandNotFound,
|
||||
@@ -299,7 +299,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// </summary>
|
||||
private void IssueErrorForMoreThanOneCommand()
|
||||
{
|
||||
InvalidOperationException errorException = new InvalidOperationException(
|
||||
InvalidOperationException errorException = new(
|
||||
string.Format(
|
||||
CultureInfo.CurrentUICulture,
|
||||
FormatAndOut_out_gridview.MoreThanOneCommand,
|
||||
|
||||
@@ -168,7 +168,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
try
|
||||
{
|
||||
ProcessStartInfo startInfo = new ProcessStartInfo();
|
||||
ProcessStartInfo startInfo = new();
|
||||
startInfo.FileName = tmpFilePath;
|
||||
startInfo.UseShellExecute = true;
|
||||
Process.Start(startInfo);
|
||||
|
||||
@@ -239,7 +239,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// </summary>
|
||||
protected override void EndProcessing()
|
||||
{
|
||||
OrderByProperty orderByProperty = new OrderByProperty(
|
||||
OrderByProperty orderByProperty = new(
|
||||
this, InputObjects, Property, !Descending, ConvertedCulture, CaseSensitive);
|
||||
|
||||
var dataToProcess = orderByProperty.OrderMatrix;
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
// object used for synchronizes pipeline thread and stop thread
|
||||
// access to waitHandle
|
||||
private readonly object _syncObject = new object();
|
||||
private readonly object _syncObject = new();
|
||||
|
||||
// this is set to true by stopProcessing
|
||||
private bool _stopping = false;
|
||||
|
||||
@@ -115,7 +115,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
e is SecurityException
|
||||
)
|
||||
{
|
||||
Exception exception = new Exception(
|
||||
Exception exception = new(
|
||||
string.Format(
|
||||
CultureInfo.CurrentUICulture,
|
||||
TestJsonCmdletStrings.JsonSchemaFileOpenFailure,
|
||||
@@ -125,7 +125,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Exception exception = new Exception(TestJsonCmdletStrings.InvalidJsonSchema, e);
|
||||
Exception exception = new(TestJsonCmdletStrings.InvalidJsonSchema, e);
|
||||
ThrowTerminatingError(new ErrorRecord(exception, "InvalidJsonSchema", ErrorCategory.InvalidData, resolvedpath));
|
||||
}
|
||||
}
|
||||
@@ -149,11 +149,11 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
result = false;
|
||||
|
||||
Exception exception = new Exception(TestJsonCmdletStrings.InvalidJsonAgainstSchema);
|
||||
Exception exception = new(TestJsonCmdletStrings.InvalidJsonAgainstSchema);
|
||||
|
||||
foreach (var message in errorMessages)
|
||||
{
|
||||
ErrorRecord errorRecord = new ErrorRecord(exception, "InvalidJsonAgainstSchema", ErrorCategory.InvalidData, null);
|
||||
ErrorRecord errorRecord = new(exception, "InvalidJsonAgainstSchema", ErrorCategory.InvalidData, null);
|
||||
errorRecord.ErrorDetails = new ErrorDetails(message.ToString());
|
||||
WriteError(errorRecord);
|
||||
}
|
||||
@@ -164,7 +164,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
result = false;
|
||||
|
||||
Exception exception = new Exception(TestJsonCmdletStrings.InvalidJson, exc);
|
||||
Exception exception = new(TestJsonCmdletStrings.InvalidJson, exc);
|
||||
WriteError(new ErrorRecord(exception, "InvalidJson", ErrorCategory.InvalidData, Json));
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
#region private members
|
||||
|
||||
private readonly System.Diagnostics.Stopwatch _stopWatch = new System.Diagnostics.Stopwatch();
|
||||
private readonly System.Diagnostics.Stopwatch _stopWatch = new();
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// </summary>
|
||||
protected override void ProcessRecord()
|
||||
{
|
||||
List<string> pathsToProcess = new List<string>();
|
||||
List<string> pathsToProcess = new();
|
||||
ProviderInfo provider = null;
|
||||
|
||||
if (string.Equals(this.ParameterSetName, "ByLiteralPath", StringComparison.OrdinalIgnoreCase))
|
||||
@@ -110,7 +110,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
if (!WildcardPattern.ContainsWildcardCharacters(path))
|
||||
{
|
||||
ErrorRecord errorRecord = new ErrorRecord(e,
|
||||
ErrorRecord errorRecord = new(e,
|
||||
"FileNotFound",
|
||||
ErrorCategory.ObjectNotFound,
|
||||
path);
|
||||
@@ -180,7 +180,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
if (!System.IO.File.Exists(resolvedpath))
|
||||
{
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
ErrorRecord errorRecord = new(
|
||||
new System.IO.FileNotFoundException(resolvedpath),
|
||||
"FileNotFound",
|
||||
ErrorCategory.ObjectNotFound,
|
||||
|
||||
+2
-2
@@ -97,7 +97,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
(!WildcardPattern.ContainsWildcardCharacters(_sourceIdentifier)) &&
|
||||
(!_foundMatch))
|
||||
{
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
ErrorRecord errorRecord = new(
|
||||
new ArgumentException(
|
||||
string.Format(
|
||||
System.Globalization.CultureInfo.CurrentCulture,
|
||||
@@ -111,7 +111,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
else if ((SubscriptionId >= 0) &&
|
||||
(!_foundMatch))
|
||||
{
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
ErrorRecord errorRecord = new(
|
||||
new ArgumentException(
|
||||
string.Format(
|
||||
System.Globalization.CultureInfo.CurrentCulture,
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
private static void ReportWrongExtension(string file, string errorId, PSCmdlet cmdlet)
|
||||
{
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
ErrorRecord errorRecord = new(
|
||||
PSTraceSource.NewInvalidOperationException(UpdateDataStrings.UpdateData_WrongExtension, file, "ps1xml"),
|
||||
errorId,
|
||||
ErrorCategory.InvalidArgument,
|
||||
@@ -45,7 +45,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
private static void ReportWrongProviderType(string providerId, string errorId, PSCmdlet cmdlet)
|
||||
{
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
ErrorRecord errorRecord = new(
|
||||
PSTraceSource.NewInvalidOperationException(UpdateDataStrings.UpdateData_WrongProviderError, providerId),
|
||||
errorId,
|
||||
ErrorCategory.InvalidArgument,
|
||||
@@ -61,7 +61,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <returns></returns>
|
||||
internal static Collection<string> Glob(string[] files, string errorId, PSCmdlet cmdlet)
|
||||
{
|
||||
Collection<string> retValue = new Collection<string>();
|
||||
Collection<string> retValue = new();
|
||||
foreach (string file in files)
|
||||
{
|
||||
Collection<string> providerPaths;
|
||||
|
||||
@@ -129,7 +129,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
private Hashtable CreateHashtable()
|
||||
{
|
||||
Hashtable hash = new Hashtable(2);
|
||||
Hashtable hash = new(2);
|
||||
if (Add != null)
|
||||
{
|
||||
hash.Add("Add", Add);
|
||||
@@ -150,7 +150,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
private PSListModifier CreatePSListModifier()
|
||||
{
|
||||
PSListModifier listModifier = new PSListModifier();
|
||||
PSListModifier listModifier = new();
|
||||
if (Add != null)
|
||||
{
|
||||
foreach (object obj in Add)
|
||||
@@ -180,8 +180,8 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
private ErrorRecord NewError(string errorId, string resourceId, object targetObject, params object[] args)
|
||||
{
|
||||
ErrorDetails details = new ErrorDetails(this.GetType().Assembly, "UpdateListStrings", resourceId, args);
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
ErrorDetails details = new(this.GetType().Assembly, "UpdateListStrings", resourceId, args);
|
||||
ErrorRecord errorRecord = new(
|
||||
new InvalidOperationException(details.Message),
|
||||
errorId,
|
||||
ErrorCategory.InvalidOperation,
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
private const string DynamicTypeSet = "DynamicTypeSet";
|
||||
private const string TypeDataSet = "TypeDataSet";
|
||||
|
||||
private static readonly object s_notSpecified = new object();
|
||||
private static readonly object s_notSpecified = new();
|
||||
|
||||
private static bool HasBeenSpecified(object obj)
|
||||
{
|
||||
@@ -372,7 +372,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
foreach (string s in errors)
|
||||
{
|
||||
RuntimeException rte = new RuntimeException(s);
|
||||
RuntimeException rte = new(s);
|
||||
this.WriteError(new ErrorRecord(rte, "TypesDynamicUpdateException", ErrorCategory.InvalidOperation, null));
|
||||
}
|
||||
}
|
||||
@@ -411,7 +411,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
ThrowTerminatingError(NewError("TargetTypeNameEmpty", UpdateDataStrings.TargetTypeNameEmpty, _typeName));
|
||||
}
|
||||
|
||||
TypeData type = new TypeData(_typeName) { IsOverride = _force };
|
||||
TypeData type = new(_typeName) { IsOverride = _force };
|
||||
|
||||
GetMembers(type.Members);
|
||||
|
||||
@@ -457,19 +457,19 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
if (_defaultDisplayPropertySet != null)
|
||||
{
|
||||
PropertySetData defaultDisplayPropertySet = new PropertySetData(_defaultDisplayPropertySet);
|
||||
PropertySetData defaultDisplayPropertySet = new(_defaultDisplayPropertySet);
|
||||
type.DefaultDisplayPropertySet = defaultDisplayPropertySet;
|
||||
}
|
||||
|
||||
if (_defaultKeyPropertySet != null)
|
||||
{
|
||||
PropertySetData defaultKeyPropertySet = new PropertySetData(_defaultKeyPropertySet);
|
||||
PropertySetData defaultKeyPropertySet = new(_defaultKeyPropertySet);
|
||||
type.DefaultKeyPropertySet = defaultKeyPropertySet;
|
||||
}
|
||||
|
||||
if (_propertySerializationSet != null)
|
||||
{
|
||||
PropertySetData propertySerializationSet = new PropertySetData(_propertySerializationSet);
|
||||
PropertySetData propertySerializationSet = new(_propertySerializationSet);
|
||||
type.PropertySerializationSet = propertySerializationSet;
|
||||
}
|
||||
|
||||
@@ -496,7 +496,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
foreach (string s in errors)
|
||||
{
|
||||
RuntimeException rte = new RuntimeException(s);
|
||||
RuntimeException rte = new(s);
|
||||
this.WriteError(new ErrorRecord(rte, "TypesDynamicUpdateException", ErrorCategory.InvalidOperation, null));
|
||||
}
|
||||
}
|
||||
@@ -690,7 +690,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
value2ScriptBlock = GetParameterType<ScriptBlock>(_value2);
|
||||
}
|
||||
|
||||
ScriptPropertyData scriptProperty = new ScriptPropertyData(_memberName, value1ScriptBlock, value2ScriptBlock);
|
||||
ScriptPropertyData scriptProperty = new(_memberName, value1ScriptBlock, value2ScriptBlock);
|
||||
return scriptProperty;
|
||||
}
|
||||
|
||||
@@ -712,7 +712,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
value2CodeReference = GetParameterType<MethodInfo>(_value2);
|
||||
}
|
||||
|
||||
CodePropertyData codeProperty = new CodePropertyData(_memberName, value1CodeReference, value2CodeReference);
|
||||
CodePropertyData codeProperty = new(_memberName, value1CodeReference, value2CodeReference);
|
||||
return codeProperty;
|
||||
}
|
||||
|
||||
@@ -723,7 +723,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
EnsureValue2HasNotBeenSpecified();
|
||||
|
||||
ScriptBlock method = GetParameterType<ScriptBlock>(_value1);
|
||||
ScriptMethodData scriptMethod = new ScriptMethodData(_memberName, method);
|
||||
ScriptMethodData scriptMethod = new(_memberName, method);
|
||||
return scriptMethod;
|
||||
}
|
||||
|
||||
@@ -734,7 +734,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
EnsureValue2HasNotBeenSpecified();
|
||||
|
||||
MethodInfo codeReference = GetParameterType<MethodInfo>(_value1);
|
||||
CodeMethodData codeMethod = new CodeMethodData(_memberName, codeReference);
|
||||
CodeMethodData codeMethod = new(_memberName, codeReference);
|
||||
return codeMethod;
|
||||
}
|
||||
|
||||
@@ -749,7 +749,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
private static ErrorRecord NewError(string errorId, string template, object targetObject, params object[] args)
|
||||
{
|
||||
string message = string.Format(CultureInfo.CurrentCulture, template, args);
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
ErrorRecord errorRecord = new(
|
||||
new InvalidOperationException(message),
|
||||
errorId,
|
||||
ErrorCategory.InvalidOperation,
|
||||
@@ -866,7 +866,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
foreach (string s in errors)
|
||||
{
|
||||
RuntimeException rte = new RuntimeException(s);
|
||||
RuntimeException rte = new(s);
|
||||
this.WriteError(new ErrorRecord(rte, "TypesXmlUpdateException", ErrorCategory.InvalidOperation, null));
|
||||
}
|
||||
|
||||
@@ -1119,8 +1119,8 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
// Key of the map is the name of the file that is in the cache. Value of the map is a index list. Duplicate files might
|
||||
// exist in the cache because the user can add arbitrary files to the cache by $host.Runspace.InitialSessionState.Types.Add()
|
||||
Dictionary<string, List<int>> fileToIndexMap = new Dictionary<string, List<int>>(StringComparer.OrdinalIgnoreCase);
|
||||
List<int> indicesToRemove = new List<int>();
|
||||
Dictionary<string, List<int>> fileToIndexMap = new(StringComparer.OrdinalIgnoreCase);
|
||||
List<int> indicesToRemove = new();
|
||||
|
||||
if (Context.InitialSessionState != null)
|
||||
{
|
||||
@@ -1209,7 +1209,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
|
||||
Dbg.Assert(!string.IsNullOrEmpty(typeNameToRemove), "TypeNameToRemove should be not null and not empty at this point");
|
||||
TypeData type = new TypeData(typeNameToRemove);
|
||||
TypeData type = new(typeNameToRemove);
|
||||
string removeTypeFormattedTarget = string.Format(CultureInfo.InvariantCulture, removeTypeTarget, typeNameToRemove);
|
||||
|
||||
if (ShouldProcess(removeTypeFormattedTarget, removeTypeAction))
|
||||
@@ -1223,7 +1223,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
foreach (string s in errors)
|
||||
{
|
||||
RuntimeException rte = new RuntimeException(s);
|
||||
RuntimeException rte = new(s);
|
||||
this.WriteError(new ErrorRecord(rte, "TypesDynamicRemoveException", ErrorCategory.InvalidOperation, null));
|
||||
}
|
||||
}
|
||||
@@ -1258,7 +1258,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
private static ErrorRecord NewError(string errorId, string template, object targetObject, params object[] args)
|
||||
{
|
||||
string message = string.Format(CultureInfo.CurrentCulture, template, args);
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
ErrorRecord errorRecord = new(
|
||||
new InvalidOperationException(message),
|
||||
errorId,
|
||||
ErrorCategory.InvalidOperation,
|
||||
@@ -1334,7 +1334,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
ValidateTypeName();
|
||||
|
||||
Dictionary<string, TypeData> alltypes = Context.TypeTable.GetAllTypeData();
|
||||
Collection<TypeData> typedefs = new Collection<TypeData>();
|
||||
Collection<TypeData> typedefs = new();
|
||||
|
||||
foreach (string type in alltypes.Keys)
|
||||
{
|
||||
|
||||
@@ -241,7 +241,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
if (_hexBytes == string.Empty)
|
||||
{
|
||||
StringBuilder line = new StringBuilder(BytesPerLine * 3);
|
||||
StringBuilder line = new(BytesPerLine * 3);
|
||||
|
||||
foreach (var currentByte in Bytes)
|
||||
{
|
||||
@@ -267,7 +267,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
if (_ascii == string.Empty)
|
||||
{
|
||||
StringBuilder ascii = new StringBuilder(BytesPerLine);
|
||||
StringBuilder ascii = new(BytesPerLine);
|
||||
|
||||
foreach (var currentByte in Bytes)
|
||||
{
|
||||
@@ -304,11 +304,11 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
// '16 + 3' comes from format "{0:X16} ".
|
||||
// '16' comes from '[Uint64]::MaxValue.ToString("X").Length'.
|
||||
StringBuilder nextLine = new StringBuilder(16 + 3 + (BytesPerLine * 3));
|
||||
StringBuilder asciiEnd = new StringBuilder(BytesPerLine);
|
||||
StringBuilder nextLine = new(16 + 3 + (BytesPerLine * 3));
|
||||
StringBuilder asciiEnd = new(BytesPerLine);
|
||||
|
||||
// '+1' comes from 'result.Append(nextLine.ToString() + " " + asciiEnd.ToString());' below.
|
||||
StringBuilder result = new StringBuilder(nextLine.Capacity + asciiEnd.Capacity + 1);
|
||||
StringBuilder result = new(nextLine.Capacity + asciiEnd.Capacity + 1);
|
||||
|
||||
if (Bytes.Length > 0)
|
||||
{
|
||||
|
||||
@@ -99,7 +99,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
wasFiltered = false;
|
||||
|
||||
List<PSVariable> result = new List<PSVariable>();
|
||||
List<PSVariable> result = new();
|
||||
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
@@ -355,7 +355,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (!matchFound && !wasFiltered)
|
||||
{
|
||||
ItemNotFoundException itemNotFound =
|
||||
new ItemNotFoundException(
|
||||
new(
|
||||
varName,
|
||||
"VariableNotFound",
|
||||
SessionStateStrings.VariableNotFound);
|
||||
@@ -490,7 +490,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (varFound != null)
|
||||
{
|
||||
SessionStateException sessionStateException =
|
||||
new SessionStateException(
|
||||
new(
|
||||
Name,
|
||||
SessionStateCategory.Variable,
|
||||
"VariableAlreadyExists",
|
||||
@@ -514,7 +514,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
if (ShouldProcess(target, action))
|
||||
{
|
||||
PSVariable newVariable = new PSVariable(Name, Value, Option);
|
||||
PSVariable newVariable = new(Name, Value, Option);
|
||||
|
||||
if (_visibility != null)
|
||||
{
|
||||
@@ -810,7 +810,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
// First look for existing variables to set.
|
||||
|
||||
List<PSVariable> matchingVariables = new List<PSVariable>();
|
||||
List<PSVariable> matchingVariables = new();
|
||||
|
||||
bool wasFiltered = false;
|
||||
|
||||
@@ -865,7 +865,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
|
||||
PSVariable varToSet =
|
||||
new PSVariable(
|
||||
new(
|
||||
varName,
|
||||
newVarValue,
|
||||
newOptions);
|
||||
@@ -1121,7 +1121,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
// characters were specified, write an error.
|
||||
|
||||
ItemNotFoundException itemNotFound =
|
||||
new ItemNotFoundException(
|
||||
new(
|
||||
varName,
|
||||
"VariableNotFound",
|
||||
SessionStateStrings.VariableNotFound);
|
||||
@@ -1283,7 +1283,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
// characters were specified, write an error.
|
||||
|
||||
ItemNotFoundException itemNotFound =
|
||||
new ItemNotFoundException(
|
||||
new(
|
||||
varName,
|
||||
"VariableNotFound",
|
||||
SessionStateStrings.VariableNotFound);
|
||||
|
||||
@@ -60,9 +60,9 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
#endregion parameters
|
||||
|
||||
private readonly AutoResetEvent _eventArrived = new AutoResetEvent(false);
|
||||
private readonly AutoResetEvent _eventArrived = new(false);
|
||||
private PSEventArgs _receivedEvent = null;
|
||||
private readonly object _receivedEventLock = new object();
|
||||
private readonly object _receivedEventLock = new();
|
||||
private WildcardPattern _matchPattern;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
if (mshCommandRuntime != null)
|
||||
{
|
||||
DebugRecord record = new DebugRecord(Message);
|
||||
DebugRecord record = new(Message);
|
||||
|
||||
InvocationInfo invocationInfo = GetVariableValue(SpecialVariables.MyInvocation) as InvocationInfo;
|
||||
|
||||
@@ -85,7 +85,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
if (mshCommandRuntime != null)
|
||||
{
|
||||
VerboseRecord record = new VerboseRecord(Message);
|
||||
VerboseRecord record = new(Message);
|
||||
|
||||
InvocationInfo invocationInfo = GetVariableValue(SpecialVariables.MyInvocation) as InvocationInfo;
|
||||
|
||||
@@ -133,7 +133,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
if (mshCommandRuntime != null)
|
||||
{
|
||||
WarningRecord record = new WarningRecord(Message);
|
||||
WarningRecord record = new(Message);
|
||||
|
||||
InvocationInfo invocationInfo = GetVariableValue(SpecialVariables.MyInvocation) as InvocationInfo;
|
||||
|
||||
@@ -184,7 +184,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
if (tag.StartsWith("PS", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
ErrorRecord er = new ErrorRecord(
|
||||
ErrorRecord er = new(
|
||||
new InvalidOperationException(StringUtil.Format(UtilityCommonStrings.PSPrefixReservedInInformationTag, tag)),
|
||||
"PSPrefixReservedInInformationTag", ErrorCategory.InvalidArgument, tag);
|
||||
ThrowTerminatingError(er);
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
// unroll enumerables, including arrays.
|
||||
|
||||
bool printSeparator = false;
|
||||
StringBuilder result = new StringBuilder();
|
||||
StringBuilder result = new();
|
||||
|
||||
foreach (object element in enumerable)
|
||||
{
|
||||
@@ -102,7 +102,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
string result = ProcessObject(Object) ?? string.Empty;
|
||||
|
||||
HostInformationMessage informationMessage = new HostInformationMessage();
|
||||
HostInformationMessage informationMessage = new();
|
||||
informationMessage.Message = result;
|
||||
informationMessage.NoNewLine = NoNewline.IsPresent;
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
void
|
||||
ProcessRecord()
|
||||
{
|
||||
ProgressRecord pr = new ProgressRecord(Id, Activity, Status);
|
||||
ProgressRecord pr = new(Id, Activity, Status);
|
||||
pr.ParentActivityId = ParentId;
|
||||
pr.PercentComplete = PercentComplete;
|
||||
pr.SecondsRemaining = SecondsRemaining;
|
||||
|
||||
@@ -226,7 +226,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
);
|
||||
|
||||
// create xml writer
|
||||
XmlWriterSettings xmlSettings = new XmlWriterSettings();
|
||||
XmlWriterSettings xmlSettings = new();
|
||||
xmlSettings.CloseOutput = true;
|
||||
xmlSettings.Encoding = sw.Encoding;
|
||||
xmlSettings.Indent = true;
|
||||
@@ -463,7 +463,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
// Loading to the XML Document
|
||||
_ms.Position = 0;
|
||||
StreamReader read = new StreamReader(_ms);
|
||||
StreamReader read = new(_ms);
|
||||
string data = read.ReadToEnd();
|
||||
WriteObject(data);
|
||||
|
||||
@@ -498,13 +498,13 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (As.Equals("Document", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// this is a trusted xml doc - the cmdlet generated the doc into a private memory stream
|
||||
XmlDocument xmldoc = new XmlDocument();
|
||||
XmlDocument xmldoc = new();
|
||||
xmldoc.Load(_ms);
|
||||
WriteObject(xmldoc);
|
||||
}
|
||||
else if (As.Equals("String", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
StreamReader read = new StreamReader(_ms);
|
||||
StreamReader read = new(_ms);
|
||||
string data = read.ReadToEnd();
|
||||
WriteObject(data);
|
||||
}
|
||||
@@ -892,7 +892,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
foreach (XmlNode foundXmlNode in foundXmlNodes)
|
||||
{
|
||||
SelectXmlInfo selectXmlInfo = new SelectXmlInfo();
|
||||
SelectXmlInfo selectXmlInfo = new();
|
||||
selectXmlInfo.Node = foundXmlNode;
|
||||
selectXmlInfo.Pattern = XPath;
|
||||
selectXmlInfo.Path = filePath;
|
||||
@@ -968,8 +968,8 @@ namespace Microsoft.PowerShell.Commands
|
||||
filePath,
|
||||
exception.Message);
|
||||
|
||||
ArgumentException argumentException = new ArgumentException(errorMessage, exception);
|
||||
ErrorRecord errorRecord = new ErrorRecord(argumentException, "ProcessingFile", ErrorCategory.InvalidArgument, filePath);
|
||||
ArgumentException argumentException = new(errorMessage, exception);
|
||||
ErrorRecord errorRecord = new(argumentException, "ProcessingFile", ErrorCategory.InvalidArgument, filePath);
|
||||
|
||||
this.WriteError(errorRecord);
|
||||
}
|
||||
@@ -996,15 +996,15 @@ namespace Microsoft.PowerShell.Commands
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
string message = StringUtil.Format(UtilityCommonStrings.SearchXMLPrefixNullError);
|
||||
InvalidOperationException e = new InvalidOperationException(message);
|
||||
ErrorRecord er = new ErrorRecord(e, "PrefixError", ErrorCategory.InvalidOperation, namespacetable);
|
||||
InvalidOperationException e = new(message);
|
||||
ErrorRecord er = new(e, "PrefixError", ErrorCategory.InvalidOperation, namespacetable);
|
||||
WriteError(er);
|
||||
}
|
||||
catch (ArgumentNullException)
|
||||
{
|
||||
string message = StringUtil.Format(UtilityCommonStrings.SearchXMLPrefixNullError);
|
||||
InvalidOperationException e = new InvalidOperationException(message);
|
||||
ErrorRecord er = new ErrorRecord(e, "PrefixError", ErrorCategory.InvalidOperation, namespacetable);
|
||||
InvalidOperationException e = new(message);
|
||||
ErrorRecord er = new(e, "PrefixError", ErrorCategory.InvalidOperation, namespacetable);
|
||||
WriteError(er);
|
||||
}
|
||||
}
|
||||
@@ -1033,7 +1033,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
(ParameterSetName.Equals("LiteralPath", StringComparison.OrdinalIgnoreCase))))
|
||||
{
|
||||
// If any file not resolved, execution stops. this is to make consistent with select-string.
|
||||
List<string> fullresolvedPaths = new List<string>();
|
||||
List<string> fullresolvedPaths = new();
|
||||
foreach (string fpath in Path)
|
||||
{
|
||||
if (_isLiteralPath)
|
||||
@@ -1049,8 +1049,8 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
// Cannot open File error
|
||||
string message = StringUtil.Format(UtilityCommonStrings.FileOpenError, provider.FullName);
|
||||
InvalidOperationException e = new InvalidOperationException(message);
|
||||
ErrorRecord er = new ErrorRecord(e, "ProcessingFile", ErrorCategory.InvalidOperation, fpath);
|
||||
InvalidOperationException e = new(message);
|
||||
ErrorRecord er = new(e, "ProcessingFile", ErrorCategory.InvalidOperation, fpath);
|
||||
WriteError(er);
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user