Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,9 @@ internal UniquePSObjectHelper(PSObject o, int notePropertyCount)

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=}
Expand Down Expand Up @@ -381,18 +381,18 @@ private void ProcessObject(PSObject inputObject)
}

// If property parameter is mentioned
List<PSNoteProperty> matchedProperties = new List<PSNoteProperty>();
List<PSNoteProperty> matchedProperties = new();
foreach (MshParameter p in _propertyMshParameterList)
{
ProcessParameter(p, inputObject, matchedProperties);
}

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)
{
Expand Down Expand Up @@ -430,7 +430,7 @@ private void ProcessParameter(MshParameter p, PSObject inputObject, List<PSNoteP
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))
Expand All @@ -455,7 +455,7 @@ private void ProcessParameter(MshParameter p, PSObject inputObject, List<PSNoteP
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,
Expand Down Expand Up @@ -505,7 +505,7 @@ private void ProcessExpandParameter(MshParameter p, PSObject inputObject,

if (expressionResults.Count == 0)
{
ErrorRecord errorRecord = new ErrorRecord(
ErrorRecord errorRecord = new(
PSTraceSource.NewArgumentException("ExpandProperty", SelectObjectStrings.PropertyNotFound, ExpandProperty),
"ExpandPropertyNotFound",
ErrorCategory.InvalidArgument,
Expand All @@ -515,7 +515,7 @@ private void ProcessExpandParameter(MshParameter p, PSObject inputObject,

if (expressionResults.Count > 1)
{
ErrorRecord errorRecord = new ErrorRecord(
ErrorRecord errorRecord = new(
PSTraceSource.NewArgumentException("ExpandProperty", SelectObjectStrings.MutlipleExpandProperties, ExpandProperty),
"MutlipleExpandProperties",
ErrorCategory.InvalidArgument,
Expand Down Expand Up @@ -562,7 +562,7 @@ private void ProcessExpandParameter(MshParameter p, PSObject inputObject,
}
else
{
ErrorRecord errorRecord = new ErrorRecord(
ErrorRecord errorRecord = new(
r.Exception,
"PropertyEvaluationExpand",
ErrorCategory.InvalidResult,
Expand Down Expand Up @@ -595,7 +595,7 @@ private void AddNoteProperties(PSObject expandedObject, PSObject inputObject, IE

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,
Expand Down Expand Up @@ -623,7 +623,7 @@ private void FilteredWriteObject(PSObject obj, List<PSNoteProperty> addedNotePro
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))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public Encoding Encoding
#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;

Expand Down Expand Up @@ -216,7 +216,7 @@ private void AddAddressesToMailMessage(object address, string param)
}
catch (FormatException e)
{
ErrorRecord er = new ErrorRecord(e, "FormatException", ErrorCategory.InvalidType, null);
ErrorRecord er = new(e, "FormatException", ErrorCategory.InvalidType, null);
WriteError(er);
continue;
}
Expand All @@ -239,7 +239,7 @@ protected override void BeginProcessing()
}
catch (FormatException e)
{
ErrorRecord er = new ErrorRecord(e, "FormatException", ErrorCategory.InvalidType, From);
ErrorRecord er = new(e, "FormatException", ErrorCategory.InvalidType, From);
ThrowTerminatingError(er);
}

Expand Down Expand Up @@ -294,7 +294,7 @@ protected override void BeginProcessing()

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);
}

Expand Down Expand Up @@ -344,7 +344,7 @@ protected override void ProcessRecord()
PathUtils.ReportFileOpenFailure(this, filepath, e);
}

Attachment mailAttachment = new Attachment(filepath);
Attachment mailAttachment = new(filepath);
_mMailMessage.Attachments.Add(mailAttachment);
}
}
Expand All @@ -362,30 +362,30 @@ protected override void EndProcessing()
}
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ protected override void BeginProcessing()
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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected override void ProcessRecord()
// Create the alias info

AliasInfo aliasToSet =
new AliasInfo(
new(
Name,
Value,
Context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected override void ProcessRecord()
}
#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;
Expand All @@ -102,8 +102,8 @@ protected override void ProcessRecord()
}

// 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class ShowCommandCommand : PSCmdlet, IDisposable
/// <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.
Expand Down Expand Up @@ -182,7 +182,7 @@ protected override void BeginProcessing()

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,
Expand All @@ -192,7 +192,7 @@ protected override void BeginProcessing()

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,
Expand Down Expand Up @@ -241,7 +241,7 @@ protected override void EndProcessing()
return;
}

StringBuilder errorString = new StringBuilder();
StringBuilder errorString = new();

for (int i = 0; i < _errors.Count; i++)
{
Expand Down Expand Up @@ -276,7 +276,7 @@ protected override void StopProcessing()
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;
Expand All @@ -294,7 +294,7 @@ private void RunScriptSilentlyAndWithErrorHookup(string script)
/// </summary>
private void IssueErrorForNoCommand()
{
InvalidOperationException errorException = new InvalidOperationException(
InvalidOperationException errorException = new(
string.Format(
CultureInfo.CurrentUICulture,
FormatAndOut_out_gridview.CommandNotFound,
Expand All @@ -307,7 +307,7 @@ private void IssueErrorForNoCommand()
/// </summary>
private void IssueErrorForMoreThanOneCommand()
{
InvalidOperationException errorException = new InvalidOperationException(
InvalidOperationException errorException = new(
string.Format(
CultureInfo.CurrentUICulture,
FormatAndOut_out_gridview.MoreThanOneCommand,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private void ProcessMarkdownInfo(MarkdownInfo markdownInfo)

try
{
ProcessStartInfo startInfo = new ProcessStartInfo();
ProcessStartInfo startInfo = new();
startInfo.FileName = tmpFilePath;
startInfo.UseShellExecute = true;
Process.Start(startInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ private int Heapify(List<OrderByPropertyEntry> dataToSort, OrderByPropertyCompar
/// </summary>
protected override void EndProcessing()
{
OrderByProperty orderByProperty = new OrderByProperty(
OrderByProperty orderByProperty = new(
this, InputObjects, Property, !Descending, ConvertedCulture, CaseSensitive);

var dataToProcess = orderByProperty.OrderMatrix;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void Dispose()

// 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ e is NotSupportedException ||
e is SecurityException
)
{
Exception exception = new Exception(
Exception exception = new(
string.Format(
CultureInfo.CurrentUICulture,
TestJsonCmdletStrings.JsonSchemaFileOpenFailure,
Expand All @@ -125,7 +125,7 @@ e is SecurityException
}
catch (Exception e)
{
Exception exception = new Exception(TestJsonCmdletStrings.InvalidJsonSchema, e);
Exception exception = new(TestJsonCmdletStrings.InvalidJsonSchema, e);
ThrowTerminatingError(new ErrorRecord(exception, "InvalidJsonSchema", ErrorCategory.InvalidData, resolvedpath));
}
}
Expand All @@ -149,11 +149,11 @@ protected override void ProcessRecord()
{
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);
}
Expand All @@ -164,7 +164,7 @@ protected override void ProcessRecord()
{
result = false;

Exception exception = new Exception(TestJsonCmdletStrings.InvalidJson, exc);
Exception exception = new(TestJsonCmdletStrings.InvalidJson, exc);
WriteError(new ErrorRecord(exception, "InvalidJson", ErrorCategory.InvalidData, Json));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public sealed class MeasureCommandCommand : PSCmdlet

#region private members

private readonly System.Diagnostics.Stopwatch _stopWatch = new System.Diagnostics.Stopwatch();
private readonly System.Diagnostics.Stopwatch _stopWatch = new();

#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public string[] LiteralPath
/// </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))
Expand Down Expand Up @@ -110,7 +110,7 @@ protected override void ProcessRecord()
{
if (!WildcardPattern.ContainsWildcardCharacters(path))
{
ErrorRecord errorRecord = new ErrorRecord(e,
ErrorRecord errorRecord = new(e,
"FileNotFound",
ErrorCategory.ObjectNotFound,
path);
Expand Down Expand Up @@ -180,7 +180,7 @@ private bool IsValidFileForUnblocking(string resolvedpath)
{
if (!System.IO.File.Exists(resolvedpath))
{
ErrorRecord errorRecord = new ErrorRecord(
ErrorRecord errorRecord = new(
new System.IO.FileNotFoundException(resolvedpath),
"FileNotFound",
ErrorCategory.ObjectNotFound,
Expand Down
Loading