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. How to load class file dynamically in C# .Net

How to load class file dynamically in C# .Net

Scheduled Pinned Locked Moved C#
csharptutorialquestion
9 Posts 4 Posters 2 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.
  • J Offline
    J Offline
    jmavn
    wrote on last edited by
    #1

    Hi, I have one class file that is stored in one of the subfolders in the Application. I need to load a class file dynamically and get the details (Properties and Fields) of the class. (i.e.) Employee.cs file is stored inside one of the subfolder. Using programatically at runtime i need to load that class file and read the information about that class file using Reflection. Is it possible to do this? If so in what way can i do? Can anyone pls reply me? I am in urgent need.. Expecting your reply..:)

    Thankfully, jm

    G G M 3 Replies Last reply
    0
    • J jmavn

      Hi, I have one class file that is stored in one of the subfolders in the Application. I need to load a class file dynamically and get the details (Properties and Fields) of the class. (i.e.) Employee.cs file is stored inside one of the subfolder. Using programatically at runtime i need to load that class file and read the information about that class file using Reflection. Is it possible to do this? If so in what way can i do? Can anyone pls reply me? I am in urgent need.. Expecting your reply..:)

      Thankfully, jm

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

      Are you loading source code file or the assembly file? If it is assembly than you can use reflection. As for source file you can compile it dynamically during runtime and then use the above method. I don't know if there is any other way with source file :)

      J 1 Reply Last reply
      0
      • G Giorgi Dalakishvili

        Are you loading source code file or the assembly file? If it is assembly than you can use reflection. As for source file you can compile it dynamically during runtime and then use the above method. I don't know if there is any other way with source file :)

        J Offline
        J Offline
        jmavn
        wrote on last edited by
        #3

        I am loading the source file not the assembly file. In this case how can i get the class properties and fields??

        Thankfully, jm

        G 1 Reply Last reply
        0
        • J jmavn

          I am loading the source file not the assembly file. In this case how can i get the class properties and fields??

          Thankfully, jm

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

          In that case as I have said you can compile it during runtime dynamically and then use reflection. I can't think of any other way.

          1 Reply Last reply
          0
          • J jmavn

            Hi, I have one class file that is stored in one of the subfolders in the Application. I need to load a class file dynamically and get the details (Properties and Fields) of the class. (i.e.) Employee.cs file is stored inside one of the subfolder. Using programatically at runtime i need to load that class file and read the information about that class file using Reflection. Is it possible to do this? If so in what way can i do? Can anyone pls reply me? I am in urgent need.. Expecting your reply..:)

            Thankfully, jm

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

            As Giorgio said, you can compile the source and use reflection to inspect it. I'm not sure that's the solution that you really need, though. What is it that you are trying to accomplish, really?

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

            J 2 Replies Last reply
            0
            • G Guffa

              As Giorgio said, you can compile the source and use reflection to inspect it. I'm not sure that's the solution that you really need, though. What is it that you are trying to accomplish, really?

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

              J Offline
              J Offline
              jmavn
              wrote on last edited by
              #6

              Hi, Why i am in need of this is i need to generate an XML by reading the properties from a Class file (in any language C#, VB.Net..etc).. for that i have to know the properties defined in those class files and based on the properties and datatype of those properties i need to generate a dynamic XML files example If a class file is something as public Class A { private int number; private string name; public int Number { get {return number;} set {number = value;} } public string Name { get {return name;} set {name = value;} } } based the above shown class, i have to generate by getting the properties of the class Like this i have to generate XML file.. For this i need to get the reflection of class, isnt it? Is any other way available to get the properties declared in a class file? Expecting your reply. Thankfully, jm

              Thankfully, jm

              G 1 Reply Last reply
              0
              • G Guffa

                As Giorgio said, you can compile the source and use reflection to inspect it. I'm not sure that's the solution that you really need, though. What is it that you are trying to accomplish, really?

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

                J Offline
                J Offline
                jmavn
                wrote on last edited by
                #7

                Hi, Why i am in need of this is i need to generate an XML by reading the properties from a Class file (in any language C#, VB.Net..etc).. for that i have to know the properties defined in those class files and based on the properties and datatype of those properties i need to generate a dynamic XML files example If a class file is something as public Class A { private int number; private string name; public int Number { get {return number;} set {number = value;} } public string Name { get {return name;} set {name = value;} } } based the above shown class, i have to generate by getting the properties of the class Like this i have to generate XML file.. For this i need to get the reflection of class, isnt it? Is any other way available to get the properties declared in a class file? Expecting your reply. Thankfully, jm Thankfully, jm Thankfully, jm

                1 Reply Last reply
                0
                • J jmavn

                  Hi, Why i am in need of this is i need to generate an XML by reading the properties from a Class file (in any language C#, VB.Net..etc).. for that i have to know the properties defined in those class files and based on the properties and datatype of those properties i need to generate a dynamic XML files example If a class file is something as public Class A { private int number; private string name; public int Number { get {return number;} set {number = value;} } public string Name { get {return name;} set {name = value;} } } based the above shown class, i have to generate by getting the properties of the class Like this i have to generate XML file.. For this i need to get the reflection of class, isnt it? Is any other way available to get the properties declared in a class file? Expecting your reply. Thankfully, jm

                  Thankfully, jm

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

                  It really sounds like you are trying to reinvent the wheel... Visual Studio can create XML documentation when you compile the code. Just enable "XML Documentation" in the build options for the project. If you want this for documentation, you can add xml comments in the code, which will be included in the xml file, from which you then can create complete documentation in several different formats usings Sandcastle. The xml files created are also used in intellisense, so when using the class you will see the comments about the members in the intellisense just as with the classes in the framework. Visual Studio even helps you create the comments; just type /// on the line before a member (''' in VB), and it will provide you with a template for the comments. Example:

                  /// <summary>
                  /// Gets some information about something.
                  /// </summary>
                  /// <param name="index">The index of the informtion piece to get.</param>
                  /// <returns>Returns a string containing the specified information text.</returns>
                  public string GetInfo(int index) {
                  return _someInfo[index];
                  }

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

                  1 Reply Last reply
                  0
                  • J jmavn

                    Hi, I have one class file that is stored in one of the subfolders in the Application. I need to load a class file dynamically and get the details (Properties and Fields) of the class. (i.e.) Employee.cs file is stored inside one of the subfolder. Using programatically at runtime i need to load that class file and read the information about that class file using Reflection. Is it possible to do this? If so in what way can i do? Can anyone pls reply me? I am in urgent need.. Expecting your reply..:)

                    Thankfully, jm

                    M Offline
                    M Offline
                    mike montagne
                    wrote on last edited by
                    #9

                    I think you may have a conceptual problem. The assembly loads the class whenever you have an instance of the class or call into the class. At that time, you can reflect the class; but if you wrote the class you should be able to indicate anything about it by even more straightforward processes. Nonetheless, you don't load the file to reflect on the object: You reflect (usually) an instance of the object or a type object representing the class.

                    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