Skip to content

Commit a9fff7a

Browse files
committed
fix ArrayFormatter does not register correctly
1 parent 6fecbcc commit a9fff7a

4 files changed

Lines changed: 24 additions & 6 deletions

File tree

sandbox/SandboxConsoleApp/Models.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ public class NewBase
2424
public long Description { get; set; }
2525
}
2626

27+
[MemoryPackable]
28+
public partial struct FooUnman
29+
{
30+
public float MyProperty { get; set; }
31+
public float MyProperty2 { get; set; }
32+
}
33+
2734
[MemoryPackable]
2835
public partial class NewProp : NewBase, IMore
2936
{

src/MemoryPack.Generator/MemoryPackGenerator.Emitter.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,26 @@ string WithEscape(ISymbol symbol)
181181
{
182182
if (type.IsUnmanagedType)
183183
{
184-
sb.Append("unmanaged ");
184+
sb.Append("GanerateType unmanaged ");
185+
}
186+
else
187+
{
188+
sb.Append("GenerateType " + type.GenerateType.ToString() + " ");
185189
}
186190
sb.AppendLine(WithEscape(type.Symbol));
187191
sb.AppendLine("---");
188192
}
189193
else
190194
{
191195
sb.AppendLine("/// <remarks>");
192-
sb.AppendLine("/// MemoryPack serialize members:<br/>");
196+
if (type.IsUnmanagedType)
197+
{
198+
sb.AppendLine("/// MemoryPack GenerateType: unmanaged<br/>");
199+
}
200+
else
201+
{
202+
sb.AppendLine("/// MemoryPack GenerateType: " + type.GenerateType.ToString() + "<br/>");
203+
}
193204
sb.AppendLine("/// <code>");
194205
}
195206

src/MemoryPack.Generator/ReferenceSymbols.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,21 +270,21 @@ public bool Contains(ITypeSymbol symbol)
270270
{
271271
if (array.IsSZArray)
272272
{
273-
return $"MemoryPack.Formatters.ArrayFormatter<{type.FullyQualifiedToString()}>";
273+
return $"MemoryPack.Formatters.ArrayFormatter<{array.ElementType.FullyQualifiedToString()}>";
274274
}
275275
else
276276
{
277277
if (array.Rank == 2)
278278
{
279-
return $"MemoryPack.Formatters.TwoDimensionalArrayFormatter<{type.FullyQualifiedToString()}>";
279+
return $"MemoryPack.Formatters.TwoDimensionalArrayFormatter<{array.ElementType.FullyQualifiedToString()}>";
280280
}
281281
else if (array.Rank == 3)
282282
{
283-
return $"MemoryPack.Formatters.ThreeDimensionalArrayFormatter<{type.FullyQualifiedToString()}>";
283+
return $"MemoryPack.Formatters.ThreeDimensionalArrayFormatter<{array.ElementType.FullyQualifiedToString()}>";
284284
}
285285
else if (array.Rank == 4)
286286
{
287-
return $"MemoryPack.Formatters.FourDimensionalArrayFormatter<{type.FullyQualifiedToString()}>";
287+
return $"MemoryPack.Formatters.FourDimensionalArrayFormatter<{array.ElementType.FullyQualifiedToString()}>";
288288
}
289289
}
290290
}

0 commit comments

Comments
 (0)