private ClrInstance[] ComputeItems() { if (!IsArray) { return(Array.Empty <ClrInstance>()); } Contract.AssertNotNull(Type, "Arrays should always have Type != null."); Contract.AssertNotNull(ObjectAddress); var address = ObjectAddress.Value; var length = Type.GetArrayLength(address); var items = new ClrInstance[length]; var elementType = Type.ComponentType; for (var i = 0; i < length; i++) { var tmp = GetElementAt(i); if (!(tmp is ClrInstance)) { tmp = CreateInterior(Heap, tmp, elementType); } items[i] = (ClrInstance)tmp; //var value = Type.GetArrayElementValue(address, i); //items[i] = CreateItemInstance(value, elementType, i); } return(items); }
public static IEnumerable <ClrInstance> EnumerateClrObjects(this ClrHeap heap) { foreach (var address in heap.EnumerateObjectAddresses()) { var result = ClrInstance.CreateInstance(heap, address); yield return(result); } }
public static bool IsOfType(this ClrInstance instance, TypeIndex typeIndex) { if (instance.Type == null) { return(false); } return(typeIndex.ContainsType(instance.Type)); }
public static bool IsOfType(this ClrInstance instance, Type type, TypesRegistry registry) { if (instance.Type == null) { return(false); } return(registry.IsInstanceOfType(instance.Type, type)); }
public static bool IsTaskLike(this ClrInstance instance, TypesRegistry registry) { if (instance.IsOfType(typeof(Task), registry)) { return(true); } // Add support for ValueTask and other task-like types. return(false); }
public static IEnumerable <ClrInstance> EnumerateListOfObjects(this ClrInstance instance) { if (!instance.IsListOfObjects()) { throw new ArgumentException($"'instance' should be of type 'List<object>' but was '{instance.Type}'"); } var size = (int)instance.GetField("_size").Instance.Value; var items = instance.GetField("_items").Instance.Items; for (int i = 0; i < size; i++) { yield return(items[i]); } }
internal static ClrFieldValue?Create(ClrInstanceField typeField, ClrInstance instance, bool interior) { if (typeField.Type.MetadataToken == 0 && typeField.Type.Name == "ERROR") { return(null); // TODO: not sure about this! //throw new NotSupportedException(); } Contract.AssertNotNull(instance.ObjectAddress); object?value = null; try { // This code could fail with NRE with no obvious reason. value = typeField.GetValue(instance.ObjectAddress.Value, interior); } catch (Exception) { } var type = typeField.Type; if (!type.IsIntrinsic() && value != null) { // instance.Heap.GetObjectType may return null. WHY? type = instance.Heap.GetObjectType((ulong)value) ?? type; } if (value == null) { value = instance.ObjectAddress.Value + (ulong)typeField.Offset; } return(new ClrFieldValue(typeField, new ClrInstance(instance.Heap, value, type, interior))); }
private static string PrintArray(ClrInstance instance) { return($"[{string.Join(", ", instance.Items.Select(i => i.ToString()))}]"); }
private ClrFieldValue(ClrInstanceField field, ClrInstance instance) { Field = field ?? throw new ArgumentNullException(nameof(field)); Instance = instance ?? throw new ArgumentNullException(nameof(instance)); }
public static bool IsListOfObjects(this ClrInstance instance) { // Need to compare by name since GetTypeByName does not work for the generic type during initialization return(instance.Type?.Name == "System.Collections.Generic.List<System.Object>"); }
public static bool IsTaskCompletionSource(this ClrInstance continuation, CausalityContext context) { return(context.Registry.IsTaskCompletionSource(continuation.Type)); }
public static bool IsCompletedTaskContinuation(this ClrInstance continuation, CausalityContext context) { return(context.Registry.IsTaskCompletionSentinel(continuation)); }
public static bool IsTaskWhenAll(this ClrInstance instance, CausalityContext context) { return(context.Registry.IsTaskWhenAll(instance)); }
public static bool IsOfType(this ClrInstance instance, Type type, CausalityContext context) { return(instance.IsOfType(type, context.Registry)); }