Generate Extension Methods using System.CodeDom

前端 未结 2 712
日久生厌
日久生厌 2021-01-05 15:58

Has anyone ever tried to generate extension methods using System.CodeDom under .NET 4.0? There doesn\'t seem to be any way to specify a CodeMemberMethod or CodeParameterDecl

2条回答
  •  Happy的楠姐
    2021-01-05 16:09

    Apparently CodeDom isn't able to generate the correct code for the first parameter of an extension method, but you can cheat it like this:

    var param = new CodeParameterDeclarationExpression("this string", "s");
    

    It will blissfully ignore the fact that "this string" is not a valid type...

提交回复
热议问题