Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
195 changes: 195 additions & 0 deletions ReflectorNet.Tests.OuterAssembly/src/Model/TypeIdTestModels.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
/*
* ReflectorNet
* Author: Ivan Murzak (https://github.com/IvanMurzak)
* Copyright (c) 2025 Ivan Murzak
* Licensed under the Apache License, Version 2.0. See LICENSE file in the project root for full license information.
*/

namespace com.IvanMurzak.ReflectorNet.OuterAssembly.Model
{
// Simple class
public class OuterSimpleClass
{
public int Value { get; set; }
}

// Simple struct
public struct OuterSimpleStruct
{
public int Value { get; set; }
}

// Abstract class
public abstract class OuterAbstractClass
{
public abstract int Value { get; set; }
}

// Sealed class
public sealed class OuterSealedClass
{
public int Value { get; set; }
}

// Static class (cannot be used as type argument, but can be referenced)
public static class OuterStaticClass
{
public static int Value { get; set; }
}

// Generic class with single type parameter
public class OuterGenericClass<T>
{
public T? Value { get; set; }
}

// Generic class with two type parameters
public class OuterGenericClass2<T1, T2>
{
public T1? Value1 { get; set; }
public T2? Value2 { get; set; }
}

// Generic class with three type parameters
public class OuterGenericClass3<T1, T2, T3>
{
public T1? Value1 { get; set; }
public T2? Value2 { get; set; }
public T3? Value3 { get; set; }
}

// Generic struct
public struct OuterGenericStruct<T>
{
public T? Value { get; set; }
}

// Generic struct with two type parameters
public struct OuterGenericStruct2<T1, T2>
{
public T1? Value1 { get; set; }
public T2? Value2 { get; set; }
}

// Container class with nested types
public class OuterContainer
{
// Nested class
public class NestedClass
{
public int Value { get; set; }
}

// Nested struct
public struct NestedStruct
{
public int Value { get; set; }
}

// Nested abstract class
public abstract class NestedAbstractClass
{
public abstract int Value { get; set; }
}

// Nested sealed class
public sealed class NestedSealedClass
{
public int Value { get; set; }
}

// Nested generic class
public class NestedGenericClass<T>
{
public T? Value { get; set; }
}

// Nested generic struct
public struct NestedGenericStruct<T>
{
public T? Value { get; set; }
}

// Double nested container
public class NestedContainer
{
// Double nested class
public class DoubleNestedClass
{
public int Value { get; set; }
}

// Double nested struct
public struct DoubleNestedStruct
{
public int Value { get; set; }
}

// Double nested generic
public class DoubleNestedGenericClass<T>
{
public T? Value { get; set; }
}
}
}

// Generic container with nested types
public class OuterGenericContainer<T>
{
public class NestedInGeneric
{
public T? Value { get; set; }
}

public struct NestedStructInGeneric
{
public T? Value { get; set; }
}

public class NestedGenericInGeneric<U>
{
public T? Value1 { get; set; }
public U? Value2 { get; set; }
}
}

// Interface
public interface IOuterInterface
{
int Value { get; set; }
}

// Generic interface
public interface IOuterGenericInterface<T>
{
T? Value { get; set; }
}

// Enum
public enum OuterEnum
{
None = 0,
First = 1,
Second = 2
}

// Flags enum
[System.Flags]
public enum OuterFlagsEnum
{
None = 0,
Flag1 = 1,
Flag2 = 2,
Flag3 = 4
}

// Nested enum container
public class OuterEnumContainer
{
public enum NestedEnum
{
None = 0,
Value = 1
}
}
}
24 changes: 12 additions & 12 deletions ReflectorNet.Tests/src/ReflectorTests/SerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public void Serialize_ParentClass_NestedClass_Instance()

// Assert
Assert.NotNull(serialized);
Assert.Equal(typeof(ParentClass.NestedClass).GetTypeName(pretty: false), serialized.typeName);
Assert.Equal(typeof(ParentClass.NestedClass).GetTypeId(), serialized.typeName);
Assert.NotNull(serialized.valueJsonElement);
_output.WriteLine($"Serialized ParentClass.NestedClass: {serialized.ToJson(reflector)}");
}
Expand Down Expand Up @@ -232,7 +232,7 @@ public void Serialize_StaticParentClass_NestedClass_Instance()

// Assert
Assert.NotNull(serialized);
Assert.Equal(typeof(StaticParentClass.NestedClass).GetTypeName(pretty: false), serialized.typeName);
Assert.Equal(typeof(StaticParentClass.NestedClass).GetTypeId(), serialized.typeName);
Assert.NotNull(serialized.valueJsonElement);
_output.WriteLine($"Serialized StaticParentClass.NestedClass: {serialized.ToJson(reflector)}");
}
Expand Down Expand Up @@ -332,7 +332,7 @@ public void Serialize_NestedClass_WithDefaultValues()

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

