Skip to content

Commit 3842d58

Browse files
authored
Merge pull request #41 from IvanMurzak/refactor/type-id
Refactor type name retrieval to use GetTypeId method
2 parents d1a5aa5 + dd0c074 commit 3842d58

61 files changed

Lines changed: 1867 additions & 551 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
/*
2+
* ReflectorNet
3+
* Author: Ivan Murzak (https://github.com/IvanMurzak)
4+
* Copyright (c) 2025 Ivan Murzak
5+
* Licensed under the Apache License, Version 2.0. See LICENSE file in the project root for full license information.
6+
*/
7+
8+
namespace com.IvanMurzak.ReflectorNet.OuterAssembly.Model
9+
{
10+
// Simple class
11+
public class OuterSimpleClass
12+
{
13+
public int Value { get; set; }
14+
}
15+
16+
// Simple struct
17+
public struct OuterSimpleStruct
18+
{
19+
public int Value { get; set; }
20+
}
21+
22+
// Abstract class
23+
public abstract class OuterAbstractClass
24+
{
25+
public abstract int Value { get; set; }
26+
}
27+
28+
// Sealed class
29+
public sealed class OuterSealedClass
30+
{
31+
public int Value { get; set; }
32+
}
33+
34+
// Static class (cannot be used as type argument, but can be referenced)
35+
public static class OuterStaticClass
36+
{
37+
public static int Value { get; set; }
38+
}
39+
40+
// Generic class with single type parameter
41+
public class OuterGenericClass<T>
42+
{
43+
public T? Value { get; set; }
44+
}
45+
46+
// Generic class with two type parameters
47+
public class OuterGenericClass2<T1, T2>
48+
{
49+
public T1? Value1 { get; set; }
50+
public T2? Value2 { get; set; }
51+
}
52+
53+
// Generic class with three type parameters
54+
public class OuterGenericClass3<T1, T2, T3>
55+
{
56+
public T1? Value1 { get; set; }
57+
public T2? Value2 { get; set; }
58+
public T3? Value3 { get; set; }
59+
}
60+
61+
// Generic struct
62+
public struct OuterGenericStruct<T>
63+
{
64+
public T? Value { get; set; }
65+
}
66+
67+
// Generic struct with two type parameters
68+
public struct OuterGenericStruct2<T1, T2>
69+
{
70+
public T1? Value1 { get; set; }
71+
public T2? Value2 { get; set; }
72+
}
73+
74+
// Container class with nested types
75+
public class OuterContainer
76+
{
77+
// Nested class
78+
public class NestedClass
79+
{
80+
public int Value { get; set; }
81+
}
82+
83+
// Nested struct
84+
public struct NestedStruct
85+
{
86+
public int Value { get; set; }
87+
}
88+
89+
// Nested abstract class
90+
public abstract class NestedAbstractClass
91+
{
92+
public abstract int Value { get; set; }
93+
}
94+
95+
// Nested sealed class
96+
public sealed class NestedSealedClass
97+
{
98+
public int Value { get; set; }
99+
}
100+
101+
// Nested generic class
102+
public class NestedGenericClass<T>
103+
{
104+
public T? Value { get; set; }
105+
}
106+
107+
// Nested generic struct
108+
public struct NestedGenericStruct<T>
109+
{
110+
public T? Value { get; set; }
111+
}
112+
113+
// Double nested container
114+
public class NestedContainer
115+
{
116+
// Double nested class
117+
public class DoubleNestedClass
118+
{
119+
public int Value { get; set; }
120+
}
121+
122+
// Double nested struct
123+
public struct DoubleNestedStruct
124+
{
125+
public int Value { get; set; }
126+
}
127+
128+
// Double nested generic
129+
public class DoubleNestedGenericClass<T>
130+
{
131+
public T? Value { get; set; }
132+
}
133+
}
134+
}
135+
136+
// Generic container with nested types
137+
public class OuterGenericContainer<T>
138+
{
139+
public class NestedInGeneric
140+
{
141+
public T? Value { get; set; }
142+
}
143+
144+
public struct NestedStructInGeneric
145+
{
146+
public T? Value { get; set; }
147+
}
148+
149+
public class NestedGenericInGeneric<U>
150+
{
151+
public T? Value1 { get; set; }
152+
public U? Value2 { get; set; }
153+
}
154+
}
155+
156+
// Interface
157+
public interface IOuterInterface
158+
{
159+
int Value { get; set; }
160+
}
161+
162+
// Generic interface
163+
public interface IOuterGenericInterface<T>
164+
{
165+
T? Value { get; set; }
166+
}
167+
168+
// Enum
169+
public enum OuterEnum
170+
{
171+
None = 0,
172+
First = 1,
173+
Second = 2
174+
}
175+
176+
// Flags enum
177+
[System.Flags]
178+
public enum OuterFlagsEnum
179+
{
180+
None = 0,
181+
Flag1 = 1,
182+
Flag2 = 2,
183+
Flag3 = 4
184+
}
185+
186+
// Nested enum container
187+
public class OuterEnumContainer
188+
{
189+
public enum NestedEnum
190+
{
191+
None = 0,
192+
Value = 1
193+
}
194+
}
195+
}

