示例#1
0
 public bool EqualsType(MySubType other)
 {
     return(Bool == other.Bool &&
            Int32 == other.Int32 &&
            UInt32 == other.UInt32 &&
            Int64 == other.Int64 &&
            UInt64 == other.UInt64 &&
            Float32.Equals(other.Float32) &&
            Float64.Equals(other.Float64) &&
            Enum == other.Enum &&
            string.Equals(Str, other.Str));
 }
示例#2
0
        public void Build(ref StringBuilder builder, int prettyIndent)
        {
            switch (Type)
            {
            case FieldType.NULL:
                builder.Append(NULL);
                break;

            case FieldType.STRING:
                builder.Append("\"");
                builder.Append(JSONHelper.GetSafelyFormattedString(String));
                builder.Append("\"");
                break;

            case FieldType.NUMBER:
                if (IsFloat)
                {
                    builder.Append(Float64.ToString("##########0.###########").Replace(',', '.'));
                }
                else if (IsSigned)
                {
                    builder.Append(Signed_Int64.ToString());
                }
                else
                {
                    builder.Append(Unsigned_Int64.ToString());
                }
                break;

            case FieldType.CONTAINER:
                if (Container != null)
                {
                    Container.Build(ref builder, prettyIndent);
                }
                else
                {
                    builder.Append(NULL);
                }
                break;

            case FieldType.BOOL:
                if (Boolean)
                {
                    builder.Append(BOOL_TRUE);
                }
                else
                {
                    builder.Append(BOOL_FALSE);
                }
                break;
            }
        }
示例#3
0
 protected bool EqualsType(MyType other)
 {
     return(Bool == other.Bool &&
            Int32 == other.Int32 &&
            UInt32 == other.UInt32 &&
            Int64 == other.Int64 &&
            UInt64 == other.UInt64 &&
            Float32.Equals(other.Float32) &&
            Float64.Equals(other.Float64) &&
            string.Equals(Str, other.Str) &&
            Enum == other.Enum &&
            Equals(Struct, other.Struct));
 }
        /// <summary>
        /// Return binary represebtation of the number in the format IEEE 754
        /// </summary>
        /// <param name="number">source number</param>
        /// <returns>binary represebtation</returns>
        public static string GetBinaryIEEE754(this double number)
        {
            Float64       float64       = new Float64(number);
            ulong         ulongNumber   = float64.UlongNumber;
            StringBuilder stringBuilder = new StringBuilder();

            for (int i = 0; i < 64; i++)
            {
                if ((ulongNumber & 1) == 1)
                {
                    stringBuilder.Insert(0, "1");
                }
                else
                {
                    stringBuilder.Insert(0, "0");
                }

                ulongNumber = ulongNumber >> 1;
            }

            return(stringBuilder.ToString());
        }
        /// <summary>
        /// Transforms number to binary string.
        /// </summary>
        /// <param name="number">Given number.</param>
        /// <returns>String representation of double number.</returns>
        public static string TransformToIEEE754(this double number)
        {
            var   float64       = new Float64(number);
            ulong ulongValue    = float64.UlongValue;
            var   stringBuilder = new StringBuilder();

            for (int i = 0; i < AmountOfBitsForDouble; i++)
            {
                if ((ulongValue & 1) == 1)
                {
                    stringBuilder.Insert(0, "1");
                }
                else
                {
                    stringBuilder.Insert(0, "0");
                }

                ulongValue >>= 1;
            }

            return(stringBuilder.ToString());
        }
示例#6
0
        private void _parse()
        {
            _datatype = ((DataType)m_io.ReadU1());
            switch (Datatype)
            {
            case DataType.Integer:
            {
                _dataValue = new Integer(m_io, this, m_root);
                break;
            }

            case DataType.Unsigned:
            {
                _dataValue = new Unsigned(m_io, this, m_root);
                break;
            }

            case DataType.Long:
            {
                _dataValue = new Long(m_io, this, m_root);
                break;
            }

            case DataType.Boolean:
            {
                _dataValue = new Boolean(m_io, this, m_root);
                break;
            }

            case DataType.Structure:
            {
                _dataValue = new Structure(m_io, this, m_root);
                break;
            }

            case DataType.Array:
            {
                _dataValue = new Array(m_io, this, m_root);
                break;
            }

            case DataType.Float64:
            {
                _dataValue = new Float64(m_io, this, m_root);
                break;
            }

            case DataType.DoNotCare:
            {
                _dataValue = new DoNotCare(m_io, this, m_root);
                break;
            }

            case DataType.LongUnsigned:
            {
                _dataValue = new LongUnsigned(m_io, this, m_root);
                break;
            }

            case DataType.Time:
            {
                _dataValue = new Time(m_io, this, m_root);
                break;
            }

            case DataType.OctetString:
            {
                _dataValue = new OctetString(m_io, this, m_root);
                break;
            }

            case DataType.NullData:
            {
                _dataValue = new NullData(m_io, this, m_root);
                break;
            }

            case DataType.CompactArray:
            {
                _dataValue = new CompactArray(m_io, this, m_root);
                break;
            }

            case DataType.DateTime:
            {
                _dataValue = new DateTime(m_io, this, m_root);
                break;
            }

            case DataType.DoubleLongUnsigned:
            {
                _dataValue = new DoubleLongUnsigned(m_io, this, m_root);
                break;
            }

            case DataType.Float32:
            {
                _dataValue = new Float32(m_io, this, m_root);
                break;
            }

            case DataType.Long64Unsigned:
            {
                _dataValue = new Long64Unsigned(m_io, this, m_root);
                break;
            }

            case DataType.DoubleLong:
            {
                _dataValue = new DoubleLong(m_io, this, m_root);
                break;
            }

            case DataType.Long64:
            {
                _dataValue = new Long64(m_io, this, m_root);
                break;
            }

            case DataType.Date:
            {
                _dataValue = new Date(m_io, this, m_root);
                break;
            }

            case DataType.Enum:
            {
                _dataValue = new Enum(m_io, this, m_root);
                break;
            }

            case DataType.Bcd:
            {
                _dataValue = new Bcd(m_io, this, m_root);
                break;
            }

            case DataType.VisibleString:
            {
                _dataValue = new VisibleString(m_io, this, m_root);
                break;
            }

            case DataType.BitString:
            {
                _dataValue = new BitString(m_io, this, m_root);
                break;
            }
            }
        }