@@ -44,69 +44,86 @@ public void OnVisitSyntaxNode(GeneratorSyntaxContext context)
4444 if ( attributes . Any ( attribute => attribute . AttributeClass ? . ToDisplayString ( ) == "YamlDotNet.Serialization.YamlStaticContextAttribute" ) )
4545 {
4646 YamlStaticContextType = classSymbol ;
47+
48+ var types =
49+ attributes . Where ( attribute => attribute . AttributeClass ? . ToDisplayString ( ) == "YamlDotNet.Serialization.YamlSerializableAttribute"
50+ && attribute . ConstructorArguments . Any ( argument => argument . Type ? . ToDisplayString ( ) == "System.Type" ) )
51+ . Select ( attribute => attribute . ConstructorArguments . First ( ) . Value )
52+ . ToArray ( ) ;
53+
54+ foreach ( var type in types . OfType < INamedTypeSymbol > ( ) )
55+ {
56+ AddSerializableClass ( type ) ;
57+ }
4758 }
4859
49- if ( classSymbol . GetAttributes ( ) . Any ( attribute => attribute . AttributeClass ? . ToDisplayString ( ) == "YamlDotNet.Serialization.YamlSerializableAttribute" ) )
60+ if ( classSymbol . GetAttributes ( ) . Any ( attribute => attribute . AttributeClass ? . ToDisplayString ( ) == "YamlDotNet.Serialization.YamlSerializableAttribute"
61+ && attribute . ConstructorArguments . Length == 0 ) )
5062 {
51- ClassObject classObject ;
52- var className = SanitizeName ( classSymbol . GetFullName ( ) ) ;
53- if ( Classes . ContainsKey ( className ) )
63+ AddSerializableClass ( classSymbol ) ;
64+ }
65+ }
66+ }
67+ }
68+
69+ private void AddSerializableClass ( INamedTypeSymbol classSymbol )
70+ {
71+ ClassObject classObject ;
72+ var className = SanitizeName ( classSymbol . GetFullName ( ) ) ;
73+ if ( Classes . ContainsKey ( className ) )
74+ {
75+ classObject = Classes [ className ] ;
76+ }
77+ else
78+ {
79+ classObject = new ClassObject ( className , classSymbol ) ;
80+ Classes [ className ] = classObject ;
81+ }
82+ while ( classSymbol != null )
83+ {
84+ var members = classSymbol . GetMembers ( ) ;
85+ foreach ( var member in members )
86+ {
87+ if ( member . IsStatic ||
88+ ( member . DeclaredAccessibility != Accessibility . Public &&
89+ member . DeclaredAccessibility != Accessibility . Internal ) ||
90+ member . GetAttributes ( ) . Any ( x => x . AttributeClass ! . ToDisplayString ( ) == "YamlDotNet.Serialization.YamlIgnoreAttribute" ) )
91+ {
92+ continue ;
93+ }
94+
95+ if ( member is IPropertySymbol propertySymbol )
96+ {
97+ classObject . PropertySymbols . Add ( propertySymbol ) ;
98+ CheckForSupportedGeneric ( propertySymbol . Type ) ;
99+ }
100+ else if ( member is IFieldSymbol fieldSymbol )
101+ {
102+ classObject . FieldSymbols . Add ( fieldSymbol ) ;
103+ CheckForSupportedGeneric ( fieldSymbol . Type ) ;
104+ }
105+ else if ( member is IMethodSymbol methodSymbol )
106+ {
107+ var methodAttributes = methodSymbol . GetAttributes ( ) ;
108+ if ( methodAttributes . Any ( x => x . AttributeClass ! . ToDisplayString ( ) == "YamlDotNet.Serialization.Callbacks.OnDeserializedAttribute" ) )
54109 {
55- classObject = Classes [ className ] ;
110+ classObject . OnDeserializedMethods . Add ( methodSymbol ) ;
56111 }
57- else
112+ if ( methodAttributes . Any ( x => x . AttributeClass ! . ToDisplayString ( ) == "YamlDotNet.Serialization.Callbacks.OnDeserializingAttribute" ) )
58113 {
59- classObject = new ClassObject ( className , classSymbol ) ;
60- Classes [ className ] = classObject ;
114+ classObject . OnDeserializingMethods . Add ( methodSymbol ) ;
61115 }
62- while ( classSymbol != null )
116+ if ( methodAttributes . Any ( x => x . AttributeClass ! . ToDisplayString ( ) == "YamlDotNet.Serialization.Callbacks.OnSerializedAttribute" ) )
63117 {
64- var members = classSymbol . GetMembers ( ) ;
65- foreach ( var member in members )
66- {
67- if ( member . IsStatic ||
68- ( member . DeclaredAccessibility != Accessibility . Public &&
69- member . DeclaredAccessibility != Accessibility . Internal ) ||
70- member . GetAttributes ( ) . Any ( x => x . AttributeClass ! . ToDisplayString ( ) == "YamlDotNet.Serialization.YamlIgnoreAttribute" ) )
71- {
72- continue ;
73- }
74-
75- if ( member is IPropertySymbol propertySymbol )
76- {
77- classObject . PropertySymbols . Add ( propertySymbol ) ;
78- CheckForSupportedGeneric ( propertySymbol . Type ) ;
79- }
80- else if ( member is IFieldSymbol fieldSymbol )
81- {
82- classObject . FieldSymbols . Add ( fieldSymbol ) ;
83- CheckForSupportedGeneric ( fieldSymbol . Type ) ;
84- }
85- else if ( member is IMethodSymbol methodSymbol )
86- {
87- var methodAttributes = methodSymbol . GetAttributes ( ) ;
88- if ( methodAttributes . Any ( x => x . AttributeClass ! . ToDisplayString ( ) == "YamlDotNet.Serialization.Callbacks.OnDeserializedAttribute" ) )
89- {
90- classObject . OnDeserializedMethods . Add ( methodSymbol ) ;
91- }
92- if ( methodAttributes . Any ( x => x . AttributeClass ! . ToDisplayString ( ) == "YamlDotNet.Serialization.Callbacks.OnDeserializingAttribute" ) )
93- {
94- classObject . OnDeserializingMethods . Add ( methodSymbol ) ;
95- }
96- if ( methodAttributes . Any ( x => x . AttributeClass ! . ToDisplayString ( ) == "YamlDotNet.Serialization.Callbacks.OnSerializedAttribute" ) )
97- {
98- classObject . OnSerializedMethods . Add ( methodSymbol ) ;
99- }
100- if ( methodAttributes . Any ( x => x . AttributeClass ! . ToDisplayString ( ) == "YamlDotNet.Serialization.Callbacks.OnSerializingAttribute" ) )
101- {
102- classObject . OnSerializingMethods . Add ( methodSymbol ) ;
103- }
104- }
105- }
106- classSymbol = classSymbol . BaseType ;
118+ classObject . OnSerializedMethods . Add ( methodSymbol ) ;
119+ }
120+ if ( methodAttributes . Any ( x => x . AttributeClass ! . ToDisplayString ( ) == "YamlDotNet.Serialization.Callbacks.OnSerializingAttribute" ) )
121+ {
122+ classObject . OnSerializingMethods . Add ( methodSymbol ) ;
107123 }
108124 }
109125 }
126+ classSymbol = classSymbol . BaseType ;
110127 }
111128 }
112129
0 commit comments