Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EnumBuilder.CreateType back in the public API #49319

Merged
merged 1 commit into from
Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ internal AssemblyBuilder() { }
public override string? CodeBase { get { throw null; } }
public override System.Reflection.MethodInfo? EntryPoint { get { throw null; } }
public override string? FullName { get { throw null; } }
[System.ObsoleteAttribute("The Global Assembly Cache is not supported.", DiagnosticId = "SYSLIB0005", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
eerhardt marked this conversation as resolved.
Show resolved Hide resolved
public override bool GlobalAssemblyCache { get { throw null; } }
public override long HostContext { get { throw null; } }
public override string ImageRuntimeVersion { get { throw null; } }
public override bool IsCollectible { get { throw null; } }
public override bool IsDynamic { get { throw null; } }
public override string Location { get { throw null; } }
public override System.Reflection.Module ManifestModule { get { throw null; } }
Expand Down Expand Up @@ -65,6 +63,7 @@ internal ConstructorBuilder() { }
public override System.Reflection.CallingConventions CallingConvention { get { throw null; } }
public override System.Type? DeclaringType { get { throw null; } }
public bool InitLocals { get { throw null; } set { } }
public override int MetadataToken { get { throw null; } }
eerhardt marked this conversation as resolved.
Show resolved Hide resolved
public override System.RuntimeMethodHandle MethodHandle { get { throw null; } }
public override System.Reflection.Module Module { get { throw null; } }
public override string Name { get { throw null; } }
Expand All @@ -79,7 +78,6 @@ internal ConstructorBuilder() { }
public override object Invoke(object? obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder? binder, object?[]? parameters, System.Globalization.CultureInfo? culture) { throw null; }
public override object Invoke(System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder? binder, object?[]? parameters, System.Globalization.CultureInfo? culture) { throw null; }
public override bool IsDefined(System.Type attributeType, bool inherit) { throw null; }
public override int MetadataToken { get { throw null; } }
public void SetCustomAttribute(System.Reflection.ConstructorInfo con, byte[] binaryAttribute) { }
public void SetCustomAttribute(System.Reflection.Emit.CustomAttributeBuilder customBuilder) { }
public void SetImplementationFlags(System.Reflection.MethodImplAttributes attributes) { }
Expand All @@ -98,7 +96,6 @@ internal EnumBuilder() { }
public override bool IsConstructedGenericType { get { throw null; } }
public override bool IsSZArray { get { throw null; } }
public override bool IsTypeDefinition { get { throw null; } }
public override bool IsVariableBoundArray { get { throw null; } }
public override System.Reflection.Module Module { get { throw null; } }
public override string Name { get { throw null; } }
public override string? Namespace { get { throw null; } }
Expand All @@ -107,6 +104,8 @@ internal EnumBuilder() { }
public System.Reflection.Emit.FieldBuilder UnderlyingField { get { throw null; } }
public override System.Type UnderlyingSystemType { get { throw null; } }
[return: System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)]
public System.Type? CreateType() { throw null; }
[return: System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)]
public System.Reflection.TypeInfo? CreateTypeInfo() { throw null; }
public System.Reflection.Emit.FieldBuilder DefineLiteral(string literalName, object? literalValue) { throw null; }
protected override System.Reflection.TypeAttributes GetAttributeFlagsImpl() { throw null; }
Expand Down Expand Up @@ -151,6 +150,7 @@ internal EnumBuilder() { }
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)]
public override object? InvokeMember(string name, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder? binder, object? target, object?[]? args, System.Reflection.ParameterModifier[]? modifiers, System.Globalization.CultureInfo? culture, string[]? namedParameters) { throw null; }
protected override bool IsArrayImpl() { throw null; }
public override bool IsAssignableFrom([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] System.Reflection.TypeInfo? typeInfo) { throw null; }
protected override bool IsByRefImpl() { throw null; }
protected override bool IsCOMObjectImpl() { throw null; }
public override bool IsDefined(System.Type attributeType, bool inherit) { throw null; }
Expand Down Expand Up @@ -215,7 +215,6 @@ internal GenericTypeParameterBuilder() { }
public override bool IsGenericTypeDefinition { get { throw null; } }
public override bool IsSZArray { get { throw null; } }
public override bool IsTypeDefinition { get { throw null; } }
public override bool IsVariableBoundArray { get { throw null; } }
public override int MetadataToken { get { throw null; } }
public override System.Reflection.Module Module { get { throw null; } }
public override string Name { get { throw null; } }
Expand Down Expand Up @@ -268,6 +267,7 @@ internal GenericTypeParameterBuilder() { }
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)]
public override object InvokeMember(string name, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder? binder, object? target, object?[]? args, System.Reflection.ParameterModifier[]? modifiers, System.Globalization.CultureInfo? culture, string[]? namedParameters) { throw null; }
protected override bool IsArrayImpl() { throw null; }
public override bool IsAssignableFrom([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] System.Reflection.TypeInfo? typeInfo) { throw null; }
public override bool IsAssignableFrom([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] System.Type? c) { throw null; }
protected override bool IsByRefImpl() { throw null; }
protected override bool IsCOMObjectImpl() { throw null; }
Expand Down Expand Up @@ -296,7 +296,6 @@ internal MethodBuilder() { }
public override bool ContainsGenericParameters { get { throw null; } }
public override System.Type? DeclaringType { get { throw null; } }
public bool InitLocals { get { throw null; } set { } }
public override bool IsConstructedGenericMethod { get { throw null; } }
public override bool IsGenericMethod { get { throw null; } }
public override bool IsGenericMethodDefinition { get { throw null; } }
public override bool IsSecurityCritical { get { throw null; } }
Expand Down Expand Up @@ -371,6 +370,8 @@ public void CreateGlobalFunctions() { }
public override System.Reflection.FieldInfo[] GetFields(System.Reflection.BindingFlags bindingFlags) { throw null; }
public override int GetHashCode() { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Methods might be removed")]
protected override System.Reflection.MethodInfo? GetMethodImpl(string name, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder? binder, System.Reflection.CallingConventions callConvention, System.Type[]? types, System.Reflection.ParameterModifier[]? modifiers) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Methods might be removed")]
public override System.Reflection.MethodInfo[] GetMethods(System.Reflection.BindingFlags bindingFlags) { throw null; }
public override void GetPEKind(out System.Reflection.PortableExecutableKinds peKind, out System.Reflection.ImageFileMachine machine) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Types might be removed")]
Expand Down Expand Up @@ -450,7 +451,6 @@ internal TypeBuilder() { }
public override bool IsSecurityTransparent { get { throw null; } }
public override bool IsSZArray { get { throw null; } }
public override bool IsTypeDefinition { get { throw null; } }
public override bool IsVariableBoundArray { get { throw null; } }
public override int MetadataToken { get { throw null; } }
public override System.Reflection.Module Module { get { throw null; } }
public override string Name { get { throw null; } }
Expand Down Expand Up @@ -541,6 +541,7 @@ public void DefineMethodOverride(System.Reflection.MethodInfo methodInfoBody, Sy
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)]
public override object? InvokeMember(string name, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder? binder, object? target, object?[]? args, System.Reflection.ParameterModifier[]? modifiers, System.Globalization.CultureInfo? culture, string[]? namedParameters) { throw null; }
protected override bool IsArrayImpl() { throw null; }
public override bool IsAssignableFrom([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] System.Reflection.TypeInfo? typeInfo) { throw null; }
public override bool IsAssignableFrom([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] System.Type? c) { throw null; }
protected override bool IsByRefImpl() { throw null; }
protected override bool IsCOMObjectImpl() { throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,9 @@ Compat issues with assembly System.Reflection.Emit:
MembersMustExist : Member 'public System.Reflection.Emit.ModuleBuilder System.Reflection.Emit.AssemblyBuilder.DefineDynamicModule(System.String, System.Boolean)' does not exist in the reference but it does exist in the implementation.
MembersMustExist : Member 'public System.Reflection.Module System.Reflection.Emit.ConstructorBuilder.GetModule()' does not exist in the reference but it does exist in the implementation.
MembersMustExist : Member 'public System.String System.Reflection.Emit.ConstructorBuilder.Signature.get()' does not exist in the reference but it does exist in the implementation.
CannotRemoveBaseTypeOrInterface : Type 'System.Reflection.Emit.EnumBuilder' does not inherit from base type 'System.Reflection.TypeInfo' in the reference but it does in the implementation.
MembersMustExist : Member 'public System.Type System.Reflection.Emit.EnumBuilder.CreateType()' does not exist in the reference but it does exist in the implementation.
MembersMustExist : Member 'public System.Boolean System.Reflection.Emit.EnumBuilder.IsAssignableFrom(System.Reflection.TypeInfo)' does not exist in the reference but it does exist in the implementation.
CannotRemoveBaseTypeOrInterface : Type 'System.Reflection.Emit.GenericTypeParameterBuilder' does not inherit from base type 'System.Reflection.TypeInfo' in the reference but it does in the implementation.
MembersMustExist : Member 'public System.Boolean System.Reflection.Emit.GenericTypeParameterBuilder.IsAssignableFrom(System.Reflection.TypeInfo)' does not exist in the reference but it does exist in the implementation.
MembersMustExist : Member 'public System.Reflection.Module System.Reflection.Emit.MethodBuilder.GetModule()' does not exist in the reference but it does exist in the implementation.
MembersMustExist : Member 'public System.String System.Reflection.Emit.MethodBuilder.Signature.get()' does not exist in the reference but it does exist in the implementation.
MembersMustExist : Member 'public System.Diagnostics.SymbolStore.ISymbolDocumentWriter System.Reflection.Emit.ModuleBuilder.DefineDocument(System.String, System.Guid, System.Guid, System.Guid)' does not exist in the reference but it does exist in the implementation.
MembersMustExist : Member 'protected System.ModuleHandle System.Reflection.Emit.ModuleBuilder.GetModuleHandleImpl()' does not exist in the reference but it does exist in the implementation.
MembersMustExist : Member 'public System.Boolean System.Reflection.Emit.ModuleBuilder.IsTransient()' does not exist in the reference but it does exist in the implementation.
CannotRemoveBaseTypeOrInterface : Type 'System.Reflection.Emit.TypeBuilder' does not inherit from base type 'System.Reflection.TypeInfo' in the reference but it does in the implementation.
MembersMustExist : Member 'public System.Boolean System.Reflection.Emit.TypeBuilder.IsAssignableFrom(System.Reflection.TypeInfo)' does not exist in the reference but it does exist in the implementation.
Total Issues: 15
Total Issues: 8
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ namespace System.Reflection.Emit.Tests
public class EnumBuilderMethodTests
{
public static IEnumerable<object[]> DefineLiteral_TestData()
{
foreach (object[] coreData in DefineLiteralTestDataCore())
{
yield return coreData.Concat(new object[] { true }).ToArray();
yield return coreData.Concat(new object[] { false }).ToArray();
}
}

private static IEnumerable<object[]> DefineLiteralTestDataCore()
{
yield return new object[] { typeof(byte), (byte)0 };
yield return new object[] { typeof(byte), (byte)1 };
Expand Down Expand Up @@ -51,7 +60,7 @@ public static IEnumerable<object[]> DefineLiteral_TestData()
[Theory]
[ActiveIssue("https://github.com/dotnet/runtime/issues/2389", TestRuntimes.Mono)]
[MemberData(nameof(DefineLiteral_TestData))]
public void DefineLiteral(Type underlyingType, object literalValue)
public void DefineLiteral(Type underlyingType, object literalValue, bool useCreateTypeInfo)
{
EnumBuilder enumBuilder = Helpers.DynamicEnum(TypeAttributes.Public, underlyingType);
FieldBuilder literal = enumBuilder.DefineLiteral("FieldOne", literalValue);
Expand All @@ -61,7 +70,10 @@ public void DefineLiteral(Type underlyingType, object literalValue)
Assert.Equal(FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal, literal.Attributes);
Assert.Equal(enumBuilder.AsType(), literal.FieldType);

Type createdEnum = enumBuilder.CreateTypeInfo().AsType();
Type createdEnum = useCreateTypeInfo ?
enumBuilder.CreateTypeInfo().AsType() :
enumBuilder.CreateType();

FieldInfo createdLiteral = createdEnum.GetField("FieldOne");
Assert.Equal(createdEnum, createdLiteral.FieldType);

Expand Down Expand Up @@ -123,17 +135,27 @@ public void DefineLiteral_InvalidLiteralValue_ThrowsArgumentException(Type under

public static IEnumerable<object[]> DefineLiteral_InvalidLiteralValue_ThrowsTypeLoadExceptionOnCreation_TestData()
{
yield return new object[] { typeof(DateTime), DateTime.Now };
yield return new object[] { typeof(string), "" }; ;
yield return new object[] { typeof(DateTime), DateTime.Now, true };
yield return new object[] { typeof(DateTime), DateTime.Now, false };

yield return new object[] { typeof(string), "", true };
yield return new object[] { typeof(string), "", false };
}

[Theory]
[MemberData(nameof(DefineLiteral_InvalidLiteralValue_ThrowsTypeLoadExceptionOnCreation_TestData))]
public void DefineLiteral_InvalidLiteralValue_ThrowsTypeLoadExceptionOnCreation(Type underlyingType, object literalValue)
public void DefineLiteral_InvalidLiteralValue_ThrowsTypeLoadExceptionOnCreation(Type underlyingType, object literalValue, bool useCreateTypeInfo)
{
EnumBuilder enumBuilder = Helpers.DynamicEnum(TypeAttributes.Public, underlyingType);
FieldBuilder literal = enumBuilder.DefineLiteral("LiteralName", literalValue);
Assert.Throws<TypeLoadException>(() => enumBuilder.CreateTypeInfo());
if (useCreateTypeInfo)
{
Assert.Throws<TypeLoadException>(() => enumBuilder.CreateTypeInfo());
}
else
{
Assert.Throws<TypeLoadException>(() => enumBuilder.CreateType());
}
}

[Fact]
Expand Down