Skip to content

Commit

Permalink
release v3.0.7
Browse files Browse the repository at this point in the history
- [fix] fixed duplicate generated unsafe accessors to private members of a same type
  • Loading branch information
JasonXuDeveloper committed Jan 5, 2025
1 parent 8872338 commit 985f2c8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/Nino.Generator/UnsafeAccessorGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ private static void Execute(Compilation compilation, ImmutableArray<CSharpSyntax
_) = ninoSymbols.GetInheritanceMap();

var sb = new StringBuilder();
var generatedTypes = new HashSet<ITypeSymbol>(SymbolEqualityComparer.Default);

foreach (var typeSymbol in ninoSymbols)
{
Expand All @@ -50,6 +51,11 @@ private static void Execute(Compilation compilation, ImmutableArray<CSharpSyntax
void WriteMembers(List<NinoTypeHelper.NinoMember> members, ITypeSymbol type,
string typeName)
{
if (!generatedTypes.Add(type))
{
return;
}

foreach (var (name, declaredType, _, _, isPrivate, isProperty) in members)
{
if (!isPrivate)
Expand Down
10 changes: 9 additions & 1 deletion src/Nino.UnitTests/SimpleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,19 @@ public class SimpleTests
[TestMethod]
public void TestPrivateAccess()
{
TestPrivateMemberClass pcls = new TestPrivateMemberClass();
pcls.A = 1;

byte[] bytes = pcls.Serialize();
Deserializer.Deserialize(bytes, out TestPrivateMemberClass pcls2);
Assert.AreEqual(pcls.A, pcls2.A);
Assert.AreEqual(pcls.ReadonlyId, pcls2.ReadonlyId);

RecordWithPrivateMember record = new RecordWithPrivateMember("Test");
Assert.IsNotNull(record.Name);
Assert.AreEqual("Test", record.Name);

byte[] bytes = record.Serialize();
bytes = record.Serialize();
Deserializer.Deserialize(bytes, out RecordWithPrivateMember r1);
Assert.AreEqual(record.Name, r1.Name);
Assert.AreEqual(record.ReadonlyId, r1.ReadonlyId);
Expand Down
17 changes: 17 additions & 0 deletions src/Nino.UnitTests/TestClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,23 @@

namespace Nino.UnitTests
{
[NinoType]
public
#if !NET8_0_OR_GREATER
partial
#endif
class TestPrivateMemberClass : Base
{
private int Id { get; set; }

public int ReadonlyId => Id;

public TestPrivateMemberClass()
{
Id = Random.Shared.Next();
}
}

[NinoType]
public
#if !NET8_0_OR_GREATER
Expand Down

0 comments on commit 985f2c8

Please sign in to comment.