473,320 Members | 2,094 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How do I know a MemberInfo is static?

Is there any way I can find out a MethodInfo/PropertyInfo/... is
static (which means the same as in C# language here)?

Thanks!
Jun 27 '08 #1
4 2888
Well, one option is the calling convention; static is "Standard",
instance is generally "HasThis" (for C# at least). With PropertyInfo you
might have to get one of the accessors (GetGetMethod / GetSetMethod) to
do this.

There may be other ways, of course...

Marc
Jun 27 '08 #2
On Jun 19, 4:44*pm, Marc Gravell <marc.grav...@gmail.comwrote:
Well, one option is the calling convention; static is "Standard",
instance is generally "HasThis" (for C# at least). With PropertyInfo you
might have to get one of the accessors (GetGetMethod / GetSetMethod) to
do this.

There may be other ways, of course...

Marc
Thanks, I'll have a try.

I am wondering why wouldn't the microsoft guys add an IsStatic
property for MemberInfo class :(
Jun 27 '08 #3
On Thu, 19 Jun 2008 03:39:21 -0700, deerchao <de******@gmail.comwrote:
I am wondering why wouldn't the microsoft guys add an IsStatic
property for MemberInfo class :(
Well, wouldn't that be redundant? I mean, "HasThis" means that the call
uses a "this" reference, which is exactly what an instance member
requires. Likewise, "Standard" means it doesn't, which is exactly what a
static member requires. The need to get at the method (i.e. for dealing
with properties) adds a little inconvenience, but it's not like the
information isn't there.

You also have the alternative of specifically searching for instance and
static members separately (use the Type.GetMember(BindingFlags)
overload). Then whatever's returned, you know it will be the specific
category of member that you asked for, instance or static.

I guess I'm saying that while adding an IsStatic property might have made
it even _more_ convenient, once you head down that path there's all sorts
of attributes they could expose as properties rather than just having you
look at the specific meta-data. Given that the information is in fact
available, I think the reason "the microsoft guys" wouldn't add an
IsStatic property is that there's really no need to.

Pete

Jun 27 '08 #4
I guess I'm saying that while adding an IsStatic property might have
made it even _more_ convenient, once you head down that path there's
all sorts of attributes they could expose as properties rather than
just having you look at the specific meta-data. Given that the

But... they did. All sorts of attributes. In the MethodBase.Attributes
property no less.

Try (mi.Attributes & MethodAttributes.Static).

information is in fact available, I think the reason "the microsoft
guys" wouldn't add an IsStatic property is that there's really no
need to.
Pete

Jul 18 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: SJ | last post by:
Hi: I have a class which has a static member function. The function implements something common to all instances. How can the static member function know all of the (Get access to the instances'...
79
by: Me | last post by:
Just a question/observation out of frustration. I read in depth the book by Peter Van Der Linden entitled "Expert C Programming" (Deep C Secrets). In particular the chapters entitled: 4: The...
2
by: Ben Taylor | last post by:
Hi, I am writing a program that uses different threads to handle various painting operations, I wondered if somebody could possible tell me if I create a new thread using...
14
by: stic | last post by:
Hi, I'm in a middle of writing something like 'exception handler wraper' for a set of different methodes. The case is that I have ca. 40 methods form web servicem, with different return values...
5
by: admin | last post by:
ok This is my main. Pretty much it goes through each category and starts up 4 worker threads that then ask for groups to gether from. My problem is that when the thread gets done it keeps the...
5
by: per9000 | last post by:
Hi all, I have a question I am unable solve. I have an inheritance graph like this: // CAR ----- MUSICAR ---- NICECAR // \ \ // \ +------ OLDCAR // \ // ...
8
by: Diego F. | last post by:
Hello. I'd like to know if there's a way to know if all threads started using the threadpool are finished. How can I ensure that all threads finished? -- Regards, Diego F.
4
by: =?Utf-8?B?a2g=?= | last post by:
Hi. In a custom attribute, is there any way for me to discover the type/member to which the attribute is applied during attribute construction? For example: public enum MyEnum { MyField,...
3
by: jlgraham | last post by:
This is the first course I have ever taken in any programming language. This is my last assignment and totally frustrated. My employee class compiled but get 1 error when I tried to compile my...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.