/// <inheritdoc />
 public DumpType Get(DumpTypeKey type)
 {
     if (TypesInternal.TryGetValue(type, out var res))
     {
         return(res);
     }
     throw new KeyNotFoundException($"Unable to find key {type}");
 }
Beispiel #2
0
        public void Exhibit_Value_Equality()
        {
            // arrange
            var a = new DumpTypeKey(0, "");
            var b = new DumpTypeKey(0, "");
            var c = new DumpTypeKey(1, "");

            // act
            // assert
            a.GetHashCode().Should().Be(b.GetHashCode());
            a.GetHashCode().Should().NotBe(c.GetHashCode());

            a.Equals(a).Should().BeTrue();
            a.Equals(b).Should().BeTrue();
            a.Equals(c).Should().BeFalse();
            a.Equals(null).Should().BeFalse();
            a.Equals("").Should().BeFalse();
            a.CompareTo(a).Should().Be(0);
            a.CompareTo(b).Should().Be(0);
            a.CompareTo(c).Should().Be(-1);
            a.CompareTo(null).Should().Be(1);
            a.Equals((object)a).Should().BeTrue();
            a.Equals((object)b).Should().BeTrue();
            a.Equals((object)c).Should().BeFalse();
            a.Equals((object)null).Should().BeFalse();
            a.CompareTo((object)a).Should().Be(0);
            a.CompareTo((object)b).Should().Be(0);
            a.CompareTo((object)c).Should().Be(-1);
            a.CompareTo((object)null).Should().Be(1);
            (a < b).Should().BeFalse();
            (a <= b).Should().BeTrue();
            (c > a).Should().BeTrue();
            (c >= a).Should().BeTrue();
            Action throws = () => a.CompareTo("");

            throws.Should().Throw <ArgumentException>();
        }
        /// <summary>
        ///     Creates the types.
        /// </summary>
        public void CreateTypes()
        {
            Types = new Dictionary <DumpTypeKey, DumpType>();
            TypeToBaseTypeMapping      = new Dictionary <DumpTypeKey, DumpTypeKey>();
            TypeToModuleMapping        = new Dictionary <DumpTypeKey, DumpTypeKey>();
            TypeToComponentTypeMapping = new Dictionary <DumpTypeKey, DumpTypeKey>();
            InstanceFieldToTypeMapping = new Dictionary <DumpTypeField, DumpTypeKey>();
            StaticFieldToTypeMapping   = new Dictionary <DumpTypeField, DumpTypeKey>();
            foreach (var cur in Runtime.Heap.EnumerateTypes())
            {
                var t = new DumpType
                {
                    AssemblyId        = cur.Module.AssemblyId,
                    BaseSize          = cur.BaseSize,
                    ContainsPointers  = cur.ContainsPointers,
                    HasSimpleValue    = cur.HasSimpleValue,
                    IsAbstract        = cur.IsAbstract,
                    IsArray           = cur.IsArray,
                    IsEnum            = cur.IsEnum,
                    IsException       = cur.IsException,
                    IsFinalizable     = cur.IsFinalizable,
                    IsFree            = cur.IsFree,
                    IsInterface       = cur.IsInterface,
                    IsInternal        = cur.IsInternal,
                    IsObjectReference = cur.IsObjectReference,
                    IsPointer         = cur.IsPointer,
                    IsPrimitive       = cur.IsPrimitive,
                    IsPrivate         = cur.IsPrivate,
                    IsProtected       = cur.IsProtected,
                    IsPublic          = cur.IsPublic,
                    IsRuntimeType     = cur.IsRuntimeType,
                    IsSealed          = cur.IsSealed,
                    IsString          = cur.IsString,
                    IsValueClass      = cur.IsValueClass,
                    Key                = new DumpTypeKey(cur.Module.AssemblyId, cur.Name),
                    MetaDataToken      = cur.MetadataToken,
                    MethodTable        = cur.MethodTable,
                    Name               = cur.Name,
                    ElementSize        = cur.ElementSize,
                    ElementType        = cur.ElementType,
                    InterfacesInternal = new HashSet <string>(cur.Interfaces.Select(x => x.Name))
                };
                {
                    var key = new DumpTypeKey(t.AssemblyId, t.Name);
                    if (!Types.ContainsKey(key))
                    {
                        Types.Add(key, t);
                    }
                }
                {
                    var key = new DumpTypeKey(t.AssemblyId, t.Name);
                    if (cur.BaseType != null && !TypeToBaseTypeMapping.ContainsKey(key))
                    {
                        TypeToBaseTypeMapping.Add(key, cur.BaseType.ToKeyType());
                    }
                }

                {
                    var key = new DumpTypeKey(t.AssemblyId, t.Name);
                    if (cur.ComponentType != null && !TypeToComponentTypeMapping.ContainsKey(key))
                    {
                        TypeToComponentTypeMapping.Add(key,
                                                       cur.ComponentType.ToKeyType());
                    }
                }

                {
                    var key = new DumpTypeKey(t.AssemblyId, t.Name);
                    if (cur.Module != null && !TypeToModuleMapping.ContainsKey(key))
                    {
                        TypeToModuleMapping.Add(key,
                                                new DumpTypeKey(cur.Module.AssemblyId, cur.Module.Name));
                    }
                }

                foreach (var field in cur.Fields)
                {
                    var newField = new DumpTypeField
                    {
                        HasSimpleValue    = field.HasSimpleValue,
                        IsInternal        = field.IsInternal,
                        IsObjectReference = field.IsObjectReference,
                        IsPrimitive       = field.IsPrimitive,
                        IsPrivate         = field.IsPrivate,
                        IsProtected       = field.IsProtected,
                        IsPublic          = field.IsPublic,
                        IsValueClass      = field.IsValueClass,
                        Name        = field.Name,
                        Offset      = field.Offset,
                        Size        = field.Size,
                        Token       = field.Token,
                        ElementType = field.ElementType
                    };
                    t.AddInstanceField(newField);
                    if (field.Type != null && field.Type?.Name != ERROR_TYPE &&
                        !InstanceFieldToTypeMapping.ContainsKey(newField))
                    {
                        InstanceFieldToTypeMapping.Add(newField, field.Type.ToKeyType());
                    }
                }

                foreach (var field in cur.StaticFields)
                {
                    var newField = new DumpTypeField
                    {
                        HasSimpleValue    = field.HasSimpleValue,
                        IsInternal        = field.IsInternal,
                        IsObjectReference = field.IsObjectReference,
                        IsPrimitive       = field.IsPrimitive,
                        IsPrivate         = field.IsPrivate,
                        IsProtected       = field.IsProtected,
                        IsPublic          = field.IsPublic,
                        IsValueClass      = field.IsValueClass,
                        Name        = field.Name,
                        Offset      = field.Offset,
                        Size        = field.Size,
                        Token       = field.Token,
                        ElementType = field.ElementType
                    };
                    t.AddStaticField(newField);
                    if (field.Type != null && !StaticFieldToTypeMapping.ContainsKey(newField))
                    {
                        StaticFieldToTypeMapping.Add(newField, field.Type.ToKeyType());
                    }
                }
            }
        }