mardi 12 janvier 2016

Nullable and Empty

I've got an incredibly large legacy application, the problem stems from textbox in the application. It returns a String.Empty or "", which will cause me to receive an error:

Input string was not in a correct format. System.FormatException.

The code I'm calling:

if (property.PropertyType.IsGenericType && property.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
     property.SetValue(model, Convert.ChangeType(controlType.Value, property.PropertyType.GetGenericArguments()[0]), null);
else { property.SetValue(model, Convert.ChangeType(controlType.Value, property.PropertyType), null); }

Shouldn't it simply return an empty string, why would it fail?





Aucun commentaire:

Enregistrer un commentaire