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. Adding member variables to a class at Runtime..

Adding member variables to a class at Runtime..

Scheduled Pinned Locked Moved C#
python
6 Posts 5 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.
  • N Offline
    N Offline
    nasambur
    wrote on last edited by
    #1

    hi, is it possible to add a member variable/function to a class at runtime.. This is possible in Python.. regards, nas

    S G G 3 Replies Last reply
    0
    • N nasambur

      hi, is it possible to add a member variable/function to a class at runtime.. This is possible in Python.. regards, nas

      S Offline
      S Offline
      S Senthil Kumar
      wrote on last edited by
      #2

      nasambur wrote:

      is it possible to add a member variable/function to a class at runtime..

      C# is a statically typed language, which means that the compiler needs to know about all members of a class during compilation, so that it can lay them out properly in memory. You can add static methods to a class using LCG[^], a new feature in .NET 2.0

      Regards Senthil [MVP - Visual C#] _____________________________ My Blog | My Articles | My Flickr | WinMacro

      1 Reply Last reply
      0
      • N nasambur

        hi, is it possible to add a member variable/function to a class at runtime.. This is possible in Python.. regards, nas

        G Offline
        G Offline
        Guffa
        wrote on last edited by
        #3

        No, that is not possible in .NET. What are you trying to accomplish? For questions like this there usually is an object oriented solution that works just as well, or simetimes even better.

        --- single minded; short sighted; long gone;

        B 1 Reply Last reply
        0
        • G Guffa

          No, that is not possible in .NET. What are you trying to accomplish? For questions like this there usually is an object oriented solution that works just as well, or simetimes even better.

          --- single minded; short sighted; long gone;

          B Offline
          B Offline
          Blumen
          wrote on last edited by
          #4

          Can't we achieve this using CodeDOM?

          G 1 Reply Last reply
          0
          • B Blumen

            Can't we achieve this using CodeDOM?

            G Offline
            G Offline
            Guffa
            wrote on last edited by
            #5

            No. You can use CodeDom to create source code, which you can compile if you want, but that can only be used to create a new assembly, you can't change an existing class at runtime.

            --- single minded; short sighted; long gone;

            1 Reply Last reply
            0
            • N nasambur

              hi, is it possible to add a member variable/function to a class at runtime.. This is possible in Python.. regards, nas

              G Offline
              G Offline
              Giorgi Dalakishvili
              wrote on last edited by
              #6

              Have a look at http://www.codeproject.com/cs/library/typebuilderlib.asp You might find it interesting :)

              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