diff --git a/src/System.Runtime/tests/ArrayTests.netcoreapp.cs b/src/System.Runtime/tests/ArrayTests.netcoreapp.cs new file mode 100644 index 000000000000..3cb54e9069f5 --- /dev/null +++ b/src/System.Runtime/tests/ArrayTests.netcoreapp.cs @@ -0,0 +1,36 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using Xunit; + +namespace System.Tests +{ + public static class Array17NetcoreappTests + { + [Fact] + public static void CreateInstance_Type_Int_Invalid() + { + // Type is not a valid RuntimeType + Assert.Throws("elementType", () => Array.CreateInstance(Helpers.NonRuntimeType(), 0)); + } + + [Fact] + public static void CreateInstance_Type_Int_Int_Invalid() + { + // Type is not a valid RuntimeType + Assert.Throws("elementType", () => Array.CreateInstance(Helpers.NonRuntimeType(), 0, 1)); + } + + [Fact] + public static void CreateInstance_Type_Int_Int_Int_Invalid() + { + // Type is not a valid RuntimeType + Assert.Throws("elementType", () => Array.CreateInstance(Helpers.NonRuntimeType(), 0, 1, 2)); + } + } +} \ No newline at end of file diff --git a/src/System.Runtime/tests/ArrayTests.netstandard.cs b/src/System.Runtime/tests/ArrayTests.netstandard.cs index 69b35a9bdacd..938408e00e39 100644 --- a/src/System.Runtime/tests/ArrayTests.netstandard.cs +++ b/src/System.Runtime/tests/ArrayTests.netstandard.cs @@ -141,11 +141,6 @@ public static void CreateInstance_Type_Int_Invalid() Assert.Throws(() => Array.CreateInstance(typeof(int).MakeByRefType(), 0)); // Element type is not supported (ref) Assert.Throws("length", () => Array.CreateInstance(typeof(int), -1)); // Length < 0 - -#if netcoreapp - // Type is not a valid RuntimeType - Assert.Throws("elementType", () => Array.CreateInstance(Helpers.NonRuntimeType(), 0)); -#endif // netcoreapp } [Fact] @@ -158,11 +153,6 @@ public static void CreateInstance_Type_Int_Int_Invalid() Assert.Throws(() => Array.CreateInstance(typeof(int).MakeByRefType(), 0, 1)); // Element type is not supported (ref) Assert.Throws("length2", () => Array.CreateInstance(typeof(int), 0, -1)); // Length < 0 - -#if netcoreapp - // Type is not a valid RuntimeType - Assert.Throws("elementType", () => Array.CreateInstance(Helpers.NonRuntimeType(), 0, 1)); -#endif // netcoreapp } [Fact] @@ -184,11 +174,6 @@ public static void CreateInstance_Type_Int_Int_Int_Invalid() Assert.Throws(() => Array.CreateInstance(typeof(int).MakeByRefType(), 0, 1, 2)); // Element type is not supported (ref) Assert.Throws("length3", () => Array.CreateInstance(typeof(int), 0, 1, -1)); // Length < 0 - -#if netcoreapp - // Type is not a valid RuntimeType - Assert.Throws("elementType", () => Array.CreateInstance(Helpers.NonRuntimeType(), 0, 1, 2)); -#endif // netcoreapp } [Fact] diff --git a/src/System.Runtime/tests/Helpers.cs b/src/System.Runtime/tests/Helpers.cs index c6e55e50e0d4..16fdb47ef19e 100644 --- a/src/System.Runtime/tests/Helpers.cs +++ b/src/System.Runtime/tests/Helpers.cs @@ -8,30 +8,8 @@ namespace System.Tests { - public static class Helpers + public static partial class Helpers { -#if netcoreapp // AssemblyBuilder is not in netstandard yet - - private static Type s_nonRuntimeType; - - public static Type NonRuntimeType() - { - if (s_nonRuntimeType == null) - { - AssemblyName assemblyName = new AssemblyName("AssemblyName"); - AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run); - ModuleBuilder mboduleBuilder = assemblyBuilder.DefineDynamicModule(assemblyName.Name); - - TypeBuilder typeBuilder = mboduleBuilder.DefineType("TestType", TypeAttributes.Public); - - GenericTypeParameterBuilder[] typeParams = typeBuilder.DefineGenericParameters("T"); - s_nonRuntimeType = typeParams[0].UnderlyingSystemType; - } - - return s_nonRuntimeType; - } -#endif // netcoreapp - public static void PerformActionWithCulture(CultureInfo culture, Action test) { CultureInfo originalCulture = CultureInfo.CurrentCulture; diff --git a/src/System.Runtime/tests/Helpers.netcoreapp.cs b/src/System.Runtime/tests/Helpers.netcoreapp.cs new file mode 100644 index 000000000000..db49366823b8 --- /dev/null +++ b/src/System.Runtime/tests/Helpers.netcoreapp.cs @@ -0,0 +1,32 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Globalization; +using System.Reflection; +using System.Reflection.Emit; + +namespace System.Tests +{ + public static partial class Helpers + { + private static Type s_nonRuntimeType; + + public static Type NonRuntimeType() + { + if (s_nonRuntimeType == null) + { + AssemblyName assemblyName = new AssemblyName("AssemblyName"); + AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run); + ModuleBuilder mboduleBuilder = assemblyBuilder.DefineDynamicModule(assemblyName.Name); + + TypeBuilder typeBuilder = mboduleBuilder.DefineType("TestType", TypeAttributes.Public); + + GenericTypeParameterBuilder[] typeParams = typeBuilder.DefineGenericParameters("T"); + s_nonRuntimeType = typeParams[0].UnderlyingSystemType; + } + + return s_nonRuntimeType; + } + } +} diff --git a/src/System.Runtime/tests/System.Runtime.Tests.csproj b/src/System.Runtime/tests/System.Runtime.Tests.csproj index ec2f119e11d9..f8566a7b34b4 100644 --- a/src/System.Runtime/tests/System.Runtime.Tests.csproj +++ b/src/System.Runtime/tests/System.Runtime.Tests.csproj @@ -120,6 +120,9 @@ + + + diff --git a/src/System.Runtime/tests/System/ActivatorTests.netcoreapp.cs b/src/System.Runtime/tests/System/ActivatorTests.netcoreapp.cs new file mode 100644 index 000000000000..b369d5141874 --- /dev/null +++ b/src/System.Runtime/tests/System/ActivatorTests.netcoreapp.cs @@ -0,0 +1,19 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Reflection; +using Xunit; + +namespace System.Tests +{ + public static class ActivatorNetcoreTests + { + [Fact] + public static void CreateInstance_Invalid() + { + // Type is not a valid RuntimeType + Assert.Throws("type", () => Activator.CreateInstance(Helpers.NonRuntimeType())); + } + } +} diff --git a/src/System.Runtime/tests/System/ArrayTests.cs b/src/System.Runtime/tests/System/ArrayTests.cs index 99eeb6a515e3..5287949c79a4 100644 --- a/src/System.Runtime/tests/System/ArrayTests.cs +++ b/src/System.Runtime/tests/System/ArrayTests.cs @@ -1431,16 +1431,6 @@ public static void CreateInstance_NegativeLength_ThrowsArgumentOutOfRangeExcepti Assert.Throws("lengths[0]", () => Array.CreateInstance(typeof(int), new int[] { -1 }, new int[1])); } -#if netcoreapp - [Fact] - public static void CreateInstance_TypeNotRuntimeType_ThrowsArgumentException() - { - Assert.Throws("elementType", () => Array.CreateInstance(Helpers.NonRuntimeType(), 0)); - Assert.Throws("elementType", () => Array.CreateInstance(Helpers.NonRuntimeType(), new int[1])); - Assert.Throws("elementType", () => Array.CreateInstance(Helpers.NonRuntimeType(), new int[1], new int[1])); - } -#endif // netcoreapp - [Fact] public static void CreateInstance_LengthsNull_ThrowsArgumentNullException() { diff --git a/src/System.Runtime/tests/System/ArrayTests.netcoreapp.cs b/src/System.Runtime/tests/System/ArrayTests.netcoreapp.cs index f1e739d2274b..352953e0dce7 100644 --- a/src/System.Runtime/tests/System/ArrayTests.netcoreapp.cs +++ b/src/System.Runtime/tests/System/ArrayTests.netcoreapp.cs @@ -139,5 +139,13 @@ public static void Reverse_Generic_InvalidOffsetPlusLength_ThrowsArgumentExcepti { Assert.Throws(null, () => Array.Reverse(new string[arrayLength], index, length)); } + + [Fact] + public static void CreateInstance_TypeNotRuntimeType_ThrowsArgumentException() + { + Assert.Throws("elementType", () => Array.CreateInstance(Helpers.NonRuntimeType(), 0)); + Assert.Throws("elementType", () => Array.CreateInstance(Helpers.NonRuntimeType(), new int[1])); + Assert.Throws("elementType", () => Array.CreateInstance(Helpers.NonRuntimeType(), new int[1], new int[1])); + } } } diff --git a/src/System.Runtime/tests/System/EnumTests.cs b/src/System.Runtime/tests/System/EnumTests.cs index 50623dcaff73..7457edbb9ab4 100644 --- a/src/System.Runtime/tests/System/EnumTests.cs +++ b/src/System.Runtime/tests/System/EnumTests.cs @@ -334,23 +334,6 @@ public static void GetName_MultipleMatches() Assert.True(s == "Green" || s == "Green_a" || s == "Green_b"); } -#if netcoreapp - public static IEnumerable UnsupportedEnumType_TestData() - { - yield return new object[] { s_floatEnumType, 1.0f }; - yield return new object[] { s_doubleEnumType, 1.0 }; - yield return new object[] { s_intPtrEnumType, (IntPtr)1 }; - yield return new object[] { s_uintPtrEnumType, (UIntPtr)1 }; - } - - [Theory] - [MemberData(nameof(UnsupportedEnumType_TestData))] - public static void GetName_Unsupported_ThrowsArgumentException(Type enumType, object value) - { - Assert.Throws("value", () => Enum.GetName(enumType, value)); - } -#endif // netcoreapp - [Fact] public static void GetName_Invalid() { @@ -479,18 +462,6 @@ public static void IsDefined(Type enumType, object value, bool expected) Assert.Equal(expected, Enum.IsDefined(enumType, value)); } -#if netcoreapp - [Theory] - [MemberData(nameof(UnsupportedEnumType_TestData))] - public static void IsDefined_UnsupportedEnumType_ThrowsInvalidOperationException(Type enumType, object value) - { - // A Contract.Assert(false, "...") is hit for certain unsupported primitives - Exception ex = Assert.ThrowsAny(() => Enum.IsDefined(enumType, value)); - string exName = ex.GetType().Name; - Assert.True(exName == nameof(InvalidOperationException) || exName == "ContractException"); - } -#endif // netcoreapp - [Fact] public static void IsDefined_Invalid() { @@ -1484,18 +1455,6 @@ public static void ToString_Format(Enum e, string format, string expected) Format(e.GetType(), e, format, expected); } -#if netcoreapp - [Fact] - public static void ToString_InvalidUnicodeChars() - { - // TODO: move into ToString_Format_TestData when dotnet/buildtools#1091 is fixed - ToString_Format((Enum)Enum.ToObject(s_charEnumType, char.MaxValue), "D", char.MaxValue.ToString()); - ToString_Format((Enum)Enum.ToObject(s_charEnumType, char.MaxValue), "X", "FFFF"); - ToString_Format((Enum)Enum.ToObject(s_charEnumType, char.MaxValue), "F", char.MaxValue.ToString()); - ToString_Format((Enum)Enum.ToObject(s_charEnumType, char.MaxValue), "G", char.MaxValue.ToString()); - } -#endif // netcoreapp - [Fact] public static void ToString_Format_MultipleMatches() { @@ -1506,26 +1465,6 @@ public static void ToString_Format_MultipleMatches() Assert.True(s == "Green" || s == "Green_a" || s == "Green_b"); } -#if netcoreapp - public static IEnumerable UnsupportedEnum_TestData() - { - yield return new object[] { Enum.ToObject(s_floatEnumType, 1) }; - yield return new object[] { Enum.ToObject(s_doubleEnumType, 2) }; - yield return new object[] { Enum.ToObject(s_intPtrEnumType, 1) }; - yield return new object[] { Enum.ToObject(s_uintPtrEnumType, 2) }; - } - - [Theory] - [MemberData(nameof(UnsupportedEnum_TestData))] - public static void ToString_UnsupportedEnumType_ThrowsArgumentException(Enum e) - { - // A Contract.Assert(false, "...") is hit for certain unsupported primitives - Exception formatXException = Assert.ThrowsAny(() => e.ToString("X")); - string formatXExceptionName = formatXException.GetType().Name; - Assert.True(formatXExceptionName == nameof(InvalidOperationException) || formatXExceptionName == "ContractException"); - } -#endif // netcoreapp - [Fact] public static void ToString_InvalidFormat_ThrowsFormatException() { @@ -1557,26 +1496,6 @@ public static void Format(Type enumType, object value, string format, string exp Assert.Equal(expected, Enum.Format(enumType, value, format.ToLowerInvariant())); } -#if netcoreapp - [Theory] - [MemberData(nameof(UnsupportedEnumType_TestData))] - public static void Format_UnsupportedEnumType_ThrowsArgumentException(Type enumType, object value) - { - // A Contract.Assert(false, "...") is hit for certain unsupported primitives - Exception formatGException = Assert.ThrowsAny(() => Enum.Format(enumType, value, "G")); - string formatGExceptionName = formatGException.GetType().Name; - Assert.True(formatGExceptionName == nameof(InvalidOperationException) || formatGExceptionName == "ContractException"); - - Exception formatXException = Assert.ThrowsAny(() => Enum.Format(enumType, value, "X")); - string formatXExceptionName = formatXException.GetType().Name; - Assert.True(formatXExceptionName == nameof(InvalidOperationException) || formatXExceptionName == "ContractException"); - - Exception formatFException = Assert.ThrowsAny(() => Enum.Format(enumType, value, "F")); - string formatFExceptionName = formatFException.GetType().Name; - Assert.True(formatFExceptionName == nameof(InvalidOperationException) || formatFExceptionName == "ContractException"); - } -#endif // netcoreapp - [Fact] public static void Format_Invalid() { @@ -1595,95 +1514,5 @@ public static void Format_Invalid() Assert.Throws(() => Enum.Format(typeof(SimpleEnum), SimpleEnum.Red, " \t")); // Format is whitespace Assert.Throws(() => Enum.Format(typeof(SimpleEnum), SimpleEnum.Red, "t")); // No such format } - -#if netcoreapp // EnumBuilder is defined in netcoreapp - private static EnumBuilder GetNonRuntimeEnumTypeBuilder(Type underlyingType) - { - AssemblyBuilder assembly = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Name"), AssemblyBuilderAccess.Run); - ModuleBuilder module = assembly.DefineDynamicModule("Name"); - - return module.DefineEnum("TestName_" + underlyingType.Name, TypeAttributes.Public, underlyingType); - } - - private static Type s_boolEnumType = GetBoolEnumType(); - private static Type GetBoolEnumType() - { - EnumBuilder enumBuilder = GetNonRuntimeEnumTypeBuilder(typeof(bool)); - enumBuilder.DefineLiteral("Value1", true); - enumBuilder.DefineLiteral("Value2", false); - - return enumBuilder.CreateTypeInfo().AsType(); - } - - private static Type s_charEnumType = GetCharEnumType(); - private static Type GetCharEnumType() - { - EnumBuilder enumBuilder = GetNonRuntimeEnumTypeBuilder(typeof(char)); - enumBuilder.DefineLiteral("Value1", (char)1); - enumBuilder.DefineLiteral("Value2", (char)2); - - enumBuilder.DefineLiteral("Value0x3f06", (char)0x3f06); - enumBuilder.DefineLiteral("Value0x3000", (char)0x3000); - enumBuilder.DefineLiteral("Value0x0f06", (char)0x0f06); - enumBuilder.DefineLiteral("Value0x1000", (char)0x1000); - enumBuilder.DefineLiteral("Value0x0000", (char)0x0000); - enumBuilder.DefineLiteral("Value0x0010", (char)0x0010); - enumBuilder.DefineLiteral("Value0x3f16", (char)0x3f16); - - return enumBuilder.CreateTypeInfo().AsType(); - } - - private static Type s_floatEnumType = GetFloatEnumType(); - private static Type GetFloatEnumType() - { - EnumBuilder enumBuilder = GetNonRuntimeEnumTypeBuilder(typeof(float)); - enumBuilder.DefineLiteral("Value1", 1.0f); - enumBuilder.DefineLiteral("Value2", 2.0f); - - enumBuilder.DefineLiteral("Value0x3f06", (float)0x3f06); - enumBuilder.DefineLiteral("Value0x3000", (float)0x3000); - enumBuilder.DefineLiteral("Value0x0f06", (float)0x0f06); - enumBuilder.DefineLiteral("Value0x1000", (float)0x1000); - enumBuilder.DefineLiteral("Value0x0000", (float)0x0000); - enumBuilder.DefineLiteral("Value0x0010", (float)0x0010); - enumBuilder.DefineLiteral("Value0x3f16", (float)0x3f16); - - return enumBuilder.CreateTypeInfo().AsType(); - } - - private static Type s_doubleEnumType = GetDoubleEnumType(); - private static Type GetDoubleEnumType() - { - EnumBuilder enumBuilder = GetNonRuntimeEnumTypeBuilder(typeof(double)); - enumBuilder.DefineLiteral("Value1", 1.0); - enumBuilder.DefineLiteral("Value2", 2.0); - - enumBuilder.DefineLiteral("Value0x3f06", (double)0x3f06); - enumBuilder.DefineLiteral("Value0x3000", (double)0x3000); - enumBuilder.DefineLiteral("Value0x0f06", (double)0x0f06); - enumBuilder.DefineLiteral("Value0x1000", (double)0x1000); - enumBuilder.DefineLiteral("Value0x0000", (double)0x0000); - enumBuilder.DefineLiteral("Value0x0010", (double)0x0010); - enumBuilder.DefineLiteral("Value0x3f16", (double)0x3f16); - - return enumBuilder.CreateTypeInfo().AsType(); - } - - private static Type s_intPtrEnumType = GetIntPtrEnumType(); - private static Type GetIntPtrEnumType() - { - EnumBuilder enumBuilder = GetNonRuntimeEnumTypeBuilder(typeof(IntPtr)); - - return enumBuilder.CreateTypeInfo().AsType(); - } - - private static Type s_uintPtrEnumType = GetUIntPtrEnumType(); - private static Type GetUIntPtrEnumType() - { - EnumBuilder enumBuilder = GetNonRuntimeEnumTypeBuilder(typeof(UIntPtr)); - - return enumBuilder.CreateTypeInfo().AsType(); - } -#endif // netcoreapp } } diff --git a/src/System.Runtime/tests/System/EnumTests.netcoreapp.cs b/src/System.Runtime/tests/System/EnumTests.netcoreapp.cs index c7c7fb8c3061..b2d7342a48c0 100644 --- a/src/System.Runtime/tests/System/EnumTests.netcoreapp.cs +++ b/src/System.Runtime/tests/System/EnumTests.netcoreapp.cs @@ -71,5 +71,164 @@ public static void Parse_Invalid_NetCoreApp11(Type enumType, string value, bool Assert.Equal(default(object), result); } } + + public static IEnumerable UnsupportedEnumType_TestData() + { + yield return new object[] { s_floatEnumType, 1.0f }; + yield return new object[] { s_doubleEnumType, 1.0 }; + yield return new object[] { s_intPtrEnumType, (IntPtr)1 }; + yield return new object[] { s_uintPtrEnumType, (UIntPtr)1 }; + } + + [Theory] + [MemberData(nameof(UnsupportedEnumType_TestData))] + public static void GetName_Unsupported_ThrowsArgumentException(Type enumType, object value) + { + Assert.Throws("value", () => Enum.GetName(enumType, value)); + } + + [Theory] + [MemberData(nameof(UnsupportedEnumType_TestData))] + public static void IsDefined_UnsupportedEnumType_ThrowsInvalidOperationException(Type enumType, object value) + { + // A Contract.Assert(false, "...") is hit for certain unsupported primitives + Exception ex = Assert.ThrowsAny(() => Enum.IsDefined(enumType, value)); + string exName = ex.GetType().Name; + Assert.True(exName == nameof(InvalidOperationException) || exName == "ContractException"); + } + + [Fact] + public static void ToString_InvalidUnicodeChars() + { + // TODO: move into ToString_Format_TestData when dotnet/buildtools#1091 is fixed + ToString_Format((Enum)Enum.ToObject(s_charEnumType, char.MaxValue), "D", char.MaxValue.ToString()); + ToString_Format((Enum)Enum.ToObject(s_charEnumType, char.MaxValue), "X", "FFFF"); + ToString_Format((Enum)Enum.ToObject(s_charEnumType, char.MaxValue), "F", char.MaxValue.ToString()); + ToString_Format((Enum)Enum.ToObject(s_charEnumType, char.MaxValue), "G", char.MaxValue.ToString()); + } + + public static IEnumerable UnsupportedEnum_TestData() + { + yield return new object[] { Enum.ToObject(s_floatEnumType, 1) }; + yield return new object[] { Enum.ToObject(s_doubleEnumType, 2) }; + yield return new object[] { Enum.ToObject(s_intPtrEnumType, 1) }; + yield return new object[] { Enum.ToObject(s_uintPtrEnumType, 2) }; + } + + [Theory] + [MemberData(nameof(UnsupportedEnum_TestData))] + public static void ToString_UnsupportedEnumType_ThrowsArgumentException(Enum e) + { + // A Contract.Assert(false, "...") is hit for certain unsupported primitives + Exception formatXException = Assert.ThrowsAny(() => e.ToString("X")); + string formatXExceptionName = formatXException.GetType().Name; + Assert.True(formatXExceptionName == nameof(InvalidOperationException) || formatXExceptionName == "ContractException"); + } + + [Theory] + [MemberData(nameof(UnsupportedEnumType_TestData))] + public static void Format_UnsupportedEnumType_ThrowsArgumentException(Type enumType, object value) + { + // A Contract.Assert(false, "...") is hit for certain unsupported primitives + Exception formatGException = Assert.ThrowsAny(() => Enum.Format(enumType, value, "G")); + string formatGExceptionName = formatGException.GetType().Name; + Assert.True(formatGExceptionName == nameof(InvalidOperationException) || formatGExceptionName == "ContractException"); + + Exception formatXException = Assert.ThrowsAny(() => Enum.Format(enumType, value, "X")); + string formatXExceptionName = formatXException.GetType().Name; + Assert.True(formatXExceptionName == nameof(InvalidOperationException) || formatXExceptionName == "ContractException"); + + Exception formatFException = Assert.ThrowsAny(() => Enum.Format(enumType, value, "F")); + string formatFExceptionName = formatFException.GetType().Name; + Assert.True(formatFExceptionName == nameof(InvalidOperationException) || formatFExceptionName == "ContractException"); + } + private static EnumBuilder GetNonRuntimeEnumTypeBuilder(Type underlyingType) + { + AssemblyBuilder assembly = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Name"), AssemblyBuilderAccess.Run); + ModuleBuilder module = assembly.DefineDynamicModule("Name"); + + return module.DefineEnum("TestName_" + underlyingType.Name, TypeAttributes.Public, underlyingType); + } + + private static Type s_boolEnumType = GetBoolEnumType(); + private static Type GetBoolEnumType() + { + EnumBuilder enumBuilder = GetNonRuntimeEnumTypeBuilder(typeof(bool)); + enumBuilder.DefineLiteral("Value1", true); + enumBuilder.DefineLiteral("Value2", false); + + return enumBuilder.CreateTypeInfo().AsType(); + } + + private static Type s_charEnumType = GetCharEnumType(); + private static Type GetCharEnumType() + { + EnumBuilder enumBuilder = GetNonRuntimeEnumTypeBuilder(typeof(char)); + enumBuilder.DefineLiteral("Value1", (char)1); + enumBuilder.DefineLiteral("Value2", (char)2); + + enumBuilder.DefineLiteral("Value0x3f06", (char)0x3f06); + enumBuilder.DefineLiteral("Value0x3000", (char)0x3000); + enumBuilder.DefineLiteral("Value0x0f06", (char)0x0f06); + enumBuilder.DefineLiteral("Value0x1000", (char)0x1000); + enumBuilder.DefineLiteral("Value0x0000", (char)0x0000); + enumBuilder.DefineLiteral("Value0x0010", (char)0x0010); + enumBuilder.DefineLiteral("Value0x3f16", (char)0x3f16); + + return enumBuilder.CreateTypeInfo().AsType(); + } + + private static Type s_floatEnumType = GetFloatEnumType(); + private static Type GetFloatEnumType() + { + EnumBuilder enumBuilder = GetNonRuntimeEnumTypeBuilder(typeof(float)); + enumBuilder.DefineLiteral("Value1", 1.0f); + enumBuilder.DefineLiteral("Value2", 2.0f); + + enumBuilder.DefineLiteral("Value0x3f06", (float)0x3f06); + enumBuilder.DefineLiteral("Value0x3000", (float)0x3000); + enumBuilder.DefineLiteral("Value0x0f06", (float)0x0f06); + enumBuilder.DefineLiteral("Value0x1000", (float)0x1000); + enumBuilder.DefineLiteral("Value0x0000", (float)0x0000); + enumBuilder.DefineLiteral("Value0x0010", (float)0x0010); + enumBuilder.DefineLiteral("Value0x3f16", (float)0x3f16); + + return enumBuilder.CreateTypeInfo().AsType(); + } + + private static Type s_doubleEnumType = GetDoubleEnumType(); + private static Type GetDoubleEnumType() + { + EnumBuilder enumBuilder = GetNonRuntimeEnumTypeBuilder(typeof(double)); + enumBuilder.DefineLiteral("Value1", 1.0); + enumBuilder.DefineLiteral("Value2", 2.0); + + enumBuilder.DefineLiteral("Value0x3f06", (double)0x3f06); + enumBuilder.DefineLiteral("Value0x3000", (double)0x3000); + enumBuilder.DefineLiteral("Value0x0f06", (double)0x0f06); + enumBuilder.DefineLiteral("Value0x1000", (double)0x1000); + enumBuilder.DefineLiteral("Value0x0000", (double)0x0000); + enumBuilder.DefineLiteral("Value0x0010", (double)0x0010); + enumBuilder.DefineLiteral("Value0x3f16", (double)0x3f16); + + return enumBuilder.CreateTypeInfo().AsType(); + } + + private static Type s_intPtrEnumType = GetIntPtrEnumType(); + private static Type GetIntPtrEnumType() + { + EnumBuilder enumBuilder = GetNonRuntimeEnumTypeBuilder(typeof(IntPtr)); + + return enumBuilder.CreateTypeInfo().AsType(); + } + + private static Type s_uintPtrEnumType = GetUIntPtrEnumType(); + private static Type GetUIntPtrEnumType() + { + EnumBuilder enumBuilder = GetNonRuntimeEnumTypeBuilder(typeof(UIntPtr)); + + return enumBuilder.CreateTypeInfo().AsType(); + } + } }