@@ -18,6 +18,12 @@ public class ClassModel(GeneratorConfiguration configuration) : ReferenceTypeMod
1818 public bool IsSubstitution { get ; set ; }
1919 public TypeModel BaseClass { get ; set ; }
2020 public TypeModel TextValueType { get ; set ; }
21+
22+ ///
23+ /// Default for the text value of a simple-content class, taken from the default of the
24+ /// (only) element that uses this anonymous type.
25+ ///
26+ public string TextValueDefault { get ; set ; }
2127 public List < ClassModel > DerivedTypes { get ; set ; } = [ ] ;
2228 public override bool IsSubtype => BaseClass != null ;
2329
@@ -199,12 +205,15 @@ public override CodeTypeDeclaration Generate()
199205 var enableDataBinding = Configuration . EnableDataBinding ;
200206 var typeReference = BaseClass . GetReferenceFor ( Namespace ) ;
201207
208+ var textDefaultExpression = TextValueDefault != null ? BaseClass . GetDefaultValueFor ( TextValueDefault , false ) : null ;
209+
202210 CodeMemberField backingFieldMember = null ;
203- if ( enableDataBinding )
211+ if ( enableDataBinding || textDefaultExpression != null )
204212 {
205213 backingFieldMember = new CodeMemberField ( typeReference , textName . ToBackingField ( Configuration . PrivateMemberPrefix ) )
206214 {
207- Attributes = MemberAttributes . Private
215+ Attributes = MemberAttributes . Private ,
216+ InitExpression = textDefaultExpression
208217 } ;
209218 classDeclaration . Members . Add ( backingFieldMember ) ;
210219 }
@@ -222,6 +231,14 @@ public override CodeTypeDeclaration Generate()
222231 var attribute = AttributeDecl < XmlTextAttribute > ( ) ;
223232 var valuePropertyModel = new PropertyModel ( Configuration , textName , BaseClass , this ) ;
224233
234+ if ( textDefaultExpression != null )
235+ {
236+ valuePropertyModel . SetDefaultValue ( TextValueDefault ) ;
237+
238+ if ( textDefaultExpression is CodePrimitiveExpression or CodeFieldReferenceExpression )
239+ text . CustomAttributes . Add ( valuePropertyModel . CreateDefaultValueAttribute ( typeReference , textDefaultExpression ) ) ;
240+ }
241+
225242 if ( BaseClass is SimpleModel simpleModel )
226243 {
227244 docs . AddRange ( simpleModel . Restrictions . Select ( r => new DocumentationModel { Language = English , Text = r . Description } ) ) ;
0 commit comments