0

Hi I am looking for little help here, I know I could generate code something like this

 var conditionMethod = new CodeConditionStatement(conditionStmt);
      conditionMethod.TrueStatements.Add(new CodeAssignStatement(new CodePrimitiveExpression(code1),
        new CodePrimitiveExpression(null)));

      conditionMethod.FalseStatements.Add(new CodeAssignStatement(new CodePrimitiveExpression(code1),
        new CodePrimitiveExpression(5)));

Which is result in proper IF and ELSE block, what I am looking for having something like this

var result = condtion?result1:result2; 

How to generate this type of code from CodeDom, any help is appreciated. thanks

2
  • “? .. : ..” doesn’t exist in MSIL. It’s a C# “convenience” syntax that maps down to primitive conditionals. In short, it’s no different when compiled than explicitly typed out - X result; if (condition) { result = result1; } else { result = result2; } Commented Jun 11, 2020 at 5:55
  • @user2864740 Thanks, actually I am trying to change some old code, where LHS is not available in said method. So I have to create RHS side and using CodeAssignStatement I combine it, so normal IF/ELSE block would not help.. thanks for your tip Commented Jun 11, 2020 at 6:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.