Skip to content

Commit 4e9a2f5

Browse files
committed
fix bug with protected properties
TypeDescriptor didn't find protected properties
1 parent 76b3ce5 commit 4e9a2f5

File tree

3 files changed

+87
-1
lines changed

3 files changed

+87
-1
lines changed

GeometryDashAPI.Tests/TypeDescriptorTests.cs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
using System;
22
using System.Linq;
3+
using System.Text;
4+
using FluentAssertions;
5+
using GeometryDashAPI.Levels.Enums;
6+
using GeometryDashAPI.Levels.GameObjects.Default;
7+
using GeometryDashAPI.Levels.GameObjects.Specific;
38
using GeometryDashAPI.Serialization;
49
using NUnit.Framework;
510
using TestObjects;
@@ -60,4 +65,79 @@ public void ShouldParseEnumItself()
6065

6166
Assert.AreEqual(SimpleEnum.X, instance.Value);
6267
}
68+
69+
[Test]
70+
public void ProtectedVirtualFieldGet()
71+
{
72+
var descriptor = new TypeDescriptor<BaseBlock>();
73+
74+
var builder = new StringBuilder();
75+
descriptor.CopyTo(new BaseBlock(1)
76+
{
77+
ZLayer = Layer.B4
78+
}, builder);
79+
80+
builder.ToString().Should().Be("1,1,2,0,3,0,24,-3");
81+
}
82+
83+
[Test]
84+
public void ProtectedVirtualFieldSet()
85+
{
86+
var input = "1,1,2,0,3,0,24,-3";
87+
var descriptor = new TypeDescriptor<BaseBlock>();
88+
89+
var block = descriptor.Create(input.AsSpan());
90+
91+
block.ZLayer.Should().Be(Layer.B4);
92+
}
93+
94+
[Test]
95+
public void OverrideVirtualFieldGet_Default()
96+
{
97+
var descriptor = new TypeDescriptor<JumpPlate>();
98+
99+
var builder = new StringBuilder();
100+
descriptor.CopyTo(new JumpPlate(JumpPlateId.Red)
101+
{
102+
ZLayer = Layer.B1
103+
}, builder);
104+
105+
builder.ToString().Should().Be("1,1332,2,0,3,0");
106+
}
107+
108+
[Test]
109+
public void OverrideVirtualFieldGet_Specific()
110+
{
111+
var descriptor = new TypeDescriptor<JumpPlate>();
112+
113+
var builder = new StringBuilder();
114+
descriptor.CopyTo(new JumpPlate(JumpPlateId.Red)
115+
{
116+
ZLayer = Layer.B4
117+
}, builder);
118+
119+
builder.ToString().Should().Be("1,1332,2,0,3,0,24,-3");
120+
}
121+
122+
[Test]
123+
public void OverrideVirtualFieldSet_Default()
124+
{
125+
var input = "1,1332,2,0,3,0";
126+
var descriptor = new TypeDescriptor<JumpPlate>();
127+
128+
var block = descriptor.Create(input.AsSpan());
129+
130+
block.ZLayer.Should().Be(Layer.B1);
131+
}
132+
133+
[Test]
134+
public void OverrideVirtualFieldSet_Specific()
135+
{
136+
var input = "1,1332,2,0,3,0,24,-3";
137+
var descriptor = new TypeDescriptor<JumpPlate>();
138+
139+
var block = descriptor.Create(input.AsSpan());
140+
141+
block.ZLayer.Should().Be(Layer.B4);
142+
}
63143
}

GeometryDashAPI/Serialization/PrinterInfo.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ internal class PrinterInfo<T>
1212
#if DEBUG
1313
public Expression<TypeDescriptorHelper.Printer<T>> PrinterExp { get; set; }
1414
public Expression<TypeDescriptorHelper.Getter<T, bool>> IsDefaultExp { get; set; }
15+
public string Name { get; set; }
1516
#endif
1617

1718
public PrinterInfo(
@@ -23,5 +24,9 @@ public PrinterInfo(
2324
IsDefault = isDefault;
2425
Attribute = attribute;
2526
}
27+
28+
#if DEBUG
29+
public override string ToString() => Name;
30+
#endif
2631
}
2732
}

GeometryDashAPI/Serialization/TypeDescriptor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ private PrinterInfo<T>[] InitPrinters(IEnumerable<(MemberInfo member, GameProper
177177
x.attribute)
178178
#if DEBUG
179179
{
180+
Name = x.member.Name,
180181
PrinterExp = printerExp,
181182
IsDefaultExp = isDefaultExp
182183
}
@@ -233,7 +234,7 @@ private static (SetterInfo<T>[], int baseIndex, Dictionary<string, int> mappings
233234

234235
private static IEnumerable<MemberInfo> GetPropertiesAndFields(Type type)
235236
{
236-
foreach (var property in type.GetProperties())
237+
foreach (var property in type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic))
237238
yield return property;
238239
var current = type;
239240
while (current != null && current != typeof(object))

0 commit comments

Comments
 (0)