我最近开始使用CodeDom来生成类和接口,但从不定义函数或创建并启动Task
。我需要使用CodeDom复制此代码:
public async Task<CustomTestResponse> CustomObjectTestAsync(CustomObjectTestRequest request)
{
var call = await Task.Run<CustomObjectTestResponse>(() =>
{
CustomObjectTestResponse response = new CustomObjectTestResponse();
string result;
TESTING.Testing test;
response.CustomObjectTestResponseResult = BaseChannel.CustomObjectTest(request.Test, request.IsFake, out result, out test);
response.OutTest = test;
response.Result = result;
return response;
});
return call;
}
我已经完成了功能定义,但是我无法弄清楚如何进行内部部分(从var call
到return call;
)这就是我所拥有的:
CodeMemberMethod implementationMethod = new CodeMemberMethod();
implementationMethod.Attributes = MemberAttributes.Public;
implementationMethod.Name = asyncMethod.Identifier.ToString() + "Async";
implementationMethod.ReturnType = new CodeTypeReference("async Task<" + className + "Response>");
任何帮助将不胜感激!
编辑:我已经慢慢开始进步了,但是通过使用一个大的CodeSnippetExpression
并生成我想要的代码并推进该变量......当然必须有更好的方法!