@@ -615,6 +615,7 @@ partial class MemberMeta
615615 public int Order { get ; }
616616 public bool HasExplicitOrder { get ; }
617617 public MemberKind Kind { get ; }
618+ public string DefaultValueExpression { get ; } = "default!" ;
618619
619620 MemberMeta ( int order )
620621 {
@@ -644,8 +645,12 @@ public MemberMeta(ISymbol symbol, IMethodSymbol? constructor, ReferenceSymbols r
644645
645646 if ( constructor != null )
646647 {
647- this . IsConstructorParameter = constructor . TryGetConstructorParameter ( symbol , out var constructorParameterName ) ;
648- this . ConstructorParameterName = constructorParameterName ;
648+ this . IsConstructorParameter = constructor . TryGetConstructorParameter ( symbol , out var constructorParameter ) ;
649+ this . ConstructorParameterName = constructorParameter ? . Name ;
650+ if ( constructorParameter ? . HasExplicitDefaultValue == true )
651+ {
652+ DefaultValueExpression = EmitConstantValue ( constructorParameter . ExplicitDefaultValue ) ;
653+ }
649654 }
650655 else
651656 {
@@ -664,6 +669,24 @@ public MemberMeta(ISymbol symbol, IMethodSymbol? constructor, ReferenceSymbols r
664669 ;
665670 MemberType = f . Type ;
666671
672+ // Detect default value
673+ foreach ( var syntaxReference in f . DeclaringSyntaxReferences )
674+ {
675+ var syntax = syntaxReference . GetSyntax ( ) ;
676+ if ( syntax is FieldDeclarationSyntax { Declaration . Variables : { Count : > 0 } variables } )
677+ {
678+ if ( variables . First ( ) . Initializer is { } initializer )
679+ {
680+ DefaultValueExpression = initializer . Value . ToString ( ) ;
681+ break ;
682+ }
683+ }
684+ if ( syntax is VariableDeclaratorSyntax { Initializer : { } initializer2 } )
685+ {
686+ DefaultValueExpression = initializer2 . Value . ToString ( ) ;
687+ break ;
688+ }
689+ }
667690 }
668691 else if ( symbol is IPropertySymbol p )
669692 {
@@ -676,6 +699,16 @@ public MemberMeta(ISymbol symbol, IMethodSymbol? constructor, ReferenceSymbols r
676699#endif
677700 && ( p . SetMethod != null && ! p . SetMethod . IsInitOnly ) ;
678701 MemberType = p . Type ;
702+
703+ // Detect default value
704+ foreach ( var syntaxReference in p . DeclaringSyntaxReferences )
705+ {
706+ if ( syntaxReference . GetSyntax ( ) is PropertyDeclarationSyntax { Initializer : { } initializer } )
707+ {
708+ DefaultValueExpression = initializer . Value . ToString ( ) ;
709+ break ;
710+ }
711+ }
679712 }
680713 else
681714 {
0 commit comments