Пример #1
0
 public static string GetDisplayValue(this ClrInstanceField self, ClrObject clrObject)
 {
     if (self.IsObjectReference)
     {
         var obj = clrObject.GetObjectField(self.Name);
         if (obj.IsNull)
         {
             return("null");
         }
         return($"0x{obj.Address:X} [{obj.Type.Name}:0x{obj.Type.MethodTable:X}]");
     }
     else if (self.HasSimpleValue)
     {
         return(self.GetValue(clrObject.Address).ToString());
     }
     else if (self.IsValueClass)
     {
         var vt = clrObject.GetValueClassField(self.Name);
         return($"0x{vt.Address:X} [struct {vt.Type.Name}:0x{vt.Type.MethodTable:X}]");
     }
     else
     {
         return("<unknown value>");
     }
 }
Пример #2
0
        internal static ClrValueClass?TryGetValueClassField(this ClrObject clrObject, string fieldName)
        {
            if (!clrObject.IsNull)
            {
                var field = clrObject.Type.GetFieldByName(fieldName);
                if (field != null && field.Type.IsValueClass)
                {
                    // System.Console.WriteLine("{0} {1:x} Field {2} {3} {4} {5}", clrObject.Type.Name, clrObject.Address, fieldName, field.Type.Name, field.Type.IsValueClass, field.Type.IsRuntimeType);
                    return(clrObject.GetValueClassField(fieldName));
                }
            }

            return(null);
        }
Пример #3
0
        public void GetValueClassField_WhenFieldFound_ReturnsField([Frozen] ClrHeap heap, ClrValueClass target, [Frozen] ClrType clrObjectType, ClrObject clrObject, ClrInstanceField clrObjValueField)
        {
            // Arrange
            clrObjValueField.IsValueClass.Returns(true);
            clrObjValueField.Type.Returns(target.Type);

            clrObjValueField
            .GetAddress(clrObject.Address)
            .Returns(target.Address);

            // Act
            var structRefFieldTarget = clrObject.GetValueClassField(clrObjValueField.Name);

            // Assert
            structRefFieldTarget.Equals(target).Should().BeTrue();
        }
Пример #4
0
 /// <summary>
 ///     Gets the value class field.
 /// </summary>
 /// <param name="fieldName">Name of the field.</param>
 /// <returns>IClrValueClass.</returns>
 /// <inheritdoc />
 public IClrValueClass GetValueClassField(string fieldName) =>
 Converter.Convert(Object.GetValueClassField(fieldName));