Ejemplo n.º 1
0
        public object FromString(string value)
        {
            Type valueType = this.GetValueType();

            if (valueType == typeof(Single[]))
            {
                string[] values = value.Split(new string[] { "\r", "\n", " " }, StringSplitOptions.RemoveEmptyEntries);
                Single[] result = new Single[values.Length];
                for (int i = 0; i < values.Length; i++)
                {
                    result[i] = Convert.ToSingle(values[i]);
                }
                return(result);
            }
            else if (valueType == typeof(UInt16[]))
            {
                string[] values = value.Split(new string[] { "\r", "\n", " " }, StringSplitOptions.RemoveEmptyEntries);
                UInt16[] result = new UInt16[values.Length];
                for (int i = 0; i < values.Length; i++)
                {
                    result[i] = Convert.ToUInt16(values[i]);
                }
                return(result);
            }
            else
            {
                return(HexHelper.HexLineToByteUsingByteManipulation(value));
            }
        }
Ejemplo n.º 2
0
        public byte[] FromString(string value)
        {
            Type valueType = this.GetValueType();

            if (valueType == typeof(float[]))
            {
                return(FromString <float>(value, (s, d) => BinaryPrimitives.WriteSingleBigEndian(d, Convert.ToSingle(s, CultureInfo.InvariantCulture))));
            }
            else if (valueType == typeof(ushort[]))
            {
                return(FromString <ushort>(value, (s, d) => BinaryPrimitives.WriteUInt16BigEndian(d, Convert.ToUInt16(s))));
            }
            else
            {
                return(HexHelper.HexLineToByteUsingByteManipulation(value));
            }
        }