[dba-VB] Iterating class properties

Eric Barro ebarro at verizon.net
Tue Nov 13 12:53:26 CST 2007


.NET handles this well Drew.

In VB

Dim wd as Widget = New Widget()

Wd.Height = 10

In C#

Widet wd = new Widget();

Wd.Height = 10;

-----Original Message-----
From: dba-vb-bounces at databaseadvisors.com
[mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Drew Wutka
Sent: Tuesday, November 13, 2007 8:55 AM
To: dba-vb at databaseadvisors.com
Subject: Re: [dba-VB] Iterating class properties

What are you trying to accomplish?  I don't use .Net very often, still do
most of my stuff in VB 6.  But I wanted a way to dynamically capture my
class properties.

For example, let's say I had Widget, and it had Height and Width properties.
I wanted to be able to do this:

Dim wd as Widget
Set wd=new Widget
Wd.Properties("Height")=10

Or

Dim wd as Widget
Dim I as long
Set wd=new Widget
For i=1 to wd.Properties.Count
	Wd.Properties(i)=15
Next i

I don't know if .Net has this capability, VB 6 didn't natively, but I was
able to 'spoof' the ability.  I created an Add-in that let's me create a
Properties property for a class.  When you run the Add-in, it goes through
all of the properties in your class, and creates statements to simulate the
abilities above.  It's adding a lot of extra code to do this, but in some
situations I have run into, it's worth it...plus, all the properties are
left alone, so I can use them like I normally would.

Drew

-----Original Message-----
From: dba-vb-bounces at databaseadvisors.com
[mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby
Sent: Tuesday, November 13, 2007 6:43 AM
To: dba-vb at databaseadvisors.com
Subject: [dba-VB] Iterating class properties

Does anyone know a way to iterate the properties of a class in VB.Net or
C#.Net (or in .Net in general)?  There is built-in functionality to store
classes out to XML files and this stuff does exactly that, apparently using
only the Get/Let statements, i.e. if there is not both a get and let
statement for a property then the process fails to convert that property to
XML.  

So if MS does it, is that capability publicly available?  Is there a
property iterator buried in the innards of the class object?

John W. Colby
Colby Consulting
www.ColbyConsulting.com 

_______________________________________________

 




More information about the dba-VB mailing list