示例#1
0
        // same as ToString, just full primary key and type code
        private string ToStringImpl(bool detailed)
        {
            string name = string.Empty;

            if (Constants.TryGetSystemGrainName(this, out name))
            {
                return(name);
            }

            var keyString = Key.ToString();
            // this should grab the least-significant half of n1, suffixing it with the key extension.
            string idString = keyString;

            if (!detailed)
            {
                if (keyString.Length >= 48)
                {
                    idString = keyString.Substring(24, 8) + keyString.Substring(48);
                }
                else
                {
                    idString = keyString.Substring(24, 8);
                }
            }

            string fullString = null;

            switch (Category)
            {
            case UniqueKey.Category.Grain:
            case UniqueKey.Category.KeyExtGrain:
                var typeString = TypeCode.ToString("X");
                if (!detailed)
                {
                    typeString = typeString.Tail(8);
                }
                fullString = String.Format("*grn/{0}/{1}", typeString, idString);
                break;

            case UniqueKey.Category.Client:
                fullString = "*cli/" + idString;
                break;

            case UniqueKey.Category.GeoClient:
                fullString = string.Format("*gcl/{0}/{1}", Key.KeyExt, idString);
                break;

            case UniqueKey.Category.SystemTarget:
                string explicitName = Constants.SystemTargetName(this);
                if (TypeCode != 0)
                {
                    var typeStr = TypeCode.ToString("X");
                    return(String.Format("{0}/{1}/{2}", explicitName, typeStr, idString));
                }
                fullString = explicitName;
                break;

            default:
                fullString = "???/" + idString;
                break;
            }
            return(detailed ? String.Format("{0}-0x{1, 8:X8}", fullString, GetUniformHashCode()) : fullString);
        }