473,466 Members | 1,436 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Dynamically calling classes and properties

I have several different classes that contain the same four
properties. I tell my application property of which class to call in
the configuration file.

Here are the values from my config file

<class>AAAA</class>
<property>1111</property>
This is how I current have it working.

Dim sql As String = ""
Select Case classVariable
Case "AAAA"
Dim extract As New AAAA
Select Case propertyVariable
Case "1111"
sql = extract.1111
Case "2222"
sql = extract.2222
Case "3333"
sql = extract.3333
Case "4444"
sql = extract.4444
Case Else
'quit function
End Select
Case "BBBB"
Dim extract As New BBBB
Select Case propertyVariable
Case "1111"
sql = extract.1111
Case "2222"
sql = extract.2222
Case "3333"
sql = extract.3333
Case "4444"
sql = extract.4444
Case Else
'quit function
End Select
Case "CCCC"
Dim extract As New CCCC
Select Case propertyVariable
Case "1111"
sql = extract.1111
Case "2222"
sql = extract.2222
Case "3333"
sql = extract.3333
Case "4444"
sql = extract.4444
Case Else
'quit function
End Select
End Select

Is there a was to call these classes and properties dynamically with
variable from my config file.
Something that looks like this? I don't want to have to add another
case and select case for every new class.

Dim extract as new [classVariable]
Sql = extract.[propertyVariable]

Thanks in advance,
Will

Mar 21 '07 #1
4 1209
VJ
you need to use Reflection... so you can use a string to convert it to
object i.e class

VJ

<wi********@gmail.comwrote in message
news:11**********************@o5g2000hsb.googlegro ups.com...
>I have several different classes that contain the same four
properties. I tell my application property of which class to call in
the configuration file.

Here are the values from my config file

<class>AAAA</class>
<property>1111</property>
This is how I current have it working.

Dim sql As String = ""
Select Case classVariable
Case "AAAA"
Dim extract As New AAAA
Select Case propertyVariable
Case "1111"
sql = extract.1111
Case "2222"
sql = extract.2222
Case "3333"
sql = extract.3333
Case "4444"
sql = extract.4444
Case Else
'quit function
End Select
Case "BBBB"
Dim extract As New BBBB
Select Case propertyVariable
Case "1111"
sql = extract.1111
Case "2222"
sql = extract.2222
Case "3333"
sql = extract.3333
Case "4444"
sql = extract.4444
Case Else
'quit function
End Select
Case "CCCC"
Dim extract As New CCCC
Select Case propertyVariable
Case "1111"
sql = extract.1111
Case "2222"
sql = extract.2222
Case "3333"
sql = extract.3333
Case "4444"
sql = extract.4444
Case Else
'quit function
End Select
End Select

Is there a was to call these classes and properties dynamically with
variable from my config file.
Something that looks like this? I don't want to have to add another
case and select case for every new class.

Dim extract as new [classVariable]
Sql = extract.[propertyVariable]

Thanks in advance,
Will

Mar 21 '07 #2

<wi********@gmail.comwrote in message
news:11**********************@o5g2000hsb.googlegro ups.com...
>I have several different classes that contain the same four
properties. I tell my application property of which class to call in
the configuration file.

Here are the values from my config file

<class>AAAA</class>
<property>1111</property>
This is how I current have it working.

Dim sql As String = ""
Select Case classVariable
Case "AAAA"
Dim extract As New AAAA
Select Case propertyVariable
Case "1111"
sql = extract.1111
Case "2222"
sql = extract.2222
Case "3333"
sql = extract.3333
Case "4444"
sql = extract.4444
Case Else
'quit function
End Select
Case "BBBB"
Dim extract As New BBBB
Select Case propertyVariable
Case "1111"
sql = extract.1111
Case "2222"
sql = extract.2222
Case "3333"
sql = extract.3333
Case "4444"
sql = extract.4444
Case Else
'quit function
End Select
Case "CCCC"
Dim extract As New CCCC
Select Case propertyVariable
Case "1111"
sql = extract.1111
Case "2222"
sql = extract.2222
Case "3333"
sql = extract.3333
Case "4444"
sql = extract.4444
Case Else
'quit function
End Select
End Select

Is there a was to call these classes and properties dynamically with
variable from my config file.
Something that looks like this? I don't want to have to add another
case and select case for every new class.

Dim extract as new [classVariable]
Sql = extract.[propertyVariable]

Thanks in advance,
Will
Can I make a suggestion.

Since your classes have the same 4 methods you can either create a base
class with those methods and then create your objects inheriting from the
base class. Then you would create base class variable which would hold the
object and the methods called would the same. It would get rid of alot of
your code and make the classes easier to understand.

An alternative is to create an interface with those 4 methods and have each
class "Implement" the interface. Again you can create a variable (this time
of type interface) and do your method according to the select statement.

I sure hope that is not production code since it will be unmaintainable in
its present form.

Lloyd Sheen

Mar 21 '07 #3
<wi********@gmail.comschrieb:
>I have several different classes that contain the same four
properties. I tell my application property of which class to call in
the configuration file.

Here are the values from my config file

<class>AAAA</class>
<property>1111</property>
Take a look at 'Activator.CreateInstance' and the members of the
'System.Type' class. The latter can be used to call a method on the object
created by 'CreateInstance'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Mar 22 '07 #4
What is it that you are using this for?

I suspect that, as in most cases when someone asks for dynamic
variables, it can be solved in a different way.

wi********@gmail.com wrote:
I have several different classes that contain the same four
properties. I tell my application property of which class to call in
the configuration file.

Here are the values from my config file

<class>AAAA</class>
<property>1111</property>
This is how I current have it working.

Dim sql As String = ""
Select Case classVariable
Case "AAAA"
Dim extract As New AAAA
Select Case propertyVariable
Case "1111"
sql = extract.1111
Case "2222"
sql = extract.2222
Case "3333"
sql = extract.3333
Case "4444"
sql = extract.4444
Case Else
'quit function
End Select
Case "BBBB"
Dim extract As New BBBB
Select Case propertyVariable
Case "1111"
sql = extract.1111
Case "2222"
sql = extract.2222
Case "3333"
sql = extract.3333
Case "4444"
sql = extract.4444
Case Else
'quit function
End Select
Case "CCCC"
Dim extract As New CCCC
Select Case propertyVariable
Case "1111"
sql = extract.1111
Case "2222"
sql = extract.2222
Case "3333"
sql = extract.3333
Case "4444"
sql = extract.4444
Case Else
'quit function
End Select
End Select

Is there a was to call these classes and properties dynamically with
variable from my config file.
Something that looks like this? I don't want to have to add another
case and select case for every new class.

Dim extract as new [classVariable]
Sql = extract.[propertyVariable]

Thanks in advance,
Will

--
Göran Andersson
_____
http://www.guffa.com
Mar 22 '07 #5

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

Similar topics

8
by: Mark English | last post by:
I'd like to write a Tkinter app which, given a class, pops up a window(s) with fields for each "attribute" of that class. The user could enter values for the attributes and on closing the window...
7
by: Rathtap | last post by:
I want to write a C# application (lets call it Generator) that will receive an argument(patient account number) and dynamically generate a series of linked HTML files (claim information, payments,...
5
by: Brett Kelly | last post by:
Sorry, for the somewhat confusing subject, but my problem is equally odd (imo). So, I have an assembly that contains an abstract class (File) and 5 other classes that all subclass it (Exe, Dll,...
1
by: Josh | last post by:
Hi Guys, I have been having a big problem with trying to pass parameters into a user control when the user control is dynamically loaded into a placholder. I am developing in c#. I have get...
1
by: Jeff Smith | last post by:
Can I load custom web user controls dynamically and access the properties and methods without having to explicitly define custom control types (example 2 below). I have custom web control named...
2
by: Mark | last post by:
Hi there, I'm trying to create a function to dynamically set a property from a class. The idea is to get a general function that works for every class. Although this function works for classes i...
5
by: kmcmanus | last post by:
I have just started to write a few business classes that are largely made up of properties (getters and setters). For each setter I want to fire a changed event - each event will have a unique...
3
by: rn5a | last post by:
A SqlDataReader is populated with the records from a SQL Server 2005 DB table. The records retrieved depends upon 2 conditions (the conditions depend on what a user selects in an ASPX page). If...
2
by: Nathan Sokalski | last post by:
There are many situations in which we want to assign certain styles with multiple CSS properties to a control, quite often the same ones for multiple controls. Sometimes these styles must be...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.