-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
[API Proposal]: Add protected factory method for creating Label in ILGenerator, abstract out LocalBuilder #93497
Comments
Tagging subscribers to this area: @dotnet/area-system-reflection-emit Issue DetailsBackground and motivationFor adding Related to #92975 CC @steveharter API Proposalnamespace System.Reflection.Emit;
public abstract class ILGenerator
{
protected ILGenerator() { }
....
+ protected Label CreateLabel(int id) { throw null; }
+ protected LocalBuilder CreateLocal(int localIndex, Type localType, MethodInfo methodBuilder, bool isPinned) { throw null; }
} API Usageinternal sealed class ILGeneratorImpl : ILGenerator
{
public override Label DefineLabel()
{
LabelHandle metadataLabel = _il.DefineLabel();
Label emitLabel = CreateLabel(metadataLabel.Id);
_labelTable.Add(emitLabel, metadataLabel);
return emitLabel;
}
} Alternative DesignsNo response RisksNo response
|
How about we add a way to get the ID of a label, either as an |
That can be useful for handling labels, I think it should be added to the |
How about we make - protected Label CreateLabel(int id) { throw null; }
+ protected static Label CreateLabel(int id) { throw null; } |
Updated, thanks! |
There was discussion around Since the method isn't a feature of the local, but instead describes the context where it exists, the property should be 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 Method { get; }
}
public abstract class ILGenerator
{
protected ILGenerator() { }
...
public abstract Label DefineLabel();
+ protected static Label CreateLabel(int id) { throw null; }
}
public readonly partial struct Label : System.IEquatable<System.Reflection.Emit.Label>
{
...
+ public int Id { get; }
} |
This API seems wrong to me:
I think this needs to be |
@bartonjs and @dotnet/fxdc there were push back on adding - public abstract MethodInfo Method { get; } |
Confirmed that removing the new Property is OK, no need any other action |
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 coverLabel
andLocalBuilder
types and its constructors are internal, so I could not create an instance from the newILGenerator
implementation.API Proposal
For
LocalBuilder
we need to unseal theLocalBuilder
class and make it abstract, make theinternal
constructorprotected
, also add a public getter that exposes themethod
the local belongs to.Abstract
LocalMethod
property can be used for validation. ParentLocalVariableInfo
has public virtual properties likeLocalType
,LocalIndex
,IsPinned
.For
Label
struct we need a protected factory method in the abstractILGenerator
type so that we can create an instance from derived types.API Usage
Related to #92975
CC @steveharter
The text was updated successfully, but these errors were encountered: