all groups > dotnet framework > july 2004 >
You're in the

dotnet framework

group:

What are the "get_..." methods all about?


What are the "get_..." methods all about? pseudobill2004 NO[at]SPAM yahoo-dot-ca.no-spam.invalid
7/30/2004 3:03:13 PM
dotnet framework:
I'm using reflection to get all public methods for a type, and I get
all these methods starting with "get_". What's that all about? They
aren't viewable from the object browser.
Re: What are the "get_..." methods all about? Gabriele G. Ponti
7/30/2004 4:10:04 PM
In brief the "properties" as implemented by C# and VB.NET are just syntactic
sugar. The compilers translate them as get/set couple.

http://en.wikipedia.org/wiki/Syntactic_sugar

re:What are the "get_..." methods all about? pseudobill2004 NO[at]SPAM yahoo-dot-ca.no-spam.invalid
7/30/2004 5:03:16 PM
Ahh - thanks!

Is there an elegant way to retrieve just methods, without properties?

Currently, I'm using:
MethodInfo[] oMethods =
asmType.GetMethods(BindingFlags.Public|BindingFlags.Instance|BindingFlags.Static|BindingFlags.DeclaredOnly);

Is there a binding flag or something to omit properties?
Re: re:What are the "get_..." methods all about? Jon Skeet [C# MVP]
7/31/2004 9:12:10 AM
[quoted text, click to view]

I don't think there's a binding flag to do it, but from a MethodInfo
you can use IsSpecialName which will detect properties and the like.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
re:What are the "get_..." methods all about? pseudobill2004 NO[at]SPAM yahoo-dot-ca.no-spam.invalid
7/31/2004 10:02:59 AM
Thanks Jon! That definitely works.

I must say though, that this aspect of reflection is not well thought
out by Microsoft. There should be some more intuitive way to filter
out properties from methods. I know that you can get just properties
easily (via GetProperties), but this non-intuitive way of getting
methods minus properties sucks.

Also, the fact that properties are returned as "get_X" when using
"GetMethods" is just a terrible hack - there is no "get_X" available
to anyone outside of the assembly - it's only internally regarded as
"get_X". They should be returned using the same name that they are
available to anyone coding to the assembly.
Re: re:What are the "get_..." methods all about? Niki Estner
8/1/2004 10:36:35 AM
"PseudoBill" <pseudobill2004@yahoo-dot-ca.no-spam.invalid> wrote in
news:410bb4a3_3@Usenet.com...
[quoted text, click to view]

Properties are just syntactic sugar C# or VB.net offer to you; in MC++ for
example, you have to code them as methods. The JIT also treats properties
like methods, so why should they get much special attention in IL/metadata?

[quoted text, click to view]

It's not a hack. It's syntetic sugar. Overriden methods in C++ were
implemented similarly, using unreadable cryptic internal function names.
This kind of coding isn't uncommon at all, the compiler builders simply
chose to reuse the "method" code they already had for properties.

[quoted text, click to view]

Think MC++, or any other .net language that doesn't have native support for
properties.

[quoted text, click to view]

Then how would you distinguish the getter from the setter?

Niki

Re: re:What are the "get_..." methods all about? Jay B. Harlow [MVP - Outlook]
8/1/2004 10:46:03 AM
PseudoBill,
[quoted text, click to view]
They Are!!

J# and other languages that do not have specific support for Properties use
the get_X method.

Similar to overloaded operators, VB.NET does not support overloaded
operators, while C# does. C# is able to use the overloaded operator, while
VB.NET needs to use a special named method such as op_Addition.

Hope this helps
Jay

[quoted text, click to view]

re:What are the "get_..." methods all about? pseudobill2004 NO[at]SPAM yahoo-dot-ca.no-spam.invalid
8/2/2004 5:04:06 PM
Thanks Jay and Niki - your explanations have provided some clarity.
Re: What are the "get_..." methods all about? johnnliu NO[at]SPAM gmail.com
8/2/2004 6:11:28 PM
[quoted text, click to view]

BindingFlags.GetProperty, BindingFlags.SetProperty
Looks interesting, but I'm not sure whether they are what you want here.

AddThis Social Bookmark Button