Class

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

I have the following code line:

a = MyClass.PropertyA

Is it possible to do something as follows?

a = MyClass.(b)

where b is "PropertyA"

Thanks,
Miguel
 
see the reflection namespace.

Object a = MyClass.GetType().GetProperty(b).GetValue(MyClass,null);

-- bruce (sqlwork.com)
 
shapper said:
Hello,

I have the following code line:

a = MyClass.PropertyA

Is it possible to do something as follows?

a = MyClass.(b)

where b is "PropertyA"

Thanks,
Miguel

It can be done using reflection. However it's generally a bad idea to
mix code and data.

What is it that you are trying to do, really?
 
Absolutely!

--http://www.markrae.net

Hi,

This is very simple. I have a class with many properties which are of
type collection.
This class also have a function that finds an element in one of those
collections.

The inputs of the function are the name of the property to be used and
the name of the element inside it.
So instead of having a Select Case with many cases I just get one of
the properties using the selected code.

It is working fine. Any problem in using this this way?

Thanks,
Miguel
 
Absolutely!

--http://www.markrae.net

Hi,

This is very simple. I have a class with many properties which are of
type collection.
This class also have a function that finds an element in one of those
collections.

The inputs of the function are the name of the property to be used and
the name of the element inside it.
So instead of having a Select Case with many cases I just get one of
the properties using the selected code.
---------
(I don't know why I can't get this message to quote properly!)

If these properties are all the same kind of collection, then perhaps rather
than a class with properties which are collections, you really have a class
with one property which is a collection of collections.
 
shapper said:
Hi,

This is very simple. I have a class with many properties which are of
type collection.
This class also have a function that finds an element in one of those
collections.

The inputs of the function are the name of the property to be used and
the name of the element inside it.
So instead of having a Select Case with many cases I just get one of
the properties using the selected code.

It is working fine. Any problem in using this this way?

If you just want simple, it works.

If you want performance, a switch is your best bet.

If you want robust code, an enum instead of a string as identifier is
better. It also performs slightly better.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Class question 6
Use of class function 2
String and Class 3
Generic.List 2
Dataset to Generic.List(Of MyClass) 4
Multi-lined appsettings value in web config 11
Generic.List 1
Use variable in two classes 3

Back
Top