Skip to content

Add back EnumBuilder.CreateType() #46681

Closed

Description

@eerhardt

Background and Motivation

.NET Framework has the following APIs:

System.Type TypeBuilder.CreateType()
System.Reflection.TypeInfo TypeBuilder.CreateTypeInfo()

System.Type EnumBuilder.CreateType()
System.Reflection.TypeInfo EnumBuilder.CreateTypeInfo()

In .NET 5 we have:

System.Type? TypeBuilder.CreateType()
System.Reflection.TypeInfo? TypeBuilder.CreateTypeInfo()

System.Reflection.TypeInfo? EnumBuilder.CreateTypeInfo()

To be consistent with both .NET Framework, and between EnumBuilder and TypeBuilder, we should add back the CreateType() method on EnumBuilder.

Proposed API

namespace System.Reflection.Emit
{
    public sealed class EnumBuilder : System.Reflection.TypeInfo
    {
+       public System.Type? CreateType() { throw null; }
        public System.Reflection.TypeInfo? CreateTypeInfo() { throw null; }
     }

Usage Examples

        EnumBuilder eb = ...;

        // Define two members, "High" and "Low".
        eb.DefineLiteral("Low", 0);
        eb.DefineLiteral("High", 1);

        // Create the type and save the assembly.
        Type finished = eb.CreateType();

cc @terrajobst

Activity

  1. added
    api-suggestion
    on Jan 7, 2021
  2. added
    untriaged
    on Jan 7, 2021
  3. krwq commented on Feb 16, 2021

    @krwq
    Member

    @eerhardt are you planning to send a PR assuming this gets approved? I'll put this into 6.0 backlog for now.

  4. added this to the 6.0.0 milestone on Feb 16, 2021
  5. added
    api-ready-for-review
    and removed
    api-suggestion
    untriaged
    on Feb 16, 2021
  6. eerhardt commented on Feb 16, 2021

    @eerhardt
    MemberAuthor

    @eerhardt are you planning to send a PR assuming this gets approved?

    I can, yes.

  7. added
    api-approved
    and removed
    api-ready-for-review
    on Feb 23, 2021
  8. terrajobst commented on Feb 23, 2021

    @terrajobst
    Contributor

    Video

    • Looks good as proposed
    • We should ensure that we address the other issues in the baseline file or add comments indicating why why are by-design.
    namespace System.Reflection.Emit
    {
        public sealed partial class EnumBuilder : TypeInfo
        {
            public Type? CreateType();
        }
    }
  9. I-SER-I commented on Mar 6, 2021

    @I-SER-I
    Contributor

    @eerhardt And where should this be added if it exist in coreclr, but in corelib EnumBuilder is absent full...?

  10. stephentoub commented on Mar 6, 2021

    @stephentoub
    Member

    It's already in the implementation:


    It just needs to be added to the ref assembly (and tests added).

    public System.Reflection.TypeInfo? CreateTypeInfo() { throw null; }

  11. self-assigned this
    on Mar 8, 2021
  12. added a commit that references this issue on Mar 8, 2021
    08bc96e
  13. ghost added
    in-pr
    on Mar 8, 2021
  14. added a commit that references this issue on Mar 10, 2021
    d576da2
  15. ghost removed
    in-pr
    on Mar 10, 2021
  16. ghost locked as resolved and limited conversation to collaborators on Apr 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api-approvedarea-System.Reflection.Emit

Type

No type

Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions