Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="type"></param>
        /// <param name="field"></param>
        /// <param name="kind"></param>
        /// <param name="heap"></param>
        /// <param name="addr"></param>
        /// <returns></returns>
        public static string GetValueAsString(ClrType type, ClrElementKind typeKind, ClrInstanceField field, ClrElementKind fldKind, ClrHeap heap, ulong addr, bool intr)
        {
            Debug.Assert(!TypeExtractor.IsUnknownStruct(typeKind) && !TypeExtractor.IsUnknownStruct(fldKind));
            if (TypeExtractor.IsAmbiguousKind(fldKind))
            {
                if (TypeExtractor.IsString(typeKind))
                {
                    var faddr = ValueExtractor.ReadUlongAtAddress(addr, heap);
                    return(ValueExtractor.GetStringAtAddress(faddr, heap));
                }

                if (TypeExtractor.IsKnownStruct(fldKind))
                {
                    switch (TypeExtractor.GetSpecialKind(fldKind))
                    {
                    case ClrElementKind.Decimal:
                        return(ValueExtractor.DecimalValueAsString(addr, type, null));

                    case ClrElementKind.DateTime:
                        return(ValueExtractor.DateTimeValueString(addr, type));

                    case ClrElementKind.TimeSpan:
                        return(ValueExtractor.TimeSpanValueAsString(addr, type));

                    case ClrElementKind.Guid:
                        return(ValueExtractor.GuidValue(addr, field));

                    default:
                        return(Constants.DontKnowHowToGetValue);
                    }
                }

                if (TypeExtractor.IsPrimitive(typeKind))
                {
                    return(ValueExtractor.PrimitiveValueAsString(addr, type, typeKind));
                }
                if (TypeExtractor.IsObjectReference(typeKind))
                {
                    var obj = field.GetValue(addr, false, false);
                    if (obj == null || !(obj is ulong))
                    {
                        return(Constants.ZeroAddressStr);
                    }
                    return(Utils.RealAddressString((ulong)obj));
                }
                return(Constants.DontKnowHowToGetValue);
            }
            if (TypeExtractor.IsString(fldKind))
            {
                return(ValueExtractor.GetStringAtAddress(addr, intr, field));
            }
            if (TypeExtractor.IsKnownStruct(fldKind))
            {
                switch (TypeExtractor.GetSpecialKind(fldKind))
                {
                case ClrElementKind.Decimal:
                    return(ValueExtractor.DecimalStringPAF(addr, field, intr));

                case ClrElementKind.DateTime:
                    return(ValueExtractor.GetDateTimeValue(addr, field, intr));

                case ClrElementKind.TimeSpan:
                    return(ValueExtractor.TimeSpanValue(addr, field));

                case ClrElementKind.Guid:
                    return(ValueExtractor.GuidValue(addr, field));

                default:
                    return(Constants.DontKnowHowToGetValue);
                }
            }
            if (TypeExtractor.IsPrimitive(fldKind))
            {
                return(ValueExtractor.PrimitiveValue(addr, field, intr));
            }
            if (TypeExtractor.IsObjectReference(fldKind))
            {
                var obj = field.GetValue(addr, intr, false);
                if (obj == null || !(obj is ulong))
                {
                    return(Constants.ZeroAddressStr);
                }
                return(Utils.RealAddressString((ulong)obj));
            }
            return(Constants.DontKnowHowToGetValue);
        }