public override object ConvertFrom(ITypeDescriptorContext?context, CultureInfo?culture, object value) { if (value is string s) { // ReSharper disable once HeapView.BoxingAllocation return(Moment.Parse(s)); } return(base.ConvertFrom(context, culture, value) !); }
public Task BindModelAsync(ModelBindingContext bindingContext) { if (bindingContext == null) { throw new ArgumentNullException(nameof(bindingContext)); } try { var sValue = bindingContext.ValueProvider.GetValue(bindingContext.ModelName).FirstValue ?? ""; var result = Moment.Parse(sValue); bindingContext.Result = ModelBindingResult.Success(result); } catch (Exception) { bindingContext.Result = ModelBindingResult.Failed(); } return(Task.CompletedTask); }
public void Parse() { Assert.AreEqual(Moment.NewtonMetre, Moment.Parse("1 N*m")); }
public void Parse() { AssertAreEqual(Moment.NewtonMetre, Moment.Parse("1 N*m")); AssertAreEqual(Moment.KilonewtonMetre, Moment.Parse("1 kN*m")); }