示例#1
0
        private static bool GetBool(Topic.VT vt, object o, Topic.PriDT dt)
        {
            bool ret;

            switch (vt)
            {
            case Topic.VT.Bool:
            case Topic.VT.Integer:
            case Topic.VT.DateTime:
                ret = dt.l != 0;
                break;

            case Topic.VT.Float:
                ret = dt.d != 0;
                break;

            case Topic.VT.String:
                if (!bool.TryParse((string)o, out ret))
                {
                    ret = false;
                }
                break;

            default:
                ret = false;
                break;
            }
            return(ret);
        }
示例#2
0
        private static double GetDouble(Topic.VT vt, object o, Topic.PriDT dt)
        {
            double ret;

            switch (vt)
            {
            case Topic.VT.Bool:
            case Topic.VT.Integer:
                ret = dt.l;
                break;

            case Topic.VT.Float:
                ret = dt.d;
                break;

            case Topic.VT.DateTime:
                ret = dt.dt.ToOADate();
                break;

            case Topic.VT.String:
                if (!double.TryParse((string)o, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out ret))
                {
                    ret = 0;
                }
                break;

            default:
                ret = 0;
                break;
            }
            return(ret);
        }
示例#3
0
        private static DateTime GetDateTime(Topic.VT vt, object o, Topic.PriDT dt)
        {
            DateTime ret;

            switch (vt)
            {
            case Topic.VT.DateTime:
                ret = dt.dt;
                break;

            case Topic.VT.Bool:
            case Topic.VT.Integer:
                ret = new DateTime(dt.l);
                break;

            case Topic.VT.Float:
                ret = DateTime.FromOADate(dt.d);
                break;

            case Topic.VT.String:
                DateTime.TryParse((string)o, out ret);
                break;

            default:
                ret = DateTime.MinValue;
                break;
            }
            return(ret);
        }
示例#4
0
        internal static T GetVal <T>(Topic.VT vt, ref object o, Topic.PriDT dt)
        {
            if (vt == Topic.VT.Ref && typeof(T) != typeof(Topic))
            {
                Topic r = o as Topic;
                return(r == null?default(T):r.As <T>());
            }
            if (vt == Topic.VT.Null)
            {
                return(default(T));
            }
            try {
                Delegate d;
                if (_getters.TryGetValue(typeof(T), out d))
                {
                    Func <Topic.VT, object, Topic.PriDT, T> f;
                    if ((f = d as Func <Topic.VT, object, Topic.PriDT, T>) != null)
                    {
                        return(f(vt, o, dt));
                    }
                }
                if (o == null)
                {
                    switch (vt)
                    {
                    case Topic.VT.Bool:
                        o = dt.l != 0;
                        break;

                    case Topic.VT.Integer:
                        o = dt.l;
                        break;

                    case Topic.VT.DateTime:
                        o = dt.dt;
                        break;

                    case Topic.VT.Float:
                        o = dt.d;
                        break;
                    }
                }
                return((T)o);
            }
            catch (Exception) {
            }
            return(default(T));
        }
示例#5
0
        private static long GetLong(Topic.VT vt, object o, Topic.PriDT dt)
        {
            long ret;

            switch (vt)
            {
            case Topic.VT.Bool:
            case Topic.VT.Integer:
            case Topic.VT.DateTime:
                ret = dt.l;
                break;

            case Topic.VT.Float:
                ret = (long)Math.Truncate(dt.d);
                break;

            case Topic.VT.String:
                if (!long.TryParse((string)o, out ret))
                {
                    double tmp;
                    if (double.TryParse((string)o, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp))
                    {
                        ret = (long)Math.Truncate(tmp);
                    }
                    else
                    {
                        ret = 0;
                    }
                }
                break;

            default:
                ret = 0;
                break;
            }
            return(ret);
        }
示例#6
0
        private static string GetString(Topic.VT vt, object o, Topic.PriDT dt)
        {
            string ret;

            switch (vt)
            {
            case Topic.VT.Bool:
                ret = dt.l == 0?bool.FalseString:bool.TrueString;
                break;

            case Topic.VT.Integer:
                ret = dt.l.ToString();
                break;

            case Topic.VT.DateTime:
                ret = dt.dt.ToString();
                break;

            case Topic.VT.Float:
                ret = dt.d.ToString();
                break;

            case Topic.VT.String:
                ret = (string)o;
                break;

            case Topic.VT.Object:
                ret = o == null?string.Empty:o.ToString();
                break;

            default:
                ret = string.Empty;
                break;
            }
            return(ret);
        }
示例#7
0
        internal static void Set <T>(T val, ref Topic.VT vt, ref object o, ref Topic.PriDT dt)
        {
            try {
                if (vt == Topic.VT.Ref && typeof(T) != typeof(Topic))
                {
                    (o as Topic).Set <T>(val); // ????
                    return;
                }
                o = val;
                switch (Type.GetTypeCode(o == null?null:o.GetType()))
                {
                case TypeCode.Boolean:
                    dt.l = (bool)o?1:0;
                    vt   = Topic.VT.Bool;
                    break;

                case TypeCode.Byte:
                case TypeCode.SByte:
                case TypeCode.Int16:
                case TypeCode.Int32:
                case TypeCode.Int64:
                case TypeCode.UInt16:
                case TypeCode.UInt32:
                case TypeCode.UInt64:
                    dt.l = Convert.ToInt64(o);
                    vt   = Topic.VT.Integer;
                    break;

                case TypeCode.Single:
                case TypeCode.Double:
                case TypeCode.Decimal:
                    dt.d = Convert.ToDouble(o);
                    vt   = Topic.VT.Float;
                    break;

                case TypeCode.DateTime:
                    dt.dt = (DateTime)o;
                    vt    = Topic.VT.DateTime;
                    break;

                case TypeCode.Empty:
                    dt.l = 0;
                    vt   = Topic.VT.Null;
                    break;

                case TypeCode.Object:
                default:
                    if (val is Topic)
                    {
                        vt = Topic.VT.Ref;
                    }
                    else if (val is string)
                    {
                        vt = Topic.VT.String;
                    }
                    else
                    {
                        vt = Topic.VT.Object;
                    }
                    break;
                }
            }
            catch (Exception) {
            }
        }