@@ -23,13 +23,23 @@ private static SourceText GenerateUxmlTraits(GeneratorExecutionContext context,
2323 member : ClassWidget (
2424 identifier : capture . ClassName ,
2525 modifier : SyntaxKind . PartialKeyword ,
26- member : ClassWidget (
27- identifier : "UxmlTraits" ,
28- modifiers : new [ ] { SyntaxKind . PublicKeyword , SyntaxKind . NewKeyword } ,
29- baseType : SimpleBaseType ( IdentifierName ( $ "{ GetBaseClassName ( context , capture ) } .UxmlTraits") ) ,
30- members : GetTraitsClassMembers ( context , capture ) ,
31- addGeneratedCodeAttributes : true
32- ) ) ,
26+ members : new MemberDeclarationSyntax [ ]
27+ {
28+ ClassWidget (
29+ identifier : "UxmlTraits" ,
30+ modifiers : new [ ] { SyntaxKind . PublicKeyword , SyntaxKind . NewKeyword } ,
31+ baseType : SimpleBaseType ( IdentifierName ( $ "{ GetBaseClassName ( context , capture ) } .UxmlTraits") ) ,
32+ members : GetTraitsClassMembers ( context , capture ) ,
33+ addGeneratedCodeAttributes : true ) ,
34+ MethodWidget (
35+ identifier : "OnUxmlTraitsInitialized" ,
36+ type : PredefinedType ( Token ( SyntaxKind . VoidKeyword ) ) ,
37+ modifier : SyntaxKind . PartialKeyword ,
38+ parameter : ParameterWidget (
39+ identifier : "uxmlAttributes" ,
40+ type : IdentifierName ( string . Format ( UnityUiElementsFullName , "IUxmlAttributes" ) ) ) ,
41+ addGeneratedCodeAttributes : true )
42+ } ) ,
3343 normalizeWhitespace : true )
3444 . GetText ( Encoding . UTF8 ) ;
3545 }
@@ -39,7 +49,8 @@ private static IEnumerable<MemberDeclarationSyntax> GetTraitsClassMembers(Genera
3949 {
4050 var initMethodBody = new List < StatementSyntax >
4151 {
42- MethodBaseCallWidget (
52+ MethodCallWidget (
53+ expression : BaseExpression ( ) ,
4354 identifier : "Init" ,
4455 arguments : new [ ]
4556 {
@@ -73,6 +84,12 @@ private static IEnumerable<MemberDeclarationSyntax> GetTraitsClassMembers(Genera
7384 traitsClassMembers . Add ( GetAttributeFieldDeclaration ( uxmlAttributeInfo ) ) ;
7485 }
7586
87+ initMethodBody . Add ( MethodCallWidget (
88+ expression : IdentifierName ( "control" ) ,
89+ identifier : "OnUxmlTraitsInitialized" ,
90+ argument : Argument ( IdentifierName ( "bag" ) ) )
91+ ) ;
92+
7693 var initMethod = MethodWidget (
7794 identifier : "Init" ,
7895 type : PredefinedType ( Token ( SyntaxKind . VoidKeyword ) ) ,
@@ -267,13 +284,22 @@ private static void ConfigureAttributeInfoAsPredefinedType(PredefinedTypeSyntax
267284
268285 return attribute . ArgumentList . Arguments . First ( ) . Expression switch
269286 {
287+ IdentifierNameSyntax identifierName => identifierName . Identifier . Text ,
288+ PrefixUnaryExpressionSyntax unary => GetUnaryExpressionValue ( unary ) ,
270289 LiteralExpressionSyntax literal => GetLiteralExpressionValue ( literal ) ,
271290 InvocationExpressionSyntax invocation => GetInvocationExpressionValue ( invocation ) ,
272291 MemberAccessExpressionSyntax member => GetMemberAccessExpressionValue ( member ) ,
273292 _ => null
274293 } ;
275294 }
276295
296+ private static string GetUnaryExpressionValue ( PrefixUnaryExpressionSyntax unary )
297+ {
298+ var value = unary . Operand . GetText ( ) . ToString ( ) ;
299+
300+ return unary . IsKind ( SyntaxKind . UnaryMinusExpression ) ? $ "-{ value } " : value ;
301+ }
302+
277303 private static string ? GetLiteralExpressionValue ( LiteralExpressionSyntax literal )
278304 {
279305 if ( literal . Token . IsKind ( SyntaxKind . DefaultKeyword ) )
0 commit comments