public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { try { return(reader.TokenType == JsonToken.Null ? null : BalanceLocator.Parse(reader.Value.ToString())); } catch (FormatException) { throw new JsonObjectException("Invalid BalanceLocator", reader); } }
public bool BindModel(System.Web.Http.Controllers.HttpActionContext actionContext, ModelBindingContext bindingContext) { if (!typeof(BalanceLocator).IsAssignableFrom(bindingContext.ModelType)) { return(false); } ValueProviderResult val = bindingContext.ValueProvider.GetValue( bindingContext.ModelName); if (val == null) { return(true); } string key = val.RawValue as string; bindingContext.Model = BalanceLocator.Parse(key); return(true); }
private static BalanceLocator UnEscapeLocator(string str) { return(BalanceLocator.Parse(str.Substring(1), true)); }