C# 如何避免在生成的方法语句中出现括号
我在尝试使用codedom生成一些c#代码的同时,尝试执行一个assign语句 以下是我写的声明:C# 如何避免在生成的方法语句中出现括号,c#,codedom,C#,Codedom,我在尝试使用codedom生成一些c#代码的同时,尝试执行一个assign语句 以下是我写的声明: inputmethod.Name = "CaptureInput"; inputmethod.Attributes = MemberAttributes.Public | MemberAttributes.Final; inputmethod.Parameters.Add( new CodeParameterDeclarationExpression(typeof(string[]), "
inputmethod.Name = "CaptureInput";
inputmethod.Attributes = MemberAttributes.Public | MemberAttributes.Final;
inputmethod.Parameters.Add(
new CodeParameterDeclarationExpression(typeof(string[]), "inputs"));
inputmethod.Statements.Add(
new CodeBinaryOperatorExpression(
new CodePropertyReferenceExpression(
new CodeThisReferenceExpression(), "ColA")
, CodeBinaryOperatorType.Assign
, new CodeArrayIndexerExpression(
new CodeVariableReferenceExpression("inputs"),
new CodePrimitiveExpression(0))));
当它生成时,我会得到一条如下的线:
(this.ColA = input [0]);
编译器发现上述行有错误,CS0201
如何删除生成的输出中的括号?括号是BinaryOperatorExpression的一部分。不要移除它们 使用而不是CodeBinaryOperatorExpression
inputmethod.Statements.Add(new CodeAssignStatement(
new CodeVariableReferenceExpression("ColA"),
new CodeArrayIndexerExpression(
new CodeVariableReferenceExpression("inputs"),
new CodePrimitiveExpression(0))));
生成的行似乎是方法调用的一部分。这就是inputMethod吗?它是CodeMemberMethod。。。