private void ToObjectArray(string p, ref object[] result, bool convert) { string[] elements = p.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); result = new object[elements.Length]; if (converters == null) { decimal temp = 0; converters = new IConverter[elements.Length]; for (int i = 0; i < elements.Length; i++) if (convert && decimal.TryParse(elements[i], out temp)) { converters[i] = new DecimalConverter(); result[i] = temp; } else { converters[i] = new StringConverter(); result[i] = elements[i]; } } else for (int i = 0; i < elements.Length; i++) result[i] = converters[i].convert(elements[i]); }
public void InvStringThousandsTooBig() { var converter = new DecimalConverter(); var result = converter.Convert("123456789012345678901234567890.456"); Assert.AreEqual(null, result); }
public void FromUInt() { var converter = new DecimalConverter(); var result = converter.Convert(77u); Assert.AreEqual(77m, result); }
public void FromULong() { var converter = new DecimalConverter(); var result = converter.Convert(ulong.MaxValue); Assert.AreEqual((decimal)ulong.MaxValue, result); }
public void FromUShort() { var converter = new DecimalConverter(); var result = converter.Convert((ushort)77); Assert.AreEqual(77m, result); }
public LoonkostFormViewModel(Loonkost loon, IEnumerable <Doelgroep> doelgroepen) { DecimalConverter dc = new DecimalConverter(); Id = loon.Id; AantalUrenPerWeek = loon.AantalUrenPerWeek; Beschrijving = loon.Beschrijving; Bedrag = dc.ConvertToString(loon.Bedrag); BrutoMaandloonFulltime = dc.ConvertToString(loon.BrutoMaandloonFulltime); Ondersteuningspremie = (int)loon.Ondersteuningspremie; AantalMaandenIBO = loon.AantalMaandenIBO; IBOPremie = dc.ConvertToString(loon.IBOPremie); doelgroep = loon.Doelgroep?.DoelgroepId; Doelgroep mogelijkVerwijderd = doelgroepen.SingleOrDefault(d => d.DoelgroepId == loon.Doelgroep?.DoelgroepId); if (mogelijkVerwijderd == null) { List <Doelgroep> doelgroeps = doelgroepen.ToList(); doelgroeps.Add(loon.Doelgroep); doelgroepen = doelgroeps; } DoelgroepSelectList = new SelectList(doelgroepen, nameof(Doelgroep.DoelgroepId), nameof(Doelgroep.Omschrijving), doelgroep); }
public override void ExecuteResult(ControllerContext context) { if (context == null) { throw new ArgumentNullException("context"); } HttpResponseBase response = context.HttpContext.Response; if (!string.IsNullOrEmpty(this.ContentType)) { response.ContentType = this.ContentType; } else { response.ContentType = "application/json"; } if (this.ContentEncoding != null) { response.ContentEncoding = this.ContentEncoding; } if (this.Data != null) { JsonConvert.DefaultSettings = () => new JsonSerializerSettings { ContractResolver = new NullToEmptyStringResolver() }; //var str = JsonConvert.SerializeObject(Data, Formatting.None, // new JsonConverter[] { new DecimalConverter(), new DateTimeConverter() }); var decConverter = new DecimalConverter(); var timeConverter = new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" }; var str = JsonConvert.SerializeObject(Data, Formatting.Indented, new JsonConverter[] { decConverter, timeConverter }); response.Write(str); } }
public void FromDecimal() { var converter = new DecimalConverter(); var result = converter.Convert(71m / 49m); Assert.AreEqual(71m / 49m, result); }
static Converter() { BoolConverter.Initialize(); CharConverter.Initialize(); ByteConverter.Initialize(); SByteConverter.Initialize(); Int16Converter.Initialize(); UInt16Converter.Initialize(); Int32Converter.Initialize(); UInt32Converter.Initialize(); Int64Converter.Initialize(); UInt64Converter.Initialize(); SingleConverter.Initialize(); DoubleConverter.Initialize(); DecimalConverter.Initialize(); BigIntegerConverter.Initialize(); BytesConverter.Initialize(); CharsConverter.Initialize(); StringConverter.Initialize(); StringBuilderConverter.Initialize(); DateTimeConverter.Initialize(); TimeSpanConverter.Initialize(); GuidConverter.Initialize(); MemoryStreamConverter.Initialize(); StreamConverter.Initialize(); }
public void FromByte() { var converter = new DecimalConverter(); var result = converter.Convert((byte)77); Assert.AreEqual(77m, result); }
public void ConvertToCsvItemTest() { var c = new DecimalConverter(); Assert.AreEqual("1000", c.ConvertToCsvItem(CreateConvertToCsvItemContext(1000m))); Assert.AreEqual("1,000", c.ConvertToCsvItem(CreateConvertToCsvItemContext(1000m, "FormattedValue"))); }
public void InvString() { var converter = new DecimalConverter(); var result = converter.Convert("1.234"); Assert.AreEqual(1.234m, result); }
public void InvStringThousands() { var converter = new DecimalConverter(); var result = converter.Convert("1234.456"); Assert.AreEqual(1234.456m, result); }
public void FromDouble() { var converter = new DecimalConverter(); var result = converter.Convert(4d / 5d); Assert.AreEqual((decimal)(4d / 5d), result); }
/// <summary> /// Convert a field to a string /// </summary> /// <param name="o">object we want to convert</param> /// <returns>string representation of the string</returns> internal string ValueToString(object o) { if (mDecimalConv == null) { mDecimalConv = new DecimalConverter(DecimalSeparator); mDoubleConv = new DoubleConverter(DecimalSeparator); mSingleConv = new SingleConverter(DecimalSeparator); mDateConv = new DateTimeConverter(DateFormat); } if (o == null) { return(string.Empty); } else if (o is DateTime) { return(mDateConv.FieldToString(o)); } else if (o is decimal) { return(mDecimalConv.FieldToString(o)); } else if (o is double) { return(mDoubleConv.FieldToString(o)); } else if (o is float) { return(mSingleConv.FieldToString(o)); } else { return(o.ToString()); } }
private decimal?ConvertToObjectItem(string csvItem) { var c = new DecimalConverter(); Assert.IsTrue(c.TryConvertToObjectItem(CreateConvertToObjectItemContext(csvItem), out object?result, out string _)); return((decimal?)result); }
public void FromFloat() { var converter = new DecimalConverter(); var result = converter.Convert(4f / 5f); Assert.AreEqual((decimal)(4f / 5f), result); }
public void Decimal_Converter_Test() { IConverter binaryConverter = new DecimalConverter(new DecimalNumber("123.456")); var converted = binaryConverter.Convert(); converted.IntegerPart.Should().Be("123"); converted.FloatPart.Should().Be("456"); converted.Base.Should().Be(10); converted.ToString().Should().Be("123.456"); binaryConverter = new DecimalConverter(new OctalNumber("123.456")); converted = binaryConverter.Convert(); converted.IntegerPart.Should().Be("83"); converted.FloatPart.Should().Be("589844"); converted.Base.Should().Be(10); converted.ToString().Should().Be("83.589844"); binaryConverter = new DecimalConverter(new HexadecimalNumber("123.456")); converted = binaryConverter.Convert(); converted.IntegerPart.Should().Be("291"); converted.FloatPart.Should().Be("270996"); converted.Base.Should().Be(10); converted.ToString().Should().Be("291.270996"); binaryConverter = new DecimalConverter(new BinaryNumber("101.111")); converted = binaryConverter.Convert(); converted.IntegerPart.Should().Be("5"); converted.FloatPart.Should().Be("875"); converted.Base.Should().Be(10); converted.ToString().Should().Be("5.875"); }
public void PropertiesTest() { var converter = new DecimalConverter(); Assert.AreEqual(true, converter.AcceptsNativeType); Assert.AreEqual(typeof(decimal), converter.ConvertedType); }
public void TryConvertToObjectItemRequireTest() { var c = new DecimalConverter(); var context = CreateConvertToObjectItemContext(string.Empty); Assert.IsFalse(c.TryConvertToObjectItem(context, out object?_, out string message)); Assert.AreEqual(CsvConfig.Current.ValidationMessage.GetRequiredError(context), message); }
public OverurenBesparingViewModel(OverurenBesparing besparing) : this() { DecimalConverter dc = new DecimalConverter(); Id = besparing.Id; Bedrag = dc.ConvertToString(besparing.Bedrag); }
public static int NullableDecimalToURI(char[] buf, int pos, decimal?value) { if (value == null) { return(pos); } return(DecimalConverter.Serialize(value.Value, buf, pos)); }
public SubsidieViewModel(Subsidie subsidie) : this() { DecimalConverter dc = new DecimalConverter(); Id = subsidie.Id; Bedrag = dc.ConvertToString(subsidie.Bedrag); }
public ExtraProductiviteitViewModel(ExtraProductiviteit productiviteit) : this() { DecimalConverter dc = new DecimalConverter(); Id = productiviteit.Id; Bedrag = dc.ConvertToString(productiviteit.Bedrag); }
public InnerContractToFirstContractConverterCollection( IPathFormatterCollection pathFormatterCollection, DefaultConverter defaultConverter, DecimalConverter decimalConverter) : base(pathFormatterCollection, new EnumStringConverter()) { this.defaultConverter = defaultConverter; this.decimalConverter = decimalConverter; }
/// <summary> /// Extends ConvertTo so that methods that return a specific type object given a Type parameter can be /// used as generic method and casting is not required. /// <example> /// decimalconverter.ConvertTo<int>(context, culture, value); /// </example> /// </summary> public static T ConvertTo <T>(this DecimalConverter decimalconverter, ITypeDescriptorContext context, System.Globalization.CultureInfo culture, Object value) { if (decimalconverter == null) { throw new ArgumentNullException("decimalconverter"); } return((T)decimalconverter.ConvertTo(context, culture, value, typeof(T))); }
/// <summary> /// Extends ConvertTo so that methods that return a specific type object given a Type parameter can be /// used as generic method and casting is not required. /// <example> /// typeconverter.ConvertTo<int>(value); /// </example> /// </summary> public static T ConvertTo <T>(this DecimalConverter typeconverter, Object value) { if (typeconverter == null) { throw new ArgumentNullException("typeconverter"); } return((T)typeconverter.ConvertTo(value, typeof(T))); }
public UitzendKrachtBesparingViewModel(UitzendKrachtBesparing baat) { DecimalConverter dc = new DecimalConverter(); Id = baat.Id; Type = baat.Type; Soort = baat.Soort; Beschrijving = baat.Beschrijving; Bedrag = dc.ConvertToString(baat.Bedrag); }
public void CanSerializeAndDeserialize() { decimal value = decimal.MaxValue; DecimalConverter converter = new DecimalConverter(); byte[] bytes = converter.Serialize(value); decimal valueFromBytes = converter.Deserialize(bytes); Assert.Equal(valueFromBytes, value); }
public ExtraBesparingViewModel(ExtraBesparing besparing) { DecimalConverter dc = new DecimalConverter(); Id = besparing.Id; Type = besparing.Type; Soort = besparing.Soort; Beschrijving = besparing.Beschrijving; Bedrag = dc.ConvertToString(besparing.Bedrag); }
public BegeleidingsKostViewModel(BegeleidingsKost kost) { DecimalConverter dc = new DecimalConverter(); Id = kost.Id; Type = kost.Type; Soort = kost.Soort; Uren = kost.Uren; BrutoMaandloonBegeleider = dc.ConvertToString(kost.BrutoMaandloonBegeleider); }
public void ShouldFailToConvertToCSharpValue() { //Arrange object value0; object value1; object value2; var converter = new DecimalConverter(); //Act bool success0 = converter.TryConvertToCSharpValue("9E10", out value0); bool success1 = converter.TryConvertToCSharpValue("1000000000000000000000000000000000000000000000000000000000", out value1); bool success2 = converter.TryConvertToCSharpValue("0/0", out value2); //Assert Assert.IsFalse(success0); Assert.IsFalse(success1); Assert.IsFalse(success2); }
public void ShouldConvertToCellValue() { //Arrange string value0; string value1; string value2; var converter = new DecimalConverter(); //Act bool success0 = converter.TryConvertToCellValue(0.123m, out value0); bool success1 = converter.TryConvertToCellValue(1000000000m, out value1); bool success2 = converter.TryConvertToCellValue(-12.84848715m, out value2); //Assert Assert.IsTrue(success0); Assert.IsTrue(success1); Assert.IsTrue(success2); Assert.AreEqual("0.123", value0); Assert.AreEqual("1000000000", value1); Assert.AreEqual("-12.84848715", value2); }
public void ShouldConvertToCSharpValue() { //Arrange object value0; object value1; object value2; var converter = new DecimalConverter(); //Act bool success0 = converter.TryConvertToCSharpValue("0.123", out value0); bool success1 = converter.TryConvertToCSharpValue("10000000000", out value1); bool success2 = converter.TryConvertToCSharpValue("-12.84848715", out value2); //Assert Assert.IsTrue(success0); Assert.IsTrue(success1); Assert.IsTrue(success2); Assert.AreEqual(0.123m, value0); Assert.AreEqual(10000000000m, value1); Assert.AreEqual(-12.84848715m, value2); }
public void ShouldFailToConvertToCellValue() { //Arrange string value0; string value1; string value2; var converter = new DecimalConverter(); //Act bool success0 = converter.TryConvertToCellValue(0.18f, out value0); bool success1 = converter.TryConvertToCellValue(Int64.MaxValue, out value1); bool success2 = converter.TryConvertToCellValue("NaN", out value2); //Assert Assert.IsFalse(success0); Assert.IsFalse(success1); Assert.IsFalse(success2); }