[英]CodeDom How to create a method with void return type?
public void CreateMethod()
{
CodeMemberMethod mymethod = new CodeMemberMethod();
mymethod.Name = testMethod;
CodeTypeReference ctr = new CodeTypeReference();
//Assign the return type to the method.
mymethod.ReturnType = ctr;
CodeSnippetExpression snippet1 = new CodeSnippetExpression("AutomationBase obj = new AutomationBase()");
CodeSnippetExpression snippet2 = new CodeSnippetExpression("obj.Execute(testCases[1])");
CodeExpressionStatement stmt1 = new CodeExpressionStatement(snippet1);
CodeExpressionStatement stmt2 = new CodeExpressionStatement(snippet2);
mymethod.Statements.Add(stmt1);
mymethod.Statements.Add(stmt2);
mymethod.Attributes = MemberAttributes.Public;
myclass.Members.Add(mymethod);
}
产量
public virtual void TestCaseId002() {
AutomationBase obj = new AutomationBase();
obj.Execute(testCases[1]);
}
虚拟虚无
我只需要虚无。
您需要将方法标记为Final
,以指示该方法不可继承:
mymethod.Attributes = MemberAttributes.Public | MemberAttributes.Final;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.