Skip to content

Commit

Permalink
Simplify empty object initializers
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriySvyryd committed Jun 16, 2022
1 parent f9d834b commit 9833683
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/CSharpScriptSerializer/CSharpScriptSerializer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<PackageId>CSharpScriptSerializer</PackageId>
<AssemblyTitle>CSharpScriptSerializer</AssemblyTitle>
<Title>CSharpScriptSerializer</Title>
<VersionPrefix>3.0.3</VersionPrefix>
<VersionPrefix>3.0.4</VersionPrefix>
<TargetFrameworks>netstandard2.1</TargetFrameworks>
<NetStandardImplicitPackageVersion>2.0.3</NetStandardImplicitPackageVersion>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
Expand All @@ -15,6 +15,8 @@
<PackageTags>Roslyn;CSharp;C#;CSX;Script;Serialization</PackageTags>
<PackageReleaseNotes>
<![CDATA[
Version 3.0.4
* Simplify empty object initializers
Version 3.0.3
* Simplify empty collections
Version 3.0.2
Expand Down
4 changes: 3 additions & 1 deletion src/CSharpScriptSerializer/PropertyCSScriptSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ protected override ObjectCreationExpressionSyntax GetObjectCreationExpression(T
IdentifierName(p.PropertyName),
GetCreationExpression(p.PropertyValueGetter(obj)))).ToList();

var expression = base.GetObjectCreationExpression(obj, generateEmptyArgumentList: properties.Count == 0)
var expression = properties.Count == 0
? base.GetObjectCreationExpression(obj, generateEmptyArgumentList: true)
: base.GetObjectCreationExpression(obj)
.WithInitializer(AddNewLine(
InitializerExpression(
SyntaxKind.ObjectInitializerExpression,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<PropertyGroup>
<AssemblyName>CSharpScriptSerializer.Tests</AssemblyName>
<PackageId>CSharpScriptSerializer.Tests</PackageId>
<VersionPrefix>2.0.0</VersionPrefix>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
Expand All @@ -16,7 +15,10 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
</ItemGroup>
Expand Down

0 comments on commit 9833683

Please sign in to comment.