Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Class Creation

Status
Not open for further replies.

arunglobal

Programmer
Sep 8, 2003
40
IN
Hi Guys,

I just want to create Class , attributes , methods, properties,assignments statements etc... DYNAMICALLY
(i.e Execution time)

Any Idea......

Thanks in Advance
 
I can't understand why. What are you trying to accomplish?
 
Thank for ur Rapid Reply.

I just want to create Data Object Class to Hold Record Through Properties.

No. of Methods and Names of the Methods wll be Known only @ runtime.

Hence Dynamic Class creation is Required.
 
Append up a StringBuilder that looks like a class (contains methods, properties, etc). You can then use the VBCodeProvider class from the Microsoft.VisualBasic namespace to create an instance of an ICodeCompiler object, on which you can then call CompileAssemblyFromSource().

You could also use the CodeDOM to build your class instead of using a StringBuilder, which is more technically elegant, but the CodeDOM is incomplete (missing the Xor operator, for example). Whidbey should flesh it out some, but I get the impression it's not a priority for Microsoft to make it 100% complete. Once you have a CodeDOM tree, you then call CompileAssemblyFromDom().

One good thing about using the CodeDOM, is that you can generate C# code by using the Microsoft.CSharp namespace and the CSharpCodeProvider class. Same applies for J# (change the namespace & class). Everything else about your code generation stays the same!

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top