public void PrimitiveTypeEquality() { // Make sure ClrmdPrimitiveType always equals "real" ClrmdTypes if their ElementTypes are equal. // ClrmdPrimitiveType are fake, mocked up types we create if we aren't able to create the real // ClrType for a field. using DataTarget dt = TestTargets.Types.LoadFullDump(); dt.CacheOptions.CacheTypes = false; using ClrRuntime runtime = dt.ClrVersions.Single().CreateRuntime(); foreach ((ulong mt, int _) in runtime.BaseClassLibrary.EnumerateTypeDefToMethodTableMap()) { ClrType type = runtime.GetTypeByMethodTable(mt); if (type != null && type.IsPrimitive) { // We are hoping that creating a type through a MT will result in a real ClrmdType and // not a ClrmdPrimitiveType. A ClrmdPrimitiveType is there to mock up a type we cannot // find. Assert.IsType <ClrmdType>(type); ClrmdType ct = (ClrmdType)type; ClrmdPrimitiveType prim = new ClrmdPrimitiveType((ITypeHelpers)type.ClrObjectHelpers, runtime.BaseClassLibrary, runtime.Heap, ct.ElementType); Assert.True(ct == prim); Assert.True(prim == ct); } } }
public void AirtyTest() { // https://github.com/microsoft/clrmd/issues/394 string name = ClrmdType.FixGenerics("Microsoft.Diagnostics.Runtime.Tests.TypeTests+GenericTest`2[[System.String, System.Private.CoreLib],[System.Collections.Generic.List`1[[System.Collections.Generic.IEnumerable`1[[System.Int32, System.Private.CoreLib]][,], System.Private.CoreLib]][], System.Private.CoreLib]]"); const string expected = "Microsoft.Diagnostics.Runtime.Tests.TypeTests+GenericTest<System.String, System.Collections.Generic.List<System.Collections.Generic.IEnumerable<System.Int32>[,]>[]>"; Assert.Equal(expected, name); name = ClrmdType.FixGenerics("Microsoft.Diagnostics.Runtime.Tests.TypeTests+GenericTest[[System.String, System.Private.CoreLib],[System.Collections.Generic.List[[System.Collections.Generic.IEnumerable[[System.Int32, System.Private.CoreLib]][,], System.Private.CoreLib]][], System.Private.CoreLib]]"); Assert.Equal(expected, name); Assert.Equal("MyAssembly.Test<System.String>", ClrmdType.FixGenerics("MyAssembly.Test`1[[System.String, mscorlib]]")); Assert.Equal("MyAssembly.Test<System.String>", ClrmdType.FixGenerics("MyAssembly.Test[[System.String, mscorlib]]")); }