Skip to content

Commit

Permalink
Merge pull request #17 from ronnygunawan/limi-to-classes-and-structs
Browse files Browse the repository at this point in the history
Limit to Classes and Structs
  • Loading branch information
ronnygunawan authored Nov 15, 2023
2 parents 718e649 + 874d98a commit 02bc1ad
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CsvSerializer/CsvSerializer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<RepositoryUrl>https://github.com/ronnygunawan/csv-serializer</RepositoryUrl>
<PackageTags>csv serializer deserializer parser core</PackageTags>
<Description>Fast CSV to object serializer and deserializer.</Description>
<Version>2.0.2</Version>
<Version>2.0.3</Version>
<PackageReleaseNotes></PackageReleaseNotes>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<IsRoslynComponent>true</IsRoslynComponent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public void OnVisitSyntaxNode(GeneratorSyntaxContext context) {
} typeArguments
|| typeArguments[0] is not {
Name.Length: > 0,
DeclaringSyntaxReferences.Length: > 0
DeclaringSyntaxReferences.Length: > 0,
TypeKind: TypeKind.Class or TypeKind.Struct
}) {
return;
}
Expand Down Expand Up @@ -87,7 +88,8 @@ public void OnVisitSyntaxNode(GeneratorSyntaxContext context) {
} typeArguments
|| typeArguments[0] is not {
Name.Length: > 0,
DeclaringSyntaxReferences.Length: > 0
DeclaringSyntaxReferences.Length: > 0,
TypeKind: TypeKind.Class or TypeKind.Struct
}) {
return;
}
Expand Down
31 changes: 31 additions & 0 deletions Tests/SerializerTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Csv;
using FluentAssertions;
using System;
using System.Configuration;
using System.Globalization;
using System.Linq;
using System.Net;
Expand Down Expand Up @@ -202,6 +203,36 @@ public void CanDeserializeCsvFromExcel() {
ExcelModel[] models = CsvSerializer.Deserialize<ExcelModel>(csv, hasHeaders: true, delimiter: ';', provider: CultureInfo.GetCultureInfo("id-ID"));
models.Count().Should().Be(2);
}

[Fact]
public void TypeArgumentsAreSerializedUsingNaiveSerializer() {
string Serialize<T>(T item) {
return CsvSerializer.Serialize(new[] { item }, withHeaders: true, provider: CultureInfo.GetCultureInfo("en-US"));

Check warning on line 210 in Tests/SerializerTests.cs

View workflow job for this annotation

GitHub Actions / build

The type 'T' cannot be used as type parameter 'T' in the generic type or method 'CsvSerializer.Serialize<T>(IEnumerable<T>, bool, char, IFormatProvider?)'. Nullability of type argument 'T' doesn't match 'notnull' constraint.

Check warning on line 210 in Tests/SerializerTests.cs

View workflow job for this annotation

GitHub Actions / build

The type 'T' cannot be used as type parameter 'T' in the generic type or method 'CsvSerializer.Serialize<T>(IEnumerable<T>, bool, char, IFormatProvider?)'. Nullability of type argument 'T' doesn't match 'notnull' constraint.
}
Model item = new() {
Bool = true,
Byte = 0x66,
SByte = -100,
Short = -200,
UShort = 200,
Int = -3000,
UInt = 3000,
Long = -40000L,
ULong = 40000UL,
Float = 100000000000000.0f,
Double = 17837193718273812973.0,
Decimal = 989898989898m,
String = "CSV Serializer",
DateTime = new DateTime(2019, 8, 23),
Uri = new Uri("http://localhost:5000/"),
StatusCode = HttpStatusCode.OK
};
string csv = Serialize(item);
csv.Should().BeSimilarTo("""
"Bool","Byte","SByte","Short","UShort","Int","UInt","Long","ULong","Float","Double","Decimal","String","DateTime","Uri","StatusCode"
True,102,-100,-200,200,-3000,3000,-40000,40000,1E+14,1.7837193718273812E+19,989898989898,"CSV Serializer","8/23/2019 12:00:00 AM","http://localhost:5000/",OK
""");
}
}

public class ExcelModel {
Expand Down

0 comments on commit 02bc1ad

Please sign in to comment.