is it possible to get delegates from properties directly?

  • Thread starter Thread starter PJ6
  • Start date Start date
P

PJ6

I would like to refer to properties in code without having to resort to
using a string for the name. AddessOf gives me this ability for methods, but
I can't find a single way to point that at the Get or Set methods of
properties directly.

Why don't I want to use a string? Well, I want to know at design time that
my property references aren't broken, much the same way I can have this when
using regular delegates.

Is this possible?

Paul
 
Unfortunately that has nothing to do with getting at the Set and Get methods
in a Property without first having to get the ProperyInfo with a string
representing its name...

Or am I not understanding how to apply that information to my question?

Thanks,
Paul
 
Paul,

Are you sure that VBNet is the right program language for you.

Using addresspointers to references is maybe for some a nice way of
programming, it is in my idea a litle bit out of sense to base your complete
system on it. Like an API it is a nice way to escape as nothing seems to be
more possible, to use in general is in my idea a little bit crazy.

What you see is that where it is needed, that need is often eliminiated in
the next version.

Is C++ not a better language for you?

Cor
 
Cor,

The reason for my desire to get pointers from property methods without using
strings is simple, and that is the holding to the principle of code
normalization. In my grid, when I want to point a column to a property in
code, I don't want to have to write out the property name with a string such
as "SomeProperty". This is wrong because there is no design-time
verification that the string is correct, and if I manage to change the
property name later, or I've misspelled it, I will have no idea that
something is broken until something fails at runtime. Put more simply, I
want design-time validation of property references. Why do you think that's
crazy?

What surprises me is that I apparently cannot generate a pointer to the
property Set and Get methods the same way I can for normal methods. For
normal methods, this isn't an issue at all, I don't need to spell the method
name out in a string to get at it for use as a delegate.

Yes. Apparently this is currently a deficiency in the Framework since no one
has chimed in to say otherwise. But I'm not going to throw my hands up in
the air and compromise my design or move to C just because I run into a
limitation like this; I will look for a way around it.

Paul
 
Paul,

I am not sure if this is the answer, however you can inherit almost every
class. In that way you can make it strongly typed.

Have a look at the generated strongly typed datasource in 2005 or the
generated strongly typed dataset in previous versions as it is generated.

Cor
 
PJ6,
Unfortunately AddressOf only works on Subs & Functions not properties.

As Cor suggests, I too wonder what specifically you are doing that requires
the use of the underlying delegates.

If your design truely needs the delegates & using a string to retrieve them
is undesirable. Have you considered a design that uses a Get function & a
Set sub instead?

In other words, instead of:

Public Property Name As String
...

Use:

Public Function GetName() As String
...

Public Sub SetName(value As String)
...

Alternatively I would consider a design that each "property" was actually an
object instead, then instead of relying on delegates to the "properties"
method, I would use simply pass the "property" object instead. I would
consider using Generics to define the "property" object...

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


|I would like to refer to properties in code without having to resort to
| using a string for the name. AddessOf gives me this ability for methods,
but
| I can't find a single way to point that at the Get or Set methods of
| properties directly.
|
| Why don't I want to use a string? Well, I want to know at design time that
| my property references aren't broken, much the same way I can have this
when
| using regular delegates.
|
| Is this possible?
|
| Paul
|
|
 
Back
Top