473,388 Members | 1,177 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Create a Class at runtime for use with PropertyGrid

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.
Nov 21 '05 #1
1 4548
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.
Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
2
by: Steve Teeples | last post by:
How does one go about creating an enum at runtime from an array of strings? -- Steve
11
by: Özden Irmak | last post by:
Hello, In my VB.Net application I create a new instance of my form like : NewForm = new MyNewForm() But with this line, this new form is automatically shown. I want it to be hidden at the...
7
by: MarkoH | last post by:
Wsdl.exe /server creates abstract class derived from WebService. Is there a way to create this class at runtime based on some WSDL file given at runtime ? What would be even better - creating...
0
by: Hans Koller | last post by:
Hello group, I design a class to bind it to a property grid for easy modification of some settings. My problem is now that I want to raise an event when a settings has been changed. Thats not a...
2
by: =?Utf-8?B?TWF1cmljZU0=?= | last post by:
Hi all, how can I hide a property in a derived class in a propertygrid. Let's say I have a classX and a derived classY. A property in classX will be visible in the propertygrid but the same...
2
by: =?Utf-8?B?TWF1cmljZU0=?= | last post by:
Hi there, is it possible to disable a property in the propertygrid at runtime? Normally a property will be enabled but if i.e. the user doesn't have access to change the property this property...
4
by: =?Utf-8?B?bGpsZXZlbmQy?= | last post by:
Is there any way to create an instance of the control that is used by System.Drawing.Design.ColorEditor (i.e., the control that appears when you click on a color in a PropertyGrid)? I want to...
0
by: ntabb | last post by:
Hello all, I have a class instance that I'm attaching to a propertygrid. I would like to find a way to change the "Browsable" attribute during runtime or programmatically from outside the class...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.