Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / June 2007

Tip: Looking for answers? Try searching our database.

Class

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
shapper - 22 Jun 2007 23:16 GMT
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
bruce barker - 23 Jun 2007 00:06 GMT
see the reflection namespace.

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

-- bruce (sqlwork.com)

> Hello,
>
[quoted text clipped - 10 lines]
> Thanks,
> Miguel
Göran Andersson - 23 Jun 2007 11:26 GMT
> Hello,
>
[quoted text clipped - 10 lines]
> 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?

Signature

Göran Andersson
_____
http://www.guffa.com

Mark Rae - 23 Jun 2007 11:44 GMT
> However it's generally a bad idea to mix code and data.

Absolutely!

Signature

http://www.markrae.net

shapper - 23 Jun 2007 12:33 GMT
> "G?ran Andersson" <g...@guffa.com> wrote in message
>
[quoted text clipped - 5 lines]
>
> --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
John Saunders [MVP] - 23 Jun 2007 16:32 GMT
On Jun 23, 11:44 am, "Mark Rae" <m...@markNOSPAMrae.net> wrote:
> "Göran Andersson" <g...@guffa.com> wrote in message
>
[quoted text clipped - 5 lines]
>
> --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.
Signature

John Saunders [MVP]

Göran Andersson - 23 Jun 2007 18:52 GMT
>>> However it's generally a bad idea to mix code and data.
>> Absolutely!
[quoted text clipped - 14 lines]
>
> 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.

Signature

Göran Andersson
_____
http://www.guffa.com


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.