@@ -18,7 +18,6 @@ private struct XnbTypeInfo
1818 public string TypeName ;
1919 public string TypeFullName ;
2020 public string QualifierString ;
21- public List < string > GenericParameters ;
2221 public List < XnbPropertyInfo > Properties ;
2322 }
2423
@@ -51,19 +50,32 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
5150 return null ;
5251 }
5352
53+ if ( typeSymbol . IsGenericType )
54+ {
55+ return null ;
56+ }
57+
5458 var xnbReaderTypeAttribute = typeSymbol . GetAttributes ( )
5559 . FirstOrDefault ( a => a . AttributeClass ? . ToDisplayString ( ) == XnbReaderTypeAttributeName ) ;
5660
5761 if ( xnbReaderTypeAttribute is not { ConstructorArguments . Length : > 0 } )
5862 {
5963 return null ;
6064 }
65+
66+ bool useBaseClass = xnbReaderTypeAttribute . NamedArguments
67+ . FirstOrDefault ( x => x . Key == "UseBaseClass" ) . Value . Value is true ;
68+
69+ var logicalTypeSymbol = typeSymbol ;
70+ if ( useBaseClass && typeSymbol . BaseType is not null )
71+ {
72+ logicalTypeSymbol = typeSymbol . BaseType ;
73+ }
6174
6275 var qualifierString = xnbReaderTypeAttribute . ConstructorArguments [ 0 ] . Value as string ?? string . Empty ;
63- var genericParameters = typeSymbol . TypeParameters . Select ( tp => tp . Name ) . ToList ( ) ;
6476 var properties = new List < XnbPropertyInfo > ( ) ;
6577
66- foreach ( var member in typeSymbol . GetMembers ( ) . OfType < IPropertySymbol > ( ) )
78+ foreach ( var member in logicalTypeSymbol . GetMembers ( ) . OfType < IPropertySymbol > ( ) )
6779 {
6880 ct . ThrowIfCancellationRequested ( ) ;
6981
@@ -84,21 +96,21 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
8496 bool skipIdentifier = xnbPropertyAttribute . NamedArguments
8597 . FirstOrDefault ( x => x . Key == "SkipIdentifier" ) . Value . Value is true ;
8698
87- ITypeSymbol underlyingType = member . Type ;
88- bool isNullableValueType = false ;
99+ ITypeSymbol underlyingPropertyType = member . Type ;
100+ bool propertyNullable = false ;
89101
90102 if ( member . Type is INamedTypeSymbol { ConstructedFrom . SpecialType : SpecialType . System_Nullable_T } namedType )
91103 {
92- underlyingType = namedType . TypeArguments [ 0 ] ;
93- isNullableValueType = true ;
104+ underlyingPropertyType = namedType . TypeArguments [ 0 ] ;
105+ propertyNullable = true ;
94106 }
95107
96108 properties . Add ( new XnbPropertyInfo
97109 {
98110 Name = member . Name ,
99- TypeFullName = underlyingType . ToDisplayString ( SymbolDisplayFormat . FullyQualifiedFormat ) ,
100- IsNullable = isNullableValueType ,
101- IsReferenceType = ! isNullableValueType && member . Type . IsReferenceType ,
111+ TypeFullName = underlyingPropertyType . ToDisplayString ( SymbolDisplayFormat . FullyQualifiedFormat ) ,
112+ IsNullable = propertyNullable ,
113+ IsReferenceType = ! propertyNullable && member . Type . IsReferenceType ,
102114 Order = order ,
103115 UseConverter = useConverter ,
104116 Optional = optional ,
@@ -111,10 +123,9 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
111123 return new XnbTypeInfo
112124 {
113125 TypeName = typeSymbol . Name ,
114- TypeFullName = typeSymbol . ToDisplayString ( SymbolDisplayFormat . FullyQualifiedFormat ) ,
126+ TypeFullName = logicalTypeSymbol . ToDisplayString ( SymbolDisplayFormat . FullyQualifiedFormat ) ,
115127 QualifierString = qualifierString ,
116128 Properties = properties ,
117- GenericParameters = genericParameters
118129 } ;
119130 }
120131
@@ -137,7 +148,7 @@ private static void EmitSerializer(CodeStringBuilder cb, XnbTypeInfo xnbTypeInfo
137148 cb . AppendLine ( ) ;
138149 cb . AppendLine ( "namespace FEZRepacker.Core.XNB.ContentSerialization;" ) ;
139150 cb . AppendLine ( ) ;
140- cb . Append ( $ "internal sealed class { ConstructSerializerName ( xnbTypeInfo ) } ") ;
151+ cb . Append ( $ "internal sealed class { xnbTypeInfo . TypeName } ContentSerializer ") ;
141152 cb . AppendLine ( $ " : XnbContentSerializer<{ xnbTypeInfo . TypeFullName } >") ;
142153 cb . BeginCodeBlock ( ) ;
143154 {
@@ -150,17 +161,6 @@ private static void EmitSerializer(CodeStringBuilder cb, XnbTypeInfo xnbTypeInfo
150161 cb . EndCodeBlock ( ) ;
151162 }
152163
153- private static string ConstructSerializerName ( XnbTypeInfo xnbTypeInfo )
154- {
155- var name = $ "{ xnbTypeInfo . TypeName } ContentSerializer";
156- if ( xnbTypeInfo . GenericParameters . Count > 0 )
157- {
158- var genericParametersList = string . Join ( ", " , xnbTypeInfo . GenericParameters ) ;
159- name += $ "<{ genericParametersList } >";
160- }
161- return name ;
162- }
163-
164164 private static void EmitDeserialize ( CodeStringBuilder cb , XnbTypeInfo model )
165165 {
166166 cb . AppendLine ( "public override object Deserialize(XnbContentReader reader)" ) ;
0 commit comments