@@ -19,4 +19,53 @@ public NumberField(float? defaultValue, float? max, float? min, bool isRequired
1919
2020 public float Max { get ; init ; }
2121 public float Min { get ; init ; }
22+
23+ // number box cannot have null as a valid value, so if the default value is null,
24+ // i.e. don't care, there must be an extra flag storing the info that "0" is indeed
25+ // representing the null value
26+ public override float ? Value
27+ {
28+ get => base . Value ;
29+ set
30+ {
31+ if ( DefaultValue is not null )
32+ {
33+ base . Value = value ;
34+ return ;
35+ }
36+ else if ( value == null )
37+ {
38+ _IsUsingDefault = true ;
39+ base . Value = DefaultValue ?? 0 ;
40+
41+ if ( _Value == 0 ) InvokePropertyChanged ( nameof ( IsValueChanged ) ) ;
42+ }
43+ else
44+ {
45+ _IsUsingDefault = false ;
46+ base . Value = value ;
47+ }
48+ }
49+ }
50+
51+ private bool _IsUsingDefault = true ;
52+ public override bool IsValueChanged => ! _IsUsingDefault ;
53+
54+ public override string Compile ( )
55+ {
56+ var flag = GetFlag ( ) ;
57+
58+ if ( IsRequired )
59+ {
60+ if ( ! _IsUsingDefault ) return string . Join ( Connector , flag , Value ) ;
61+ else throw new WarningException ( nameof ( Value )
62+ , $ "Value of { GetName ( ) } is required") ;
63+ }
64+ else
65+ {
66+ if ( ! _IsUsingDefault ) return string . Join ( Connector , flag , ValueToString ( Value ) ) ;
67+ else if ( DefaultValue != null ) return string . Join ( Connector , flag , ValueToString ( DefaultValue ) ) ;
68+ else return string . Empty ;
69+ }
70+ }
2271}
0 commit comments