How to load class file dynamically in C# .Net
-
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
-
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
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 :)
-
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 :)
-
I am loading the source file not the assembly file. In this case how can i get the class properties and fields??
Thankfully, jm
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.
-
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
-
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;
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, jmThankfully, jm
-
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;
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 -
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, jmThankfully, jm
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;
-
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
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.