如何使用 codedom 创建方法签名中包含“new”关键字的方法

本文关键字:方法 new 关键字 包含 codedom 何使用 创建 | 更新日期: 2023-09-27 18:37:11

我想使用 codedom 在其方法签名中动态生成一个带有"new"关键字的方法。 想要生成这样的东西

private new void MyMethod()
{ 
}

如何使用 codedom 创建方法签名中包含“new”关键字的方法

像这样:

CodeMemberMethod myMethodMethod = new CodeMemberMethod();
myMethodMethod.Attributes = MemberAttributes.Private | MemberAttributes.New;
myMethodMethod.Name = "MyMethod";

这是一个MemberAttributesMemberAttributes.New

当你调用TypeBuilder.DefineMethod时,只需包含MethodAttributes.NewSlot

指示该方法始终在 vtable 中获取新插槽。