Ewl » Canonical The canonical version of EWL Read More
Clone URL:  
Pushed to 2 repositories · View In Graph Contained in tip and canonical

Added generated checkbox form-item getters for nullable fields.

Changeset 188bb9fb525d

Parent 1f434bb5474e

by Profile picture of William GrossWilliam Gross

Changes to one file · Browse files at 188bb9fb525d Showing diff from parent 1f434bb5474e Diff from another changeset...

 
300
301
302
303
 
304
305
 
 
 
 
 
 
 
 
 
 
 
306
307
308
 
315
316
317
318
319
 
 
 
320
321
322
 
328
329
330
331
332
 
 
 
333
334
335
 
343
344
345
346
347
 
 
 
348
349
350
 
356
357
358
359
360
 
 
 
361
362
363
 
300
301
302
 
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
 
326
327
328
 
 
329
330
331
332
333
334
 
340
341
342
 
 
343
344
345
346
347
348
 
356
357
358
 
 
359
360
361
362
363
364
 
370
371
372
 
 
373
374
375
376
377
378
@@ -300,9 +300,20 @@
  }     private static void writeCheckboxFormItemGetters( TextWriter writer, ModificationField field ) { - if( !field.TypeIs( typeof( bool ) ) && !field.TypeIs( typeof( decimal ) ) ) + if( !field.TypeIs( typeof( bool ) ) && !field.TypeIs( typeof( bool? ) ) && !field.TypeIs( typeof( decimal ) ) && !field.TypeIs( typeof( decimal? ) ) )   return;   + var preFormItemStatements = field.TypeName == field.NullableTypeName + ? "var nonNullableValue = new DataValue<{0}>();".FormatWith( field.TypeIs( typeof( decimal? ) ) ? "decimal" : "bool" ) + : ""; + string getDataValueExpression( string dv ) => field.TypeName == field.NullableTypeName ? "nonNullableValue" : dv; + string getValueExpression( string dv ) => field.TypeName == field.NullableTypeName ? "value ?? {0}.Value.Value".FormatWith( dv ) : "value"; + + string getAdditionalValidationMethodExpression( string dv ) => + field.TypeName == field.NullableTypeName + ? "validator => {{ {0}.Value = nonNullableValue.Value; additionalValidationMethod?.Invoke( validator ); }}".FormatWith( dv ) + : "additionalValidationMethod"; +   // checkboxes   writeFormItemGetter(   writer, @@ -315,8 +326,9 @@
  new CSharpParameter[ 0 ],   true,   dv => - "{0}.ToCheckbox( label, setup: checkboxSetup, value: value, additionalValidationMethod: additionalValidationMethod ).ToFormItem( setup: formItemSetup, label: formItemLabel )" - .FormatWith( dv ) ); + "{0}.ToCheckbox( label, setup: checkboxSetup, value: {1}, additionalValidationMethod: {2} ).ToFormItem( setup: formItemSetup, label: formItemLabel )" + .FormatWith( getDataValueExpression( dv ), getValueExpression( dv ), getAdditionalValidationMethodExpression( dv ) ), + preFormItemStatements: preFormItemStatements );   writeFormItemGetter(   writer,   field, @@ -328,8 +340,9 @@
  new CSharpParameter[ 0 ],   true,   dv => - "{0}.ToFlowCheckbox( label, setup: checkboxSetup, value: value, additionalValidationMethod: additionalValidationMethod ).ToFormItem( setup: formItemSetup, label: formItemLabel )" - .FormatWith( dv ) ); + "{0}.ToFlowCheckbox( label, setup: checkboxSetup, value: {1}, additionalValidationMethod: {2} ).ToFormItem( setup: formItemSetup, label: formItemLabel )" + .FormatWith( getDataValueExpression( dv ), getValueExpression( dv ), getAdditionalValidationMethodExpression( dv ) ), + preFormItemStatements: preFormItemStatements );     // radio buttons   writeFormItemGetter( @@ -343,8 +356,9 @@
  new CSharpParameter[ 0 ],   true,   dv => - "{0}.ToRadioButton( group, label, setup: radioButtonSetup, value: value, additionalValidationMethod: additionalValidationMethod ).ToFormItem( setup: formItemSetup, label: formItemLabel )" - .FormatWith( dv ) ); + "{0}.ToRadioButton( group, label, setup: radioButtonSetup, value: {1}, additionalValidationMethod: {2} ).ToFormItem( setup: formItemSetup, label: formItemLabel )" + .FormatWith( getDataValueExpression( dv ), getValueExpression( dv ), getAdditionalValidationMethodExpression( dv ) ), + preFormItemStatements: preFormItemStatements );   writeFormItemGetter(   writer,   field, @@ -356,8 +370,9 @@
  new CSharpParameter[ 0 ],   true,   dv => - "{0}.ToFlowRadioButton( group, label, setup: radioButtonSetup, value: value, additionalValidationMethod: additionalValidationMethod ).ToFormItem( setup: formItemSetup, label: formItemLabel )" - .FormatWith( dv ) ); + "{0}.ToFlowRadioButton( group, label, setup: radioButtonSetup, value: {1}, additionalValidationMethod: {2} ).ToFormItem( setup: formItemSetup, label: formItemLabel )" + .FormatWith( getDataValueExpression( dv ), getValueExpression( dv ), getAdditionalValidationMethodExpression( dv ) ), + preFormItemStatements: preFormItemStatements );   }     private static void writeFileCollectionFormItemGetters( TextWriter writer, ModificationField field, string valueParamTypeName ) {