Expand Down Expand Up @@ -370,7 +370,7 @@ public void Serialize_NestedClass_WithNullValues()

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

Expand Down Expand Up @@ -415,8 +415,8 @@ public void Serialize_Static_Members_From_ParentClass_NestedClass()
Assert.NotNull(serializedProperty);
Assert.Equal("NestedStaticField", serializedField.name);
Assert.Equal("NestedStaticProperty", serializedProperty.name);
Assert.Equal(typeof(string).GetTypeName(pretty: false), serializedField.typeName);
Assert.Equal(typeof(string).GetTypeName(pretty: false), serializedProperty.typeName);
Assert.Equal(typeof(string).GetTypeId(), serializedField.typeName);
Assert.Equal(typeof(string).GetTypeId(), serializedProperty.typeName);

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

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

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

_output.WriteLine($"Serialized StaticParentClass.NestedStaticClass static field: {serializedField.ToJson(reflector)}");
_output.WriteLine($"Serialized StaticParentClass.NestedStaticClass static property: {serializedProperty.ToJson(reflector)}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void ActAssert(object? original, Type? fallbackType = null)

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

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

var deserializeLogger = new StringBuilderLogger();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void ActAssert(object? original, Type? fallbackType = null)

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

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

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

Assert.Equal(originalType.FullName, deserializedType.FullName);
Assert.Equal(originalType.GetTypeId(), deserializedType.GetTypeId());
Assert.Equal(originalType.Assembly.FullName, deserializedType.Assembly.FullName);
Assert.Equal(originalType, deserializedType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public void DirectListDeserializationViaSerializedMember_ShouldBeTyped()

// Assert
Assert.NotNull(deserialized);
_output.WriteLine($"Deserialized type: {deserialized.GetType().FullName}");
_output.WriteLine($"Deserialized type: {deserialized.GetType().GetTypeId()}");

// Critical: Should be List<int>, not List<object?>
Assert.IsType<List<int>>(deserialized);
Expand Down
2 changes: 1 addition & 1 deletion ReflectorNet.Tests/src/SchemaTests/AdvancedFeatureTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void Property_vs_Field_Serialization()
Assert.NotNull(propertiesOnly);
Assert.NotNull(fieldsOnly);
Assert.NotNull(allMembers);
Assert.Equal(typeof(GameObjectRef).GetTypeName(pretty: false), propertiesOnly.typeName);
Assert.Equal(typeof(GameObjectRef).GetTypeId(), propertiesOnly.typeName);

_output.WriteLine($"Properties serialization: {propertiesOnly.typeName}");
_output.WriteLine($"Fields serialization: {fieldsOnly.typeName}");
Expand Down
2 changes: 1 addition & 1 deletion ReflectorNet.Tests/src/SchemaTests/MethodFindingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void FindMethod_WithParameterMatching()
MethodName = nameof(TestClass.SerializedMemberList_ReturnString),
InputParameters = new List<MethodRef.Parameter>
{
new() { TypeName = typeof(SerializedMemberList).GetTypeName(pretty: false), Name = "gameObjectDiffs" }
new() { TypeName = typeof(SerializedMemberList).GetTypeId(), Name = "gameObjectDiffs" }
}
};

Expand Down
6 changes: 3 additions & 3 deletions ReflectorNet.Tests/src/SchemaTests/PerformanceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void Reflector_Introspection_Tests()
Assert.NotNull(typeId);
Assert.Equal("com.IvanMurzak.ReflectorNet.Tests.Model.GameObjectRef", typeId);

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

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

// Test default value generation
Expand Down Expand Up @@ -166,7 +166,7 @@ public void MethodDataRef_Construction_From_MethodInfo()
Assert.Equal(nameof(TestClass.SerializedMemberList_ReturnString), methodDataRef.MethodName);
Assert.Equal(methodInfo.IsPublic, methodDataRef.IsPublic);
Assert.Equal(methodInfo.IsStatic, methodDataRef.IsStatic);
Assert.Equal(methodInfo.ReturnType.GetTypeName(pretty: false), methodDataRef.ReturnType);
Assert.Equal(methodInfo.ReturnType.GetTypeId(), methodDataRef.ReturnType);
Assert.NotNull(methodDataRef.ReturnSchema);
Assert.NotNull(methodDataRef.InputParametersSchema);
Assert.Single(methodDataRef.InputParametersSchema); // SerializedMemberList parameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public SchemaSerializationValidationTests(ITestOutputHelper output) : base(outpu
/// </summary>
private void ValidateTypeSchemaAndRoundTrip(Type type, object? instance, Reflector reflector)
{
var typeName = type.GetTypeName(pretty: true);
var typeName = type.GetTypeId();
_output.WriteLine($"=== Testing type: {typeName} ===");

// Step 1: Generate schema and validate it has no errors
Expand Down
Loading