|
4 | 4 | using System;
|
5 | 5 | using System.Text;
|
6 | 6 | using System.Collections.Generic;
|
| 7 | +using System.Reflection; |
7 | 8 | using System.Runtime.CompilerServices;
|
8 | 9 | using System.Runtime.InteropServices;
|
9 | 10 | using System.Diagnostics.CodeAnalysis;
|
@@ -60,6 +61,7 @@ public static int Run()
|
60 | 61 | TestDefaultDynamicStaticNonGeneric.Run();
|
61 | 62 | TestDefaultDynamicStaticGeneric.Run();
|
62 | 63 | TestDynamicStaticGenericVirtualMethods.Run();
|
| 64 | + TestRuntime109496Regression.Run(); |
63 | 65 |
|
64 | 66 | return Pass;
|
65 | 67 | }
|
@@ -1780,4 +1782,57 @@ public static void Run()
|
1780 | 1782 | Console.WriteLine(s_entry.Enter1<SimpleCallStruct<object>>("One"));
|
1781 | 1783 | }
|
1782 | 1784 | }
|
| 1785 | + |
| 1786 | + class TestRuntime109496Regression |
| 1787 | + { |
| 1788 | + class CastableThing : IDynamicInterfaceCastable |
| 1789 | + { |
| 1790 | + RuntimeTypeHandle IDynamicInterfaceCastable.GetInterfaceImplementation(RuntimeTypeHandle interfaceType) |
| 1791 | + => Type.GetTypeFromHandle(interfaceType).GetCustomAttribute<TypeAttribute>().TheType.TypeHandle; |
| 1792 | + bool IDynamicInterfaceCastable.IsInterfaceImplemented(RuntimeTypeHandle interfaceType, bool throwIfNotImplemented) |
| 1793 | + => Type.GetTypeFromHandle(interfaceType).IsDefined(typeof(TypeAttribute)); |
| 1794 | + } |
| 1795 | + |
| 1796 | + [Type(typeof(IMyInterfaceImpl))] |
| 1797 | + interface IMyInterface |
| 1798 | + { |
| 1799 | + int Method(); |
| 1800 | + } |
| 1801 | + |
| 1802 | + [DynamicInterfaceCastableImplementation] |
| 1803 | + interface IMyInterfaceImpl : IMyInterface |
| 1804 | + { |
| 1805 | + int IMyInterface.Method() => 42; |
| 1806 | + } |
| 1807 | + |
| 1808 | + [Type(typeof(IMyGenericInterfaceImpl<int>))] |
| 1809 | + interface IMyGenericInterface |
| 1810 | + { |
| 1811 | + int Method(); |
| 1812 | + } |
| 1813 | + |
| 1814 | + [DynamicInterfaceCastableImplementation] |
| 1815 | + interface IMyGenericInterfaceImpl<T> : IMyGenericInterface |
| 1816 | + { |
| 1817 | + int IMyGenericInterface.Method() => typeof(T).Name.Length; |
| 1818 | + } |
| 1819 | + |
| 1820 | + class TypeAttribute : Attribute |
| 1821 | + { |
| 1822 | + public Type TheType { get; } |
| 1823 | + |
| 1824 | + public TypeAttribute(Type t) => TheType = t; |
| 1825 | + } |
| 1826 | + |
| 1827 | + public static void Run() |
| 1828 | + { |
| 1829 | + object o = new CastableThing(); |
| 1830 | + |
| 1831 | + if (((IMyInterface)o).Method() != 42) |
| 1832 | + throw new Exception(); |
| 1833 | + |
| 1834 | + if (((IMyGenericInterface)o).Method() != 5) |
| 1835 | + throw new Exception(); |
| 1836 | + } |
| 1837 | + } |
1783 | 1838 | }
|
0 commit comments