partial class

  • Thread starter Thread starter George Meng
  • Start date Start date
G

George Meng

Is there a way to build partial class on the fly, the partial class then
extend the class which is already complied?

For example: I have a class

public class TheClass
......
End Class

Then at the runtime, I generate the partial class:

partial public class TheClass
......
End Class

And let the two class work together?

George
 
George Meng said:
Is there a way to build partial class on the fly, the partial class then
extend the class which is already complied?

Note that the parts of partial classes must reside in the same assembly.
 
George,

VBNet is no scripting.

A class is a description of a type,
which as used as object will be build as an Exe containing ILS code.

Therefore it has no sense to do this at runtime.

Cor
 
George,
Fortunately you cannot! As Herfried states, partial classes need to be
within the same assembly & an assembly needs to be compiled all at once.

The "best" you can do is inherit from TheClass "on the fly" to extend it

You can use either the System.CodeDom namespace or the
System.Reflection.Emit namespaces to generate executables "on the fly".
Generally I favor System.CodeDom over System.Reflection.Emit.

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| Is there a way to build partial class on the fly, the partial class then
| extend the class which is already complied?
|
| For example: I have a class
|
| public class TheClass
| ......
| End Class
|
| Then at the runtime, I generate the partial class:
|
| partial public class TheClass
| ......
| End Class
|
| And let the two class work together?
|
| George
|
|
 
Back
Top