예제 #1
0
        /// <summary>
        /// Convert to just a double value and optional qualifier
        /// </summary>
        /// <param name="vo"></param>
        /// <param name="dVal"></param>
        /// <param name="qualifier"></param>
        /// <returns></returns>

        public static bool TryConvertToQualifiedDouble(
            object vo,
            out double dVal,
            out string qualifier)
        {
            QualifiedNumber qn;
            string          s = null;

            dVal      = NullValue.NullNumber;
            qualifier = null;

            if (vo == null || vo is DBNull || NullValue.IsNull(vo))
            {
                return(false);
            }

            qualifier = "";             // provide a blank qualifier if not null

            if (vo is double)
            {
                dVal = (double)vo;
            }

            else if (vo is float)
            {
                dVal = (float)vo;
            }

            else if (vo is decimal)
            {
                dVal = decimal.ToDouble((decimal)vo);
            }

            else if (vo is QualifiedNumber)
            {
                qn   = (QualifiedNumber)vo;
                dVal = qn.NumberValue;
                if (!String.IsNullOrWhiteSpace(qn.Qualifier))
                {
                    qualifier = qn.Qualifier;
                }
            }

            else if (vo is NumberMx)
            {
                NumberMx nmx = (NumberMx)vo;
                dVal = nmx.NumericValue;
            }

            else if (vo is int)
            {
                dVal = (int)vo;
            }

            else if (vo is Int16)
            {
                dVal = (Int16)vo;
            }

            else if (vo is Int64)
            {
                dVal = (Int64)vo;
            }

            else if (vo is byte)
            {
                dVal = (byte)vo;
            }

            else             // try to convert to number
            {
                s = vo.ToString();
                if (QualifiedNumber.TryParse(s, out qn))
                {
                    dVal = qn.NumberValue;
                    if (!String.IsNullOrWhiteSpace(qn.Qualifier))
                    {
                        qualifier = qn.Qualifier;
                    }
                }

                else
                {
                    return(false);                 // null
                }
            }

            return(true);
        }
예제 #2
0
        /// <summary>
        /// Custom compact Deserialization of MobiusDataType
        /// </summary>
        /// <returns></returns>

        public static MobiusDataType Deserialize(string[] sa)
        {
            int sai;

            MobiusDataType mdt  = null;
            char           type = sa[0][0];

            sai = 5;             // first array entry for specific subclass

            switch (type)
            {
            case 'M':                     // ChemicalStructure (Molecule)
                mdt = MoleculeMx.Deserialize(sa, sai);
                break;

            case 'C':                     // CompoundId
                mdt = CompoundId.Deserialize(sa, sai);
                break;

            case 'D':                     // DateTimeEx
                mdt = DateTimeMx.Deserialize(sa, sai);
                break;

            case 'I':                     // ImageEx
                mdt = ImageMx.Deserialize(sa, sai);
                break;

            case 'N':                     //NumberEx
                mdt = NumberMx.Deserialize(sa, sai);
                break;

            case 'Q':                     // QualifiedNumber
                mdt = QualifiedNumber.Deserialize(sa, sai);
                break;

            case 'S':                     // StringEx
                mdt = StringMx.Deserialize(sa, sai);
                break;

            default:
                throw new Exception("Unexpected MobiusDataType: " + type);
            }

            if (!Lex.IsNullOrEmpty(sa[1]))
            {
                mdt.BackColor = Color.FromArgb(int.Parse(sa[1]));
            }

            if (!Lex.IsNullOrEmpty(sa[2]))
            {
                mdt.ForeColor = Color.FromArgb(int.Parse(sa[2]));
            }

            if (!Lex.IsNullOrEmpty(sa[3]))
            {
                mdt.DbLink = sa[3];
            }

            if (!Lex.IsNullOrEmpty(sa[4]))
            {
                mdt.Hyperlink = sa[4];
            }

            return(mdt);
        }
예제 #3
0
/// <summary>
/// Deserialize a single value object
/// </summary>
/// <param name="ba"></param>
/// <returns></returns>

        public static object ReadBinaryItem(
            BinaryReader br)
        {
            object     vo     = null;
            VoDataType voType = (VoDataType)br.ReadByte();

            switch (voType)
            {
            case VoDataType.Null:
                return(null);

            case VoDataType.DbNull:
                return(DBNull.Value);

            case VoDataType.Byte:
                return(br.ReadByte());

            case VoDataType.Int16:
                return(br.ReadInt16());

            case VoDataType.Int32:
                return(br.ReadInt32());

            case VoDataType.Int64:
                return(br.ReadInt64());

            case VoDataType.Float:
                return(br.ReadSingle());

            case VoDataType.Double:
                return(br.ReadDouble());

            case VoDataType.Char:
                return(br.ReadChar());

            case VoDataType.String:
                return(br.ReadString());

            case VoDataType.DateTime:
                return(new DateTime(br.ReadInt64()));

            case VoDataType.CompoundId:
                return(CompoundId.DeserializeBinary(br));

            case VoDataType.NumberMx:
                return(NumberMx.DeserializeBinary(br));

            case VoDataType.QualifiedNo:
                return(QualifiedNumber.DeserializeBinary(br));

            case VoDataType.StringMx:
                return(StringMx.DeserializeBinary(br));

            case VoDataType.DateTimeMx:
                return(DateTimeMx.DeserializeBinary(br));

            case VoDataType.ImageMx:
                return(ImageMx.DeserializeBinary(br));

            case VoDataType.ChemicalStructure:
                return(MoleculeMx.DeserializeBinary(br));

            default:
                throw new Exception("Unrecognized type: " + voType);
            }
        }