Getting properties of class

Posted by jmls on 18-Jan-2009 05:32

Is there any way to iterate through the properties of a class and retrieve the name, type and default value of each property ?

How does the OEA do this ?

All Replies

Posted by Admin on 18-Jan-2009 05:36

Not in the same way as for procedures. You can get something out of the XREF. That's what we use for generating documentation (together with method comments).

My assumption is, that OEA parses the source code (AST) - at least to build the outline view.

Posted by Thomas Mercer-Hursh on 18-Jan-2009 11:56

Doing it in code is probably going to have to wait for enhanced reflection (is that anything like polishing the mirror?). Of course, you could use the proparse.jar ...

Posted by jmls on 16-Mar-2010 15:26

Is this now possible in 10.2B ??

Posted by Admin on 16-Mar-2010 15:29

Not any better than in previous releases.

Posted by jmls on 16-Mar-2010 15:31

Well, ain't that a pile of poo.

Posted by Peter Judge on 16-Mar-2010 15:34

Unfortunately not.

-- peter

Posted by Thomas Mercer-Hursh on 16-Mar-2010 15:49

Consider it a safety precaution to keep you from doing reflection and dynamic programming.

Posted by Peter Judge on 16-Mar-2010 15:54

Consider it a safety precaution to keep you from doing reflection and

dynamic programming.

That's too funny: no dynamic programming in the (our) 4GL? Um, yeah, OK.

-- peter

Posted by Thomas Mercer-Hursh on 16-Mar-2010 16:12

It has its place, but is heavily abused, especially in terms of dynamic calls that make it impossible to create a callgraph for an application.  Clearly, dynamic queries are essential for some things and there is a place for some other things in frameworks, but I think too many people reach for it all too quickly and produce unreadable, unanalyzable code.

Posted by jmls on 16-Mar-2010 16:24

I am trying to create a enum-type class where the valid values of the

class can be loaded into a combo-box or selection list . I can do this

by creating a method that adds all the property names into a string

but wanted to do it automatically.

Julian

On 16 March 2010 21:13, Thomas Mercer-Hursh

Posted by Thomas Mercer-Hursh on 16-Mar-2010 16:34

So, this is internal to the class, not something accessible from outside?

You really should look into code generators.  That would make this sort of thing automatic without requiring any dynamic features.

I'm not sure what I think about each enum value being its own property.

Posted by jmls on 16-Mar-2010 16:44

>>So, this is internal to the class, not something accessible from outside

Yes. It should be a single property that returns all possible values

of the "enum"

>>You really should look into code generators.

I was

>> I'm not sure what I think about each enum value being its own property.

This ensures that if you refer to this value anywhere in code it is a

valid value. I've been bitten many tomes my mispellign a value (e.g.

">Actoin" instead of ">Action"). Having Event:Action instead means

that it won't compile if I misspell or mistype. I used to use

preprocessors for this purpose.

Julian

On 16 March 2010 21:34, Thomas Mercer-Hursh

Posted by Admin on 16-Mar-2010 16:44

I'm not sure what I think about each enum value being its own property.

What else (given the out of the box capabilities of 10.2B)?

Posted by Thomas Mercer-Hursh on 16-Mar-2010 17:00

Admittedly, I haven't thought a lot about this yet, but I suppose I was thinking of something more like IsValid(test value) and ToString(sample value) working against a list rather than each value being its own property.  I suppose that exposing it as a property means that you can do a type-safe assignment which is a plus, but if you have a possible value which has not been verified, it seems like you need something like IsValid() to test it.  Are you doing both?

In any case, I would rather solve it with a generator than dynamic code.

Posted by Admin on 16-Mar-2010 17:04

Are you doing both?

 

Yes.

In any case, I would rather solve it with a generator than dynamic code.

Seems like overkill to me. Most enums have a hand full of values.

Posted by jmls on 16-Mar-2010 17:14

I agree, a generator is the way to do this. At the moment, I don't

allow free-form entry of values that are part of an enum, so access is

only by combo-box / selection list etc so the user can only choose a

valid value .

Julian

On 16 March 2010 22:00, Thomas Mercer-Hursh

Posted by Thomas Mercer-Hursh on 16-Mar-2010 17:18

Admittedly not a major labor saver, but it certainly takes less time to provide the list of values and press a button than it does to type all the options.

Posted by Thomas Mercer-Hursh on 16-Mar-2010 17:21

Depends on your level of trust.

I.e,

MyClass:EnumProperty = MyEnum.SomeValue

is very safe, but

MyClass.EnumProperty = something from a combo box which I am presuming was populated with the possible enum values

is less safe.

Posted by jmls on 16-Mar-2010 17:24

True. That's why there is a validator method.

Julian

On 16 March 2010 22:21, Thomas Mercer-Hursh

This thread is closed