public ApplyValueResult TryGetValueOnUi(out object value) { var result = ApplyValueResult.UnknownError; value = null; if (!mContainer.HasEnoughInformationToWork() || InstancePropertyType == null) { result = ApplyValueResult.NotEnoughInformation; } else { try { var usableString = ConvertStringToUsableValue(); var converter = TypeDescriptor.GetConverter(InstancePropertyType); bool canConverterConvert = GetIfConverterCanConvert(converter); if (canConverterConvert) { // The user may have put in a bad value try { // This used to convert from invariant string, but we want to use commas if the native // computer settings use commas value = converter.ConvertFromString(usableString); result = ApplyValueResult.Success; } catch (FormatException) { result = ApplyValueResult.InvalidSyntax; } catch { result = ApplyValueResult.InvalidSyntax; } } else { result = ApplyValueResult.NotSupported; } } catch { result = ApplyValueResult.UnknownError; } } return(result); }
public static bool TryGetValueOnInstance(this IDataUi dataUi, out object value) { //////////////////Early Out///////////////////////////////// if (dataUi.HasEnoughInformationToWork() == false || dataUi.InstanceMember.IsWriteOnly) { value = null; return(false); } ////////////////End Early Out/////////////////////////////// value = dataUi.InstanceMember.Value; return(true); }
private static void GetIfValuesCanBeSetOnInstance(IDataUi dataUi, out ApplyValueResult result, out bool hasErrorOccurred) { result = ApplyValueResult.UnknownError; hasErrorOccurred = false; if (dataUi.HasEnoughInformationToWork() == false) { result = ApplyValueResult.NotEnoughInformation; hasErrorOccurred = true; } if (dataUi.InstanceMember.IsReadOnly) { result = ApplyValueResult.NotSupported; hasErrorOccurred = true; } if (dataUi.SuppressSettingProperty) { result = ApplyValueResult.NotEnabled; hasErrorOccurred = true; } }