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 @@ -45,17 +45,19 @@ public abstract class BaseCsvWritingCommand : PSCmdlet
public abstract PSObject InputObject { get; set; }

/// <summary>
/// IncludeTypeInformation : The #TYPE line should be generated. Default is false. Cannot specify with NoTypeInformation.
/// IncludeTypeInformation : The #TYPE line should be generated. Default is false.
/// </summary>
[Parameter]
[Alias("ITI")]
public SwitchParameter IncludeTypeInformation { get; set; }

/// <summary>
/// NoTypeInformation : The #TYPE line should not be generated. Default is true. Cannot specify with IncludeTypeInformation.
/// Gets or sets a value indicating whether to suppress the #TYPE line.
/// This parameter is obsolete and has no effect. It is retained for backward compatibility only.
/// </summary>
[Parameter(DontShow = true)]
[Alias("NTI")]
[Obsolete("This parameter is obsolete and has no effect. The default behavior is to not include type information. Use -IncludeTypeInformation to include type information.")]
public SwitchParameter NoTypeInformation { get; set; } = true;

/// <summary>
Expand Down Expand Up @@ -120,18 +122,6 @@ protected override void BeginProcessing()
this.ThrowTerminatingError(errorRecord);
}

if (this.MyInvocation.BoundParameters.ContainsKey(nameof(IncludeTypeInformation)) && this.MyInvocation.BoundParameters.ContainsKey(nameof(NoTypeInformation)))
{
InvalidOperationException exception = new(CsvCommandStrings.CannotSpecifyIncludeTypeInformationAndNoTypeInformation);
ErrorRecord errorRecord = new(exception, "CannotSpecifyIncludeTypeInformationAndNoTypeInformation", ErrorCategory.InvalidData, null);
this.ThrowTerminatingError(errorRecord);
}

if (this.MyInvocation.BoundParameters.ContainsKey(nameof(IncludeTypeInformation)))
{
NoTypeInformation = !IncludeTypeInformation;
}

Delimiter = ImportExportCSVHelper.SetDelimiter(this, ParameterSetName, Delimiter, UseCulture);
}
}
Expand Down Expand Up @@ -317,7 +307,7 @@ protected override void ProcessRecord()
// write headers (row1: typename + row2: column names)
if (!_isActuallyAppending && !NoHeader.IsPresent)
{
if (NoTypeInformation == false)
if (IncludeTypeInformation)
{
WriteCsvLine(ExportCsvHelper.GetTypeString(InputObject));
}
Expand Down Expand Up @@ -742,7 +732,7 @@ protected override void ProcessRecord()

if (!NoHeader.IsPresent)
{
if (NoTypeInformation == false)
if (IncludeTypeInformation)
{
WriteCsvLine(ExportCsvHelper.GetTypeString(InputObject));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,6 @@
<data name="CannotSpecifyQuoteFieldsAndUseQuotes" xml:space="preserve">
<value>You must specify either the -UseQuotes or -QuoteFields parameters, but not both.</value>
</data>
<data name="CannotSpecifyIncludeTypeInformationAndNoTypeInformation" xml:space="preserve">
<value>You must specify either the -IncludeTypeInformation or -NoTypeInformation parameters, but not both.</value>
</data>
<data name="CannotSpecifyPathAndLiteralPath" xml:space="preserve">
<value>You must specify either the -Path or -LiteralPath parameters, but not both.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,6 @@ Describe "ConvertTo-Csv" -Tags "CI" {
Should -Throw -ErrorId "CannotSpecifyQuoteFieldsAndUseQuotes,Microsoft.PowerShell.Commands.ConvertToCsvCommand"
}

It "Does not support -IncludeTypeInformation and -NoTypeInformation at the same time" {
{ $testObject | ConvertTo-Csv -IncludeTypeInformation -NoTypeInformation } |
Should -Throw -ErrorId "CannotSpecifyIncludeTypeInformationAndNoTypeInformation,Microsoft.PowerShell.Commands.ConvertToCsvCommand"
}

Context "QuoteFields parameter" {
It "QuoteFields" {
# Use 'FiRstCoLumn' to test case insensitivity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ Describe "Export-Csv" -Tags "CI" {
$results[0] | Should -BeExactly "#TYPE System.String"
}

It "Does not support -IncludeTypeInformation and -NoTypeInformation at the same time" {
{ $testObject | Export-Csv -Path $testCsv -IncludeTypeInformation -NoTypeInformation } |
Should -Throw -ErrorId "CannotSpecifyIncludeTypeInformationAndNoTypeInformation,Microsoft.PowerShell.Commands.ExportCsvCommand"
}

It "Should support -LiteralPath parameter" {
$testObject | Export-Csv -LiteralPath $testCsv
$results = Import-Csv -Path $testCsv
Expand Down
Loading