473,408 Members | 1,907 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,408 software developers and data experts.

Reflection on static objects

The GetProperty ./ GetMethod etc. methods all require an instance as a first
parameter.

What if the property is static? I can't pass in a class, obviously...

John
Nov 16 '05 #1
3 5359
John,

GetProperty and GetMethod do not require an instance as a first
parameter, they require a Type instance, and then you can get properties and
methods, regardless of whether or not they are static.

Invoking them is a different story, and in this case, if the
method/property is static, then the method/property info will know this, and
you can pass null as the parameter for the instance.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"John Wood" <j@ro.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
The GetProperty ./ GetMethod etc. methods all require an instance as a first parameter.

What if the property is static? I can't pass in a class, obviously...

John

Nov 16 '05 #2
John Wood <j@ro.com> wrote:
The GetProperty ./ GetMethod etc. methods all require an instance as a first
parameter.

What if the property is static? I can't pass in a class, obviously...


Do you mean the PropertyInfo.GetValue methods etc? If so, pass in null
(as documented).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
Sorry I meant GetValue on the MemberInfo those methods return...

And you're right, passing in null does it.

Thanks guys.

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:uy****************@TK2MSFTNGP11.phx.gbl...
John,

GetProperty and GetMethod do not require an instance as a first
parameter, they require a Type instance, and then you can get properties and methods, regardless of whether or not they are static.

Invoking them is a different story, and in this case, if the
method/property is static, then the method/property info will know this, and you can pass null as the parameter for the instance.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"John Wood" <j@ro.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
The GetProperty ./ GetMethod etc. methods all require an instance as a

first
parameter.

What if the property is static? I can't pass in a class, obviously...

John


Nov 16 '05 #4

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

Similar topics

10
by: Sunny | last post by:
Hi, I have an old problem which I couldn't solve so far. Now I have found a post in that group that gave me an idea, but I can not fully understand it. The problem is: I'm trying to use a...
2
by: Jason Coyne Gaijin42 | last post by:
I have seen several people looking for a way to access the Columns collection when using the AutoGenerate = true option. Some people have gotten so far as to find the private autoGenColumnsArray...
0
by: Cat | last post by:
I have class Base, and class Derived. I am serializing Derived objects from XML, and these Derived objects are allowed to 'inherit' the values from other named Base objects already defined in...
0
by: torarvid | last post by:
Hello, I am trying to write a search function that will search through given properties in all objects of a given type for a given phrase, like so: ICollection Search( Type type, string...
4
by: Alexandre | last post by:
Hi, i currently know how to instantiate an object which has no parameters in the constructor. but i have objects which do have parameters in the constructor, how do i go about instantiating...
11
by: Aaron Queenan | last post by:
Given the classes: class Class { public static implicit operator int(Class c) { return 0; } } class Holder
15
by: satankidneypie | last post by:
Hi, I'm going to start this off with some code as it'll make it easier to explain afterwards... using System; namespace ConsoleApplication1 { /// <summary>
2
by: Stefan | last post by:
Hello, I was hoping my fellow coders would give me some feedback on the article I wrote which makes use of the System.Reflection namespace and Polymorphism to demonstrate how you can create...
0
by: liko81 | last post by:
I have an Invoice class that must know, directly or indirectly, how to do anything associated with creating, reading, or otherwise processing an invoice to a customer. It is an uber-DAO object that...
10
by: Rotsey | last post by:
Hi, I have a class that exist in my UI assembly that inherits from a class in a referenced assembly like this. class EmployeesDC { private string mstrEmployeeNumber; etc
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.