Skip to content

[API Proposal]: Make LocalBuilder abstract #93580

@buyaa-n

Description

@buyaa-n

Background and motivation

For adding AssemblyBuilder.Save() equivalent in .NET Core we have abstracted most of the System.Refleciton.Emit types and adding new implementations for them. This abstraction did not cover LocalBuilder type and its constructor is internal, so I could not create an instance from the new ILGenerator implementation. We need a same treatment for this type: to unseal the LocalBuilder class and make it abstract, make the internal constructor protected, also add a public getter that exposes the method the local belongs.

Related to #92975

API Proposal

namespace System.Reflection.Emit;

-public sealed class LocalBuilder : System.Reflection.LocalVariableInfo
+public abstract class LocalBuilder : System.Reflection.LocalVariableInfo
{
-   internal LocalBuilder(int localIndex, Type localType, MethodInfo method, bool isPinned) { }
+   protected LocalBuilder() { }
+   public abstract MethodInfo LocalMethod { get; }
}

Abstract LocalMethod property can be used for validation. Parent LocalVariableInfo has public virtual properties like LocalType, LocalIndex, IsPinned.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions