Here is an interesting idea and it must be possible.
I have a project with 1 windows form, nothing on it.
I have a DLL with various code bits in it including a custom form.
The declaration of the form in app 1 would be: Public Class TestForm : Form nothing weird about that. The declaration for the form in the dll would be Public Class CustomForm : Form again nothing weird about that.
I include this dll into my project to be able to have the 'TestForm' inherit from 'CustomForm' however i only want to do this when the app is compiled. So during design time, 'TestForm' inherits from 'Form', then when the project is built i would like to replace the inheritance before it goes to the compiler but without altering the source code.
This must be already be done somewhere but i am unable to find any examples of this probably due to the fact that i do not know the correct terminoligy for this.
Can anyone help?
Cheers
Loading
Sam HobbsPosted Dec 4, 2009, 2:02 PM
Sam HobbsPosted Dec 4, 2009, 1:17 PM
All your forms will derive from Form and I think that is nearly all you must do. In your program, create an instance of the Form class and during execution you can set that item to any object that derives from the Form class. You might need to create a base class derived from the Form class to derive from instead of the Form class directly.
Do you understand?
Giles PapworthPosted Dec 4, 2009, 3:56 AM
Public Partial Class MyForm : System.Windows.Forms.Form
{
.....[form code]
}
If i were to have a skinning DLL in the project, before the code is sent to the compiler i would want it to look like this:
Public Partial Class MyForm : SkinningDLL.SkinnedForm
{
.....[form code]
}
So the first set of code is my actual source. The DLL would catch the source before it is sent to the compiler and change it to what i have above. The reason for this is so that the custom form inside my dll would be used to inherit from instead of 'System.Windows.Forms.Form. This is to enable skinning.
At the moment in my app i have the form inheriting from my skinned form but i was wondering if there was anyway i could do this on the fly? I know you cannot change an objects inheritance at runtime so i was wondering if i would be able to change what is sent to the compiler before it is compiled without changing the actual source code.
I know you can do this by creating a custom MSBUILD task however this will not run in my project (or at least i cannt get it to run)
That was what i was trying to achieve.
theLizardPosted Dec 3, 2009, 4:37 PM
Sam HobbsPosted Dec 3, 2009, 1:08 PM
A definition defines what an object is. It is the source code with the names and the data types. A declaration uses the definiton as a type and reserves storage for an instance of the object. In your question you say declaration when I think you mean definition.
I am sorry I don't understand the rest of the question, especially the part "replace the inheritance before it goes to the compiler". If nothing else, I think it is not clear what is to be replaced with what and what is the criteria for determining what the replacement needs to be.