ReflectorNet.Tests/src/ReflectorTests/SerializationTests.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public void Serialize_ParentClass_NestedClass_Instance()
188188

189189
// Assert
190190
Assert.NotNull(serialized);
191-
Assert.Equal(typeof(ParentClass.NestedClass).GetTypeName(pretty: false), serialized.typeName);
191+
Assert.Equal(typeof(ParentClass.NestedClass).GetTypeId(), serialized.typeName);
192192
Assert.NotNull(serialized.valueJsonElement);
193193
_output.WriteLine($"Serialized ParentClass.NestedClass: {serialized.ToJson(reflector)}");
194194
}
@@ -232,7 +232,7 @@ public void Serialize_StaticParentClass_NestedClass_Instance()
232232

233233
// Assert
234234
Assert.NotNull(serialized);
235-
Assert.Equal(typeof(StaticParentClass.NestedClass).GetTypeName(pretty: false), serialized.typeName);
235+
Assert.Equal(typeof(StaticParentClass.NestedClass).GetTypeId(), serialized.typeName);
236236
Assert.NotNull(serialized.valueJsonElement);
237237
_output.WriteLine($"Serialized StaticParentClass.NestedClass: {serialized.ToJson(reflector)}");
238238
}
@@ -332,7 +332,7 @@ public void Serialize_NestedClass_WithDefaultValues()
332332

333333
// Assert
334334
Assert.NotNull(serialized);
335-
Assert.Equal(typeof(ParentClass.NestedClass).GetTypeName(pretty: false), serialized.typeName);
335+
Assert.Equal(typeof(ParentClass.NestedClass).GetTypeId(), serialized.typeName);
336336
_output.WriteLine($"Serialized nested class with defaults: {serialized.ToJson(reflector)}");
337337
}
338338

@@ -370,7 +370,7 @@ public void Serialize_NestedClass_WithNullValues()
370370

371371
// Assert
372372
Assert.NotNull(serialized);
373-
Assert.Equal(typeof(ParentClass.NestedClass).GetTypeName(pretty: false), serialized.typeName);
373+
Assert.Equal(typeof(ParentClass.NestedClass).GetTypeId(), serialized.typeName);
374374
_output.WriteLine($"Serialized nested class with empty strings: {serialized.ToJson(reflector)}");
375375
}
376376

@@ -415,8 +415,8 @@ public void Serialize_Static_Members_From_ParentClass_NestedClass()
415415
Assert.NotNull(serializedProperty);
416416
Assert.Equal("NestedStaticField", serializedField.name);
417417
Assert.Equal("NestedStaticProperty", serializedProperty.name);
418-
Assert.Equal(typeof(string).GetTypeName(pretty: false), serializedField.typeName);
419-
Assert.Equal(typeof(string).GetTypeName(pretty: false), serializedProperty.typeName);
418+
Assert.Equal(typeof(string).GetTypeId(), serializedField.typeName);
419+
Assert.Equal(typeof(string).GetTypeId(), serializedProperty.typeName);
420420

421421
_output.WriteLine($"Serialized static field: {serializedField.ToJson(reflector)}");
422422
_output.WriteLine($"Serialized static property: {serializedProperty.ToJson(reflector)}");
@@ -441,8 +441,8 @@ public void Serialize_Static_Members_From_ParentClass_NestedStaticClass()
441441
Assert.NotNull(serializedProperty);
442442
Assert.Equal("NestedStaticField", serializedField.name);
443443
Assert.Equal("NestedStaticProperty", serializedProperty.name);
444-
Assert.Equal(typeof(string).GetTypeName(pretty: false), serializedField.typeName);
445-
Assert.Equal(typeof(string).GetTypeName(pretty: false), serializedProperty.typeName);
444+
Assert.Equal(typeof(string).GetTypeId(), serializedField.typeName);
445+
Assert.Equal(typeof(string).GetTypeId(), serializedProperty.typeName);
446446

447447
_output.WriteLine($"Serialized ParentClass.NestedStaticClass static field: {serializedField.ToJson(reflector)}");
448448
_output.WriteLine($"Serialized ParentClass.NestedStaticClass static property: {serializedProperty.ToJson(reflector)}");
@@ -467,8 +467,8 @@ public void Serialize_Static_Members_From_StaticParentClass_NestedClass()
467467
Assert.NotNull(serializedProperty);
468468
Assert.Equal("NestedStaticField", serializedField.name);
469469
Assert.Equal("NestedStaticProperty", serializedProperty.name);
470-
Assert.Equal(typeof(string).GetTypeName(pretty: false), serializedField.typeName);
471-
Assert.Equal(typeof(string).GetTypeName(pretty: false), serializedProperty.typeName);
470+
Assert.Equal(typeof(string).GetTypeId(), serializedField.typeName);
471+
Assert.Equal(typeof(string).GetTypeId(), serializedProperty.typeName);
472472

473473
_output.WriteLine($"Serialized StaticParentClass.NestedClass static field: {serializedField.ToJson(reflector)}");
474474
_output.WriteLine($"Serialized StaticParentClass.NestedClass static property: {serializedProperty.ToJson(reflector)}");
@@ -493,8 +493,8 @@ public void Serialize_Static_Members_From_StaticParentClass_NestedStaticClass()
493493
Assert.NotNull(serializedProperty);
494494
Assert.Equal("NestedStaticField", serializedField.name);
495495
Assert.Equal("NestedStaticProperty", serializedProperty.name);
496-
Assert.Equal(typeof(string).GetTypeName(pretty: false), serializedField.typeName);
497-
Assert.Equal(typeof(string).GetTypeName(pretty: false), serializedProperty.typeName);
496+
Assert.Equal(typeof(string).GetTypeId(), serializedField.typeName);
497+
Assert.Equal(typeof(string).GetTypeId(), serializedProperty.typeName);
498498

499499
_output.WriteLine($"Serialized StaticParentClass.NestedStaticClass static field: {serializedField.ToJson(reflector)}");
500500
_output.WriteLine($"Serialized StaticParentClass.NestedStaticClass static property: {serializedProperty.ToJson(reflector)}");

ReflectorNet.Tests/src/ReflectorTests/SerializeDeserializationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void ActAssert(object? original, Type? fallbackType = null)
2525

2626
var type = original?.GetType() ?? fallbackType;
2727

28-
_output.WriteLine($"### Test for type: {type?.GetTypeName(pretty: true) ?? "null"}\n");
28+
_output.WriteLine($"### Test for type: {type?.GetTypeId() ?? "null"}\n");
2929
_output.WriteLine($"Serialization:\n{serializeLogger}");
3030

3131
var deserializeLogger = new StringBuilderLogger();

ReflectorNet.Tests/src/ReflectorTests/TypeAndAssemblySerializationTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void ActAssert(object? original, Type? fallbackType = null)
3131

3232
var type = original?.GetType() ?? fallbackType;
3333

34-
_output.WriteLine($"### Test for type: {type?.GetTypeName(pretty: true) ?? "null"}\n");
34+
_output.WriteLine($"### Test for type: {type?.GetTypeId() ?? "null"}\n");
3535
_output.WriteLine($"Serialization:\n{serializeLogger}");
3636

3737
var deserializeLogger = new StringBuilderLogger();
@@ -49,12 +49,12 @@ void ActAssert(object? original, Type? fallbackType = null)
4949
// For System.Type and System.Reflection.Assembly, we verify the essential identity information
5050
if (original is Type originalType && deserialized is Type deserializedType)
5151
{
52-
_output.WriteLine($"Original Type: {originalType.FullName}");
53-
_output.WriteLine($"Deserialized Type: {deserializedType.FullName}");
52+
_output.WriteLine($"Original Type: {originalType.GetTypeId()}");
53+
_output.WriteLine($"Deserialized Type: {deserializedType.GetTypeId()}");
5454
_output.WriteLine($"Original Assembly: {originalType.Assembly.FullName}");
5555
_output.WriteLine($"Deserialized Assembly: {deserializedType.Assembly.FullName}");
5656

57-
Assert.Equal(originalType.FullName, deserializedType.FullName);
57+
Assert.Equal(originalType.GetTypeId(), deserializedType.GetTypeId());
5858
Assert.Equal(originalType.Assembly.FullName, deserializedType.Assembly.FullName);
5959
Assert.Equal(originalType, deserializedType);
6060
}

