请教CodeDom的问题
请问如何用CodeDom生成一个重写的方法。
比如: public override int add(int x,int y)(){...}
------解决方案--------------------指定类型试试看:
method1.Attributes = MemberAttributes.Overloaded
比如:
CodeMemberMethod method1 = new CodeMemberMethod();
method1.Name = "ReturnString ";
CodeTypeReference cr = new CodeTypeReference( "System.String ");
cr.Options = CodeTypeReferenceOptions.GenericTypeParameter;
method1.Attributes = MemberAttributes.Overloaded;
method1.ReturnType = cr;
method1.Parameters.Add(new CodeParameterDeclarationExpression( "System.String ", "text "));
method1.Statements.Add(new CodeMethodReturnStatement(new CodeArgumentReferenceExpression( "text ")));
------解决方案--------------------比如:
CodeConditionStatement ep = new CodeConditionStatement();
ep.Condition = new CodeBinaryOperatorExpression(new CodePrimitiveExpression(null), CodeBinaryOperatorType.IdentityInequality, new CodeVariableReferenceExpression( "i "));
// Add the WriteLine call to the statement collection.
start.Statements.Add(ep);