CodeDom
-
Hi I'm using CodeDom and I want it to generate code such as the following:
if (var is MyClass) { //Do stuff }
The code I am currently using to perform the generation is
CodeConditionStatement ifStatement = new CodeConditionStatement(); ifStatement.Condition = new CodeBinaryOperatorExpression(lhs, CodeBinaryOperatorType.IdentityEquality, rhs);
this code will generate the below statement
if (var == MyClass) { //Do stuff }
All that needs to change is the ==, which needs to change to 'is'. Is this possible to do in CodeDom? Also note that 'var' can also be a child class of MyClass (which is why I did not use var.GetType() == typeof(MyClass)) thanks
-
Hi I'm using CodeDom and I want it to generate code such as the following:
if (var is MyClass) { //Do stuff }
The code I am currently using to perform the generation is
CodeConditionStatement ifStatement = new CodeConditionStatement(); ifStatement.Condition = new CodeBinaryOperatorExpression(lhs, CodeBinaryOperatorType.IdentityEquality, rhs);
this code will generate the below statement
if (var == MyClass) { //Do stuff }
All that needs to change is the ==, which needs to change to 'is'. Is this possible to do in CodeDom? Also note that 'var' can also be a child class of MyClass (which is why I did not use var.GetType() == typeof(MyClass)) thanks
-
Hi I'm using CodeDom and I want it to generate code such as the following:
if (var is MyClass) { //Do stuff }
The code I am currently using to perform the generation is
CodeConditionStatement ifStatement = new CodeConditionStatement(); ifStatement.Condition = new CodeBinaryOperatorExpression(lhs, CodeBinaryOperatorType.IdentityEquality, rhs);
this code will generate the below statement
if (var == MyClass) { //Do stuff }
All that needs to change is the ==, which needs to change to 'is'. Is this possible to do in CodeDom? Also note that 'var' can also be a child class of MyClass (which is why I did not use var.GetType() == typeof(MyClass)) thanks
AFAIK it's impossible to generate 'is' using CodeDom. You can try to use typeof(MyClass).IsInstanceOfType(var).
-
AFAIK it's impossible to generate 'is' using CodeDom. You can try to use typeof(MyClass).IsInstanceOfType(var).