CodeDom and typeof

  • Thread starter Thread starter ThisBytes5
  • Start date Start date
T

ThisBytes5

I have the need to generate the following code:

Type someVar = typeof(MyType);

I know how to declare the var and can intialize vars except in this
case.

I can't figure out how to get the codedom to generate a cll to typeof.
Any help would be appreciated.
 
Try something like this:

CodeTypeReference typeRef = new CodeTypeReference("MyType");
CodeTypeOfExpression typeofValue = new CodeTypeOfExpression(typeRef);
Statements.Add( new CodeAssignStatement(
new CodeFieldReferenceExpression(new CodeThisReferenceExpression(),
someVar) ,
typeofValue) );

Lionel.
 
Back
Top