public void Rebind(Dictionary <string, object> bindingObjects, Dictionary <string, Exception> conversionErrors) { IValidatingUiControl validating = _sourceProducer as IValidatingUiControl; if (validating != null && validating.IsValid == false) { conversionErrors.Add(_bindSourceName, new InvalidOperationException(validating.ValidationError)); } else { object value = _sourceProducerGetProperty.Invoke(_sourceProducer, null); Exception conversionError; bindingObjects[_bindSourceName] = ValueTypeConverter.TryConvert(value, _destinationObjectType, out conversionError); if (conversionError != null) { conversionErrors.Add(_bindSourceName, conversionError); } } }
private Expression CreateSimpleFilterExpression(object value, Expression fieldExpression) { Type propertyType = this.PropertyInfo.PropertyType; if (propertyType == typeof(DateTime) || propertyType == typeof(DateTime?)) { return(CreateFilterByDateTimeExpression(value, fieldExpression)); } if (value != null && !propertyType.IsInstanceOfType(value)) { Exception ex; value = ValueTypeConverter.TryConvert(value, propertyType, out ex); if (ex != null) { throw new InvalidOperationException($"Failed to convent a filtering value to type '{propertyType}'"); } } return(Expression.Equal(fieldExpression, Expression.Constant(value, propertyType))); }
public bool TryGetValue(RelativeRoute routePart, out TValue value) { var stringValue = routePart.PathSegments.Single(); if (string.IsNullOrEmpty(stringValue)) { value = default(TValue); return(false); } if (IsGuidField) { Guid tempGuid; if (!UrlUtils.TryExpandGuid(stringValue, out tempGuid) && !Guid.TryParse(stringValue, out tempGuid)) { value = default(TValue); return(false); } value = (TValue)(tempGuid as object); return(true); } if (IsStringField) { value = (TValue)(UrlUtils.DecodeUrlInvalidCharacters(stringValue) as object); return(true); } Exception exception; object valueObj = ValueTypeConverter.TryConvert(stringValue, typeof(TValue), out exception); bool success = valueObj != null; value = success ? (TValue)valueObj : default(TValue); return(success); }