ReflectorNet.Tests/src/ReflectorTests/TypedListDeserializationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public void DirectListDeserializationViaSerializedMember_ShouldBeTyped()
227227

228228
// Assert
229229
Assert.NotNull(deserialized);
230-
_output.WriteLine($"Deserialized type: {deserialized.GetType().FullName}");
230+
_output.WriteLine($"Deserialized type: {deserialized.GetType().GetTypeId()}");
231231

232232
// Critical: Should be List<int>, not List<object?>
233233
Assert.IsType<List<int>>(deserialized);

ReflectorNet.Tests/src/SchemaTests/AdvancedFeatureTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void Property_vs_Field_Serialization()
3131
Assert.NotNull(propertiesOnly);
3232
Assert.NotNull(fieldsOnly);
3333
Assert.NotNull(allMembers);
34-
Assert.Equal(typeof(GameObjectRef).GetTypeName(pretty: false), propertiesOnly.typeName);
34+
Assert.Equal(typeof(GameObjectRef).GetTypeId(), propertiesOnly.typeName);
3535

3636
_output.WriteLine($"Properties serialization: {propertiesOnly.typeName}");
3737
_output.WriteLine($"Fields serialization: {fieldsOnly.typeName}");

ReflectorNet.Tests/src/SchemaTests/MethodFindingTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void FindMethod_WithParameterMatching()
7979
MethodName = nameof(TestClass.SerializedMemberList_ReturnString),
8080
InputParameters = new List<MethodRef.Parameter>
8181
{
82-
new() { TypeName = typeof(SerializedMemberList).GetTypeName(pretty: false), Name = "gameObjectDiffs" }
82+
new() { TypeName = typeof(SerializedMemberList).GetTypeId(), Name = "gameObjectDiffs" }
8383
}
8484
};
8585

ReflectorNet.Tests/src/SchemaTests/PerformanceTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void Reflector_Introspection_Tests()
9090
Assert.NotNull(typeId);
9191
Assert.Equal("com.IvanMurzak.ReflectorNet.Tests.Model.GameObjectRef", typeId);
9292

93-
_output.WriteLine($"Type: {testType.GetTypeName(pretty: false)}");
93+
_output.WriteLine($"Type: {testType.GetTypeId()}");
9494
_output.WriteLine($"Schema: {schema}");
9595
_output.WriteLine($"TypeId: {typeId}");
9696
}
@@ -104,7 +104,7 @@ public void TypeUtils_Integration_Tests()
104104
var stringType = TypeUtils.GetType("System.String");
105105
Assert.Equal(typeof(string), stringType);
106106

107-
var gameObjectRefType = TypeUtils.GetType(typeof(GameObjectRef).GetTypeName(pretty: false)!);
107+
var gameObjectRefType = TypeUtils.GetType(typeof(GameObjectRef).GetTypeId()!);
108108
Assert.Equal(typeof(GameObjectRef), gameObjectRefType);
109109

110110
// Test default value generation
@@ -166,7 +166,7 @@ public void MethodDataRef_Construction_From_MethodInfo()
166166
Assert.Equal(nameof(TestClass.SerializedMemberList_ReturnString), methodDataRef.MethodName);
167167
Assert.Equal(methodInfo.IsPublic, methodDataRef.IsPublic);
168168
Assert.Equal(methodInfo.IsStatic, methodDataRef.IsStatic);
169-
Assert.Equal(methodInfo.ReturnType.GetTypeName(pretty: false), methodDataRef.ReturnType);
169+
Assert.Equal(methodInfo.ReturnType.GetTypeId(), methodDataRef.ReturnType);
170170
Assert.NotNull(methodDataRef.ReturnSchema);
171171
Assert.NotNull(methodDataRef.InputParametersSchema);
172172
Assert.Single(methodDataRef.InputParametersSchema); // SerializedMemberList parameter

ReflectorNet.Tests/src/SchemaTests/SchemaSerializationValidationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public SchemaSerializationValidationTests(ITestOutputHelper output) : base(outpu
2424
/// </summary>
2525
private void ValidateTypeSchemaAndRoundTrip(Type type, object? instance, Reflector reflector)
2626
{
27-
var typeName = type.GetTypeName(pretty: true);
27+
var typeName = type.GetTypeId();
2828
_output.WriteLine($"=== Testing type: {typeName} ===");
2929

3030
// Step 1: Generate schema and validate it has no errors

0 commit comments

Comments
 (0)