public bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext) { if (bindingContext.ModelType != typeof(Location)) { return(false); } ValueProviderResult input = bindingContext.ValueProvider.GetValue(bindingContext.ModelName); var key = input.RawValue as string; if (key == null) { return(false); } Location location; if (LocationsCache.TryGetValue(key, out location) || Location.TryParse(key, out location)) { bindingContext.Model = location; return(true); } return(false); }
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { var input = value as string; if (input != null) { Location location; if (Location.TryParse(input, out location)) { return(location); } } return(base.ConvertFrom(context, culture, value)); }