Exemple #1
0
 public static string GetDisplayValue(this ClrInstanceField self, ClrValueClass 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)} [{self.Type.Name}]");
     }
     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>");
     }
 }
        private static bool ExtractStruct(Pair p, ClrInstanceField field, ClrValueClass structClass, out object result)
        {
            result = null;
            Type type;

            if (!GetType(p, field.Type, out type))
            {
                return(false);
            }

            var fieldInfos = GetFields(type);

            result = FormatterServices.GetUninitializedObject(type);

            foreach (var fld in structClass.Type.Fields)
            {
                object value = null;
                if (fld.Type.IsString)
                {
                    value = structClass.GetStringField(fld.Name);
                }
                else if (fld.Type.IsPrimitive)
                {
                    value = fld.GetValue(structClass.Address, true);
                }
                else if (fld.Type.IsValueClass)
                {
                    if (!ExtractStruct(p, fld, structClass.GetValueClassField(fld.Name), out value))
                    {
                        continue;
                    }
                }
                else if (fld.Type.IsArray)
                {
                    Array arr = null;
                    if (!ExtractArray(p, structClass.GetObjectField(fld.Name), fld, out arr))
                    {
                        continue;
                    }
                    value = arr;
                }
                else
                {
                    if (!ExtractRefObject(p, field, structClass.GetObjectField(fld.Name), out value))
                    {
                        continue;
                    }
                }
                fieldInfos[fld.Name].SetValue(result, value);
            }
            return(true);
        }
Exemple #3
0
        public void GetValueClassField_WhenFieldFound_ReturnsField(ClrValueClass target, [Frozen] ClrType structType, ClrValueClass someStruct, ClrInstanceField structValueField)
        {
            // Arrange
            structValueField.IsValueClass.Returns(true);
            structValueField.Type.Returns(target.Type);
            structValueField.GetAddress(someStruct.Address, Arg.Any <bool>()).Returns(target.Address);

            // Act
            var structRefFieldTarget = someStruct.GetValueClassField(structValueField.Name);

            // Assert
            structRefFieldTarget.Equals(target).Should().BeTrue();
        }
 /// <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(ValueClass.GetValueClassField(fieldName));