示例#1
0
        //20160622 DKh
        public static GDIDSymbol AsGDIDSymbol(this object val)
        {
            if (val == null)
            {
                return(new GDIDSymbol());
            }

            if (val is GDIDSymbol)
            {
                return((GDIDSymbol)val);
            }
            if (val is GDID)
            {
                return(new GDIDSymbol((GDID)val, val.ToString()));
            }

            if (val is ELink)
            {
                return(((ELink)val).AsGDIDSymbol);
            }

            if (val is string)
            {
                var sval = ((string)val).Trim();

                GDID gdid;
                if (GDID.TryParse(sval, out gdid))
                {
                    return(new GDIDSymbol(gdid, sval));
                }

                try
                {
                    var elink = new ELink(sval);
                    return(elink.AsGDIDSymbol);
                }
                catch {}
            }

            if (val is ulong)
            {
                return(new GDIDSymbol(new GDID(0, (ulong)val), val.ToString()));
            }
            if (val is byte[])
            {
                var buf = (byte[])val;
                return(new GDIDSymbol(new GDID(buf), buf.ToDumpString(DumpFormat.Hex)));
            }
            return(new GDIDSymbol(new GDID(0, Convert.ToUInt64(val)), val.ToString()));
        }
示例#2
0
        public static GDID AsGDID(this object val)
        {
            if (val == null)
            {
                return(GDID.ZERO);
            }

            if (val is GDID)
            {
                return((GDID)val);
            }

            if (val is ELink)
            {
                return(((ELink)val).GDID);
            }

            if (val is string)
            {
                var sval = ((string)val).Trim();

                GDID gdid;
                if (GDID.TryParse(sval, out gdid))
                {
                    return(gdid);
                }

                //20160109 DKH also interpret string via ELink
                try
                {
                    var elink = new ELink(sval);
                    return(elink.GDID);
                }
                catch {}
            }

            if (val is ulong)
            {
                return(new GDID(0, (ulong)val));
            }
            if (val is byte[])
            {
                return(new GDID((byte[])val));
            }
            return(new GDID(0, Convert.ToUInt64(val)));
        }
        public static GDID AsGDID(this object val)
        {
            if (val == null)
            {
                return(GDID.ZERO);
            }

            if (val is GDID gdval)
            {
                return(gdval);
            }
            if (val is ELink elval)
            {
                return(elval.GDID);
            }

            if (val is string sval)
            {
                GDID gdid;
                if (GDID.TryParse(sval, out gdid))
                {
                    return(gdid);
                }

                try
                {
                    var elink = new ELink(sval);
                    return(elink.GDID);
                }
                catch {}
            }

            if (val is ulong ulval)
            {
                return(new GDID(0, ulval));
            }
            if (val is byte[] bval)
            {
                return(new GDID(bval));
            }

            return(new GDID(0, Convert.ToUInt64(val)));
        }