public void should_convert_from_string() { var converter = new IntConverter(); var result = converter.ConvertFromString("10", Mock.Of <IReaderRow>(), null); result.Should().Be(10); }
public void should_convert_none_literal_to_nullable_int() { var converter = new IntConverter(); var result = converter.ConvertFromString(TimetableLiterals.None, Mock.Of <IReaderRow>(), null); result.Should().BeNull(); }
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (null == value) { return(new CcBorder()); } //从字符串解析 if (value is string stringValue) { if (stringValue.Length <= 0) { return(new CcBorder()); } int size = 0, radius = 0; CcCtrlPosition direction = CcCtrlPosition.None; CcCtrlCorner corners = CcCtrlCorner.None; stringValue.Split(Separator).ForEach(s => { if (s.StartsWith(KeySize)) { size = (int)IntConverter.ConvertFromString(context, culture, s.Substring(KeySize.Length)); } else if (s.StartsWith(KeyDirection)) { direction = (CcCtrlPosition)PositionConverter.ConvertFromString(context, culture, s.Substring(KeyDirection.Length)); } else if (s.StartsWith(KeyRadius)) { radius = (int)IntConverter.ConvertFromString(context, culture, s.Substring(KeyRadius.Length)); } else if (s.StartsWith(KeyCorners)) { corners = (CcCtrlCorner)CornerConverter.ConvertFromString(context, culture, s.Substring(KeyCorners.Length)); } }); return(new CcBorder { Size = size, OpenDirection = direction, Radius = radius, RadiusCorners = corners }); } return(base.ConvertFrom(context, culture, value)); }