public static string GetSimpleValueString(ClrObject obj)
            {
                object value = obj.SimpleValue;

                if (value == null)
                {
                    return("null");
                }

                ClrType type = obj.Type;

                if (type != null && type.IsEnum)
                {
                    return(type.GetEnumName(value) ?? value.ToString());
                }

                DateTime?dateTime = value as DateTime?;

                if (dateTime != null)
                {
                    return(GetDateTimeString(dateTime.Value));
                }

                return(value.ToString());
            }
示例#2
0
        public static object GetSimpleValue(ulong objAddress, ClrType clrType, bool isInterior = false)
        {
            if (objAddress == 0)
            {
                throw new NullReferenceException("ClrObject at is pointing to null address.");
            }

            ClrHeap heap = clrType.Heap;

            if (clrType.IsEnum)
            {
                var val = clrType.GetValue(objAddress);
                return(clrType.GetEnumName(val));
            }

            if (clrType.IsPrimitive || clrType.IsString)
            {
                return(clrType.GetValue(objAddress));
            }

            ulong address = isInterior ? objAddress : objAddress + (ulong)heap.PointerSize;

            switch (clrType.Name)
            {
            case GuidTypeName:
            {
                byte[] buffer = ReadBuffer(heap, address, 16);
                return(new Guid(buffer));
            }

            case TimeSpanTypeName:
            {
                byte[] buffer = ReadBuffer(heap, address, 8);
                long   ticks  = BitConverter.ToInt64(buffer, 0);
                return(new TimeSpan(ticks));
            }

            case DateTimeTypeName:
            {
                byte[] buffer   = ReadBuffer(heap, address, 8);
                ulong  dateData = BitConverter.ToUInt64(buffer, 0);
                return(GetDateTime(dateData));
            }

            case IPAddressTypeName:
            {
                return(GetIPAddress(new ClrObject(objAddress, clrType, isInterior)));
            }
            }

            throw new InvalidOperationException(string.Format("SimpleValue not available for type '{0}'", clrType.Name));
        }
示例#3
0
        public static string GetEnumName(ClrType type, ulong enumValue)
        {
            if (type == null || !type.IsEnum)
            {
                return("#INVALIDENUMTYPE#");
            }
            object         value      = enumValue;
            List <string>  namesFound = new List <string>();
            ClrElementType enumType   = ClrElementType.Unknown;

            try
            {
                enumType = type.GetEnumElementType();
            }
            catch
            {
                return("#INVALIDENUMTYPE#");
            }
            byte[] raw = BitConverter.GetBytes(enumValue);

            object gvalue = enumValue;

            switch (enumType)
            {
            case ClrElementType.Int16:
                gvalue = BitConverter.ToInt16(raw, 0);
                break;

            case ClrElementType.Int32:
                gvalue = BitConverter.ToInt32(raw, 0);
                break;

            case ClrElementType.Int64:
                gvalue = BitConverter.ToInt64(raw, 0);
                break;

            case ClrElementType.UInt16:
                gvalue = BitConverter.ToUInt16(raw, 0);
                break;

            case ClrElementType.UInt32:
                gvalue = BitConverter.ToUInt32(raw, 0);
                break;

            case ClrElementType.UInt64:
                gvalue = BitConverter.ToUInt64(raw, 0);
                break;

            default:
                gvalue = 0UL;
                break;
            }

            if (!String.IsNullOrEmpty(type.GetEnumName(gvalue)))
            {
                return(type.GetEnumName(gvalue));
            }
            var names = type.GetEnumNames();

            foreach (var name in names)
            {
                if (type.TryGetEnumValue(name, out value))
                {
                    byte[] rawValue = null;
                    switch (enumType)
                    {
                    case ClrElementType.Int16:
                        rawValue = BitConverter.GetBytes((short)value);
                        break;

                    case ClrElementType.Int32:
                        rawValue = BitConverter.GetBytes((int)value);
                        break;

                    case ClrElementType.Int64:
                        rawValue = BitConverter.GetBytes((long)value);
                        break;

                    case ClrElementType.UInt16:
                        rawValue = BitConverter.GetBytes((ushort)value);
                        break;

                    case ClrElementType.UInt32:
                        rawValue = BitConverter.GetBytes((uint)value);
                        break;

                    case ClrElementType.UInt64:
                        rawValue = BitConverter.GetBytes((ulong)value);
                        break;

                    default:
                        rawValue = BitConverter.GetBytes((ulong)0UL);
                        break;
                    }
                    byte[] raw64 = BitConverter.GetBytes((ulong)0UL);
                    for (int i = 0; i < rawValue.Length; i++)
                    {
                        raw64[i] = rawValue[i];
                    }
                    ulong u = BitConverter.ToUInt64(raw64, 0);
                    if ((enumValue & u) == u && u != 0)
                    {
                        namesFound.Add(name);
                    }
                }
            }
            if (namesFound.Count == 0)
            {
                return(String.Empty);
            }
            return(String.Join("|", namesFound.ToArray()));
        }
示例#4
0
 /// <summary>
 ///     Gets the name of the value in the enum, or null if the value doesn't have a name.
 ///     This is a convenience function, and has undefined results if the same value appears
 ///     twice in the enum.
 /// </summary>
 /// <param name="value">The value to lookup.</param>
 /// <returns>The name of one entry in the enum with this value, or null if none exist.</returns>
 public string GetEnumName(object value) => ClrType.GetEnumName(value);