PC Review


Reply
Thread Tools Rate Thread

Create a Class at runtime for use with PropertyGrid

 
 
Chris Dunaway
Guest
Posts: n/a
 
      5th Aug 2004
I have a legacy application that I need to build a Windows Forms
application to interface with it. The legacy application keeps its
configuration information in INI style files.

I wish to use a PropertyGrid on the form to allow the user to adjust the
configuration of the legacy app. The problem I am facing, however, is that
the legacy app can still be changed and new configuration items can be
added/removed from the configuration files of the legacy app.

I would normally just create a class with all the properties of the INI
file but since the INI file might change, I need to be able to dynamically
change that class without having to rebuild the app each time.

I want to read the INI file and dynamically build a class with a property
for each item. I think I'll have a xml file that contains information
about the parameters in the INI file along with their types (integer,
boolean, etc.). When the INI is updated, then the xml file can be updated
to reflect any changes. The Windows app would not need to change.

I am stuck on creating and instanciating the class at runtime.

Any assistance is appreciated.


--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 
Reply With Quote
 
 
 
 
Chris Dunaway
Guest
Posts: n/a
 
      5th Aug 2004
On Thu, 5 Aug 2004 16:11:26 -0500, Chris Dunaway wrote:

>
> I am stuck on creating and instanciating the class at runtime.
>


In answer to my own question, I offer the following code. The form has a
TextBox, a button, and a PropertyGrid, all with their default names. Run
the program and type the following code in the textbox:

Class Test
Private _MyProp As Integer

Public Property MyProp() As Integer
Get
Return _MyProp
End Get
Set(ByVal Value As Integer)
_MyProp = Value
End Set
End Property
End Class


'*** CODE BEGINS
Private Sub Button1_Click(...) Handles Button1.Click

Dim VB As New VBCodeProvider
Dim obj As Object

Dim Compiler As ICodeCompiler = VB.CreateCompiler()
Dim cParams As New CompilerParameters

cParams.GenerateExecutable = False
cParams.GenerateInMemory = True
cParams.IncludeDebugInformation = False

Dim cResults As CompilerResults
cResults = Compiler.CompileAssemblyFromSource(cParams, TextBox1.Text)

If cResults.Errors.Count = 0 Then
Dim assyResult As [Assembly] = cResults.CompiledAssembly
Dim aType As Type

aType = assyResult.GetType("Test")

obj = assyResult.CreateInstance(aType.FullName)
PropertyGrid1.SelectedObject = obj
PropertyGrid1.Refresh()
End If

VB.Dispose()

End Sub
'*** CODE ENDS


--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Propertygrid disable item at runtime =?Utf-8?B?TWF1cmljZU0=?= Microsoft Dot NET 2 21st May 2007 09:41 AM
PropertyGrid-adding properties at runtime FUnky Microsoft Dot NET Framework Forms 2 22nd Mar 2006 02:23 PM
Create Class at Runtime? xenophon Microsoft Dot NET Framework 2 5th Aug 2005 10:27 AM
Create Class at Runtime? xenophon Microsoft Dot NET Framework 1 4th Aug 2005 11:02 PM
Showing verbs in a PropertyGrid at runtime Ian Ringrose Microsoft Dot NET Framework Forms 1 27th Feb 2005 02:28 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:36 AM.