Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. CodeDom

CodeDom

Scheduled Pinned Locked Moved C#
question
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    danielk_
    wrote on last edited by
    #1

    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

    G D 2 Replies Last reply
    0
    • D danielk_

      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

      G Offline
      G Offline
      Gareth H
      wrote on last edited by
      #2

      danielk_, Dunno, why don't you type it and see what happens? Would be a lot quicker than waiting for an answer... Regards, Gareth.

      1 Reply Last reply
      0
      • D danielk_

        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

        D Offline
        D Offline
        Daniel Grunwald
        wrote on last edited by
        #3

        AFAIK it's impossible to generate 'is' using CodeDom. You can try to use typeof(MyClass).IsInstanceOfType(var).

        D 1 Reply Last reply
        0
        • D Daniel Grunwald

          AFAIK it's impossible to generate 'is' using CodeDom. You can try to use typeof(MyClass).IsInstanceOfType(var).

          D Offline
          D Offline
          danielk_
          wrote on last edited by
          #4

          looks good. IsInstanceOfType should do the job thanks

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups