public (byte[] Result, decimal Value) DecimalTestSerialize() { decimal value = 453445.54245m; var result = BinaryGo.Binary.BinarySerializer.NormalInstance.Serialize(value).ToArray(); DecimalStruct decimalStruct = new DecimalStruct() { Byte0 = result[0], Byte1 = result[1], Byte2 = result[2], Byte3 = result[3], Byte4 = result[4], Byte5 = result[5], Byte6 = result[6], Byte7 = result[7], Byte8 = result[8], Byte9 = result[9], Byte10 = result[10], Byte11 = result[11], Byte12 = result[12], Byte13 = result[13], Byte14 = result[14], Byte15 = result[15] }; Assert.True(value == decimalStruct.Value, $"Your Value: {value} Serialize Value: {decimalStruct.Value}"); return(result, value); }
/// <summary> /// write a decimal struct /// </summary> /// <param name="data"></param> public void Write(ref decimal data) { if (Length + 16 > _Buffer.Length) { _capacity += 16; Resize(); } var value = new DecimalStruct() { Value = data }; _Buffer[Length] = value.Byte0; _Buffer[Length + 1] = value.Byte1; _Buffer[Length + 2] = value.Byte2; _Buffer[Length + 3] = value.Byte3; _Buffer[Length + 4] = value.Byte4; _Buffer[Length + 5] = value.Byte5; _Buffer[Length + 6] = value.Byte6; _Buffer[Length + 7] = value.Byte7; _Buffer[Length + 8] = value.Byte8; _Buffer[Length + 9] = value.Byte9; _Buffer[Length + 10] = value.Byte10; _Buffer[Length + 11] = value.Byte11; _Buffer[Length + 12] = value.Byte12; _Buffer[Length + 13] = value.Byte13; _Buffer[Length + 14] = value.Byte14; _Buffer[Length + 15] = value.Byte15; Length += 16; }
public void SetDecimal() { if (_dstruct != null) { return; } // Debug.Assert(!this.IsDecimal); switch (_xsdtype.TypeCode) { case XmlTypeCode.Byte: case XmlTypeCode.UnsignedByte: case XmlTypeCode.Short: case XmlTypeCode.UnsignedShort: case XmlTypeCode.Int: case XmlTypeCode.UnsignedInt: case XmlTypeCode.Long: case XmlTypeCode.UnsignedLong: case XmlTypeCode.Decimal: case XmlTypeCode.Integer: case XmlTypeCode.PositiveInteger: case XmlTypeCode.NonNegativeInteger: case XmlTypeCode.NegativeInteger: case XmlTypeCode.NonPositiveInteger: if (_isList) { _dstruct = new DecimalStruct(_dim); for (int i = 0; i < _dim; i++) { _dstruct.Dvalue[i] = Convert.ToDecimal(((Array)_ovalue).GetValue(i), NumberFormatInfo.InvariantInfo); } } else { //not list _dstruct = new DecimalStruct(); //possibility of list of length 1. _dstruct.Dvalue[0] = Convert.ToDecimal(_ovalue, NumberFormatInfo.InvariantInfo); } _dstruct.IsDecimal = true; break; default: if (_isList) { _dstruct = new DecimalStruct(_dim); } else { _dstruct = new DecimalStruct(); } break; } }
public void SetDecimal() { if (this.dstruct == null) { switch (this.xsdtype.TypeCode) { case XmlTypeCode.Integer: case XmlTypeCode.NonPositiveInteger: case XmlTypeCode.NegativeInteger: case XmlTypeCode.Long: case XmlTypeCode.Int: case XmlTypeCode.Short: case XmlTypeCode.Byte: case XmlTypeCode.NonNegativeInteger: case XmlTypeCode.UnsignedLong: case XmlTypeCode.UnsignedInt: case XmlTypeCode.UnsignedShort: case XmlTypeCode.UnsignedByte: case XmlTypeCode.PositiveInteger: case XmlTypeCode.Decimal: if (!this.isList) { this.dstruct = new DecimalStruct(); this.dstruct.Dvalue[0] = Convert.ToDecimal(this.ovalue, NumberFormatInfo.InvariantInfo); break; } this.dstruct = new DecimalStruct(this.dim); for (int i = 0; i < this.dim; i++) { this.dstruct.Dvalue[i] = Convert.ToDecimal(((Array)this.ovalue).GetValue(i), NumberFormatInfo.InvariantInfo); } break; default: if (this.isList) { this.dstruct = new DecimalStruct(this.dim); } else { this.dstruct = new DecimalStruct(); } return; } this.dstruct.IsDecimal = true; } }
public void SetDecimal() { if (this.dstruct != null) { return; } //list // can't use switch-case for type // from derived to base for safe, does it really affect? if (this.isList) { this.dstruct = new DecimalStruct(this.dim); // Debug.Assert(!this.IsDecimal); if ((xsdtype is Datatype_byte) || (xsdtype is Datatype_unsignedByte) || (xsdtype is Datatype_short) || (xsdtype is Datatype_unsignedShort) || (xsdtype is Datatype_int) || (xsdtype is Datatype_unsignedInt) || (xsdtype is Datatype_long) || (xsdtype is Datatype_unsignedLong) || (xsdtype is Datatype_decimal) || (xsdtype is Datatype_integer) || (xsdtype is Datatype_positiveInteger) || (xsdtype is Datatype_nonNegativeInteger) || (xsdtype is Datatype_negativeInteger) || (xsdtype is Datatype_nonPositiveInteger)) { for (int i = 0; i < this.dim; i++) { this.dstruct.Dvalue[i] = Convert.ToDecimal(((Array)this.ovalue).GetValue(i)); } this.dstruct.IsDecimal = true; } } else //not list { this.dstruct = new DecimalStruct(); if ((xsdtype is Datatype_byte) || (xsdtype is Datatype_unsignedByte) || (xsdtype is Datatype_short) || (xsdtype is Datatype_unsignedShort) || (xsdtype is Datatype_int) || (xsdtype is Datatype_unsignedInt) || (xsdtype is Datatype_long) || (xsdtype is Datatype_unsignedLong) || (xsdtype is Datatype_decimal) || (xsdtype is Datatype_integer) || (xsdtype is Datatype_positiveInteger) || (xsdtype is Datatype_nonNegativeInteger) || (xsdtype is Datatype_negativeInteger) || (xsdtype is Datatype_nonPositiveInteger)) { //possibility of list of length 1. this.dstruct.Dvalue[0] = Convert.ToDecimal(this.ovalue); this.dstruct.IsDecimal = true; } } }
public void SetDecimal () { if (this.dstruct != null) { return; } // Debug.Assert(!this.IsDecimal); switch(xsdtype.TypeCode) { case XmlTypeCode.Byte: case XmlTypeCode.UnsignedByte: case XmlTypeCode.Short: case XmlTypeCode.UnsignedShort: case XmlTypeCode.Int: case XmlTypeCode.UnsignedInt: case XmlTypeCode.Long: case XmlTypeCode.UnsignedLong: case XmlTypeCode.Decimal: case XmlTypeCode.Integer: case XmlTypeCode.PositiveInteger: case XmlTypeCode.NonNegativeInteger: case XmlTypeCode.NegativeInteger: case XmlTypeCode.NonPositiveInteger: if (this.isList) { this.dstruct = new DecimalStruct(this.dim); for (int i = 0; i < this.dim; i ++) { this.dstruct.Dvalue[i] = Convert.ToDecimal (((Array) this.ovalue).GetValue(i),NumberFormatInfo.InvariantInfo); } } else { //not list this.dstruct = new DecimalStruct(); //possibility of list of length 1. this.dstruct.Dvalue[0] = Convert.ToDecimal (this.ovalue, NumberFormatInfo.InvariantInfo); } this.dstruct.IsDecimal = true; break; default: if (this.isList) { this.dstruct = new DecimalStruct(this.dim); } else { this.dstruct = new DecimalStruct(); } break; } }
public void SetDecimal () { if (this.dstruct != null) { return; } //list // can't use switch-case for type // from derived to base for safe, does it really affect? if (this.isList) { this.dstruct = new DecimalStruct(this.dim); // Debug.Assert(!this.IsDecimal); if ((xsdtype is Datatype_byte) || (xsdtype is Datatype_unsignedByte) ||(xsdtype is Datatype_short) ||(xsdtype is Datatype_unsignedShort) ||(xsdtype is Datatype_int) ||(xsdtype is Datatype_unsignedInt) ||(xsdtype is Datatype_long) ||(xsdtype is Datatype_unsignedLong) ||(xsdtype is Datatype_decimal) || (xsdtype is Datatype_integer) ||(xsdtype is Datatype_positiveInteger) || (xsdtype is Datatype_nonNegativeInteger) ||(xsdtype is Datatype_negativeInteger) ||(xsdtype is Datatype_nonPositiveInteger)) { for (int i = 0; i < this.dim; i ++) { this.dstruct.Dvalue[i] = Convert.ToDecimal (((Array) this.ovalue).GetValue(i)); } this.dstruct.IsDecimal = true; } } else { //not list this.dstruct = new DecimalStruct(); if ((xsdtype is Datatype_byte) || (xsdtype is Datatype_unsignedByte) ||(xsdtype is Datatype_short) ||(xsdtype is Datatype_unsignedShort) ||(xsdtype is Datatype_int) ||(xsdtype is Datatype_unsignedInt) ||(xsdtype is Datatype_long) ||(xsdtype is Datatype_unsignedLong) ||(xsdtype is Datatype_decimal) || (xsdtype is Datatype_integer) ||(xsdtype is Datatype_positiveInteger) || (xsdtype is Datatype_nonNegativeInteger) ||(xsdtype is Datatype_negativeInteger) ||(xsdtype is Datatype_nonPositiveInteger)) { //possibility of list of length 1. this.dstruct.Dvalue[0] = Convert.ToDecimal (this.ovalue); this.dstruct.IsDecimal = true; } } }
public void SetDecimal() { if (this.dstruct == null) { switch (this.xsdtype.TypeCode) { case XmlTypeCode.Integer: case XmlTypeCode.NonPositiveInteger: case XmlTypeCode.NegativeInteger: case XmlTypeCode.Long: case XmlTypeCode.Int: case XmlTypeCode.Short: case XmlTypeCode.Byte: case XmlTypeCode.NonNegativeInteger: case XmlTypeCode.UnsignedLong: case XmlTypeCode.UnsignedInt: case XmlTypeCode.UnsignedShort: case XmlTypeCode.UnsignedByte: case XmlTypeCode.PositiveInteger: case XmlTypeCode.Decimal: if (!this.isList) { this.dstruct = new DecimalStruct(); this.dstruct.Dvalue[0] = Convert.ToDecimal(this.ovalue, NumberFormatInfo.InvariantInfo); break; } this.dstruct = new DecimalStruct(this.dim); for (int i = 0; i < this.dim; i++) { this.dstruct.Dvalue[i] = Convert.ToDecimal(((Array) this.ovalue).GetValue(i), NumberFormatInfo.InvariantInfo); } break; default: if (this.isList) { this.dstruct = new DecimalStruct(this.dim); } else { this.dstruct = new DecimalStruct(); } return; } this.dstruct.IsDecimal = true; } }