Пример #1
0
        public override bool TryParse(string value, ref object obj)
        {
            if (!base.TryParse(value, ref obj))
            {
                return(false);
            }

            EncodableDataType ecd = (EncodableDataType)obj;

            if (ecd.Value != null)
            {
                value = ecd.Value;
            }

            double i;
            bool   retVal = double.TryParse(value, out i);

            ((Float)obj).Value = i;
            return(retVal);
        }
Пример #2
0
        private bool TryParseBASE64(string value, ref object obj)
        {
            EncodableDataType edt = (EncodableDataType)obj;

            try
            {
                UTF8Encoding encoder    = new UTF8Encoding();
                Decoder      utf8Decode = encoder.GetDecoder();

                edt.Data = Convert.FromBase64String(value);
                int    charCount    = utf8Decode.GetCharCount(edt.Data, 0, edt.Data.Length);
                char[] decoded_char = new char[charCount];
                utf8Decode.GetChars(edt.Data, 0, edt.Data.Length, decoded_char, 0);
                edt.Value = new String(decoded_char);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Пример #3
0
        private bool TryParse8BIT(string value, ref object obj)
        {
            EncodableDataType edt = (EncodableDataType)obj;

            try
            {
                UTF8Encoding utf8 = new UTF8Encoding();
                byte[]       data = utf8.GetBytes(value);
                for (int i = 0; i < data.Length; i++)
                {
                    byte b = data[i];
                    if (b == 0)
                    {
                        return(false);
                    }
                    // Ensure CR is always part of CRLF
                    else if (b == 13 &&
                             i < data.Length - 1 &&
                             data[i + 1] != 10)
                    {
                        return(false);
                    }
                    // Ensure LF is always part of CRLF
                    else if (b == 10 &&
                             i > 0 &&
                             data[i - 1] != 13)
                    {
                        return(false);
                    }
                }

                edt.Data  = data;
                edt.Value = value;
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Пример #4
0
 public EncodableDataTypeSerializer(EncodableDataType dataType) : base(dataType)
 {
     _DataType = dataType;
 }