diff --git a/src/Nino.Generator/UnsafeAccessorGenerator.cs b/src/Nino.Generator/UnsafeAccessorGenerator.cs index 9275484..da385b0 100644 --- a/src/Nino.Generator/UnsafeAccessorGenerator.cs +++ b/src/Nino.Generator/UnsafeAccessorGenerator.cs @@ -33,6 +33,7 @@ private static void Execute(Compilation compilation, ImmutableArray(SymbolEqualityComparer.Default); foreach (var typeSymbol in ninoSymbols) { @@ -50,6 +51,11 @@ private static void Execute(Compilation compilation, ImmutableArray members, ITypeSymbol type, string typeName) { + if (!generatedTypes.Add(type)) + { + return; + } + foreach (var (name, declaredType, _, _, isPrivate, isProperty) in members) { if (!isPrivate) diff --git a/src/Nino.UnitTests/SimpleTests.cs b/src/Nino.UnitTests/SimpleTests.cs index 6aa8b10..058dbce 100644 --- a/src/Nino.UnitTests/SimpleTests.cs +++ b/src/Nino.UnitTests/SimpleTests.cs @@ -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); diff --git a/src/Nino.UnitTests/TestClass.cs b/src/Nino.UnitTests/TestClass.cs index 8a11a05..d33e651 100644 --- a/src/Nino.UnitTests/TestClass.cs +++ b/src/Nino.UnitTests/TestClass.cs @@ -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