GetMethod?

  • Thread starter Thread starter perspolis
  • Start date Start date
P

perspolis

Hi
I saw this fragment code somewhere.
MethodInfo mi=dg.GetType().GetMethod("get_DataGridRows");

I know that that code gets info about get_DataGridRows method.

but I can't find this code in MSDN..

what's your opinion???

??

thx
 
perspolis said:
Hi
I saw this fragment code somewhere.
MethodInfo mi=dg.GetType().GetMethod("get_DataGridRows");

I know that that code gets info about get_DataGridRows method.

but I can't find this code in MSDN..

what's your opinion???

It's called Reflection in .NET and Introspection in Java and RTTI in Delphi.
It allows you to check a class at runtime and query about it's structure.

The above code tries to get a 'handle' to the property DataGridRows.
As there are no properties in CIL, properties are just compiled to methods
with get_ and set_ attached.

Reflection is a powerful and dangerous tool. With Reflection you can
circumvent many aspects of OO. You can access private members and call on
private methods on an instance of a class.

I suggest you never do that! =)

Reflection is a key feature for serializing objects (to SOAP or binary or
whatever) and is typically used just for that. It can also be used for
writing code that documents your classes. And also for checking and calling
on types that are dynamically loaded. Me myself and I have seldom had any
need for it on Application-level.

For me, using Reflection on Application-level is like opening a door with a
shotgun just because you lost your keys. Or trying to do J2EE on .NET. Same
same. Poor solution for a poor design. =)

On Tool- and Component-level it is a mighty feature.

Happy Coding
- Michael S
 
thx Michael
good description of reflection :)

Michael S said:
It's called Reflection in .NET and Introspection in Java and RTTI in Delphi.
It allows you to check a class at runtime and query about it's structure.

The above code tries to get a 'handle' to the property DataGridRows.
As there are no properties in CIL, properties are just compiled to methods
with get_ and set_ attached.

Reflection is a powerful and dangerous tool. With Reflection you can
circumvent many aspects of OO. You can access private members and call on
private methods on an instance of a class.

I suggest you never do that! =)

Reflection is a key feature for serializing objects (to SOAP or binary or
whatever) and is typically used just for that. It can also be used for
writing code that documents your classes. And also for checking and calling
on types that are dynamically loaded. Me myself and I have seldom had any
need for it on Application-level.

For me, using Reflection on Application-level is like opening a door with a
shotgun just because you lost your keys. Or trying to do J2EE on .NET. Same
same. Poor solution for a poor design. =)

On Tool- and Component-level it is a mighty feature.

Happy Coding
- Michael S
 
thx perspolis.

And while you posted some code that was doing things with Reflection, I'll
post some funny lame code that makes you sick. We found this in a project
recently:

bool hasMenues = ((list.Count > 0) ? true : false);

Happy Sobbing
- Michael S
 
And while you posted some code that was doing things with Reflection, I'll
post some funny lame code that makes you sick. We found this in a project
recently:

bool hasMenues = ((list.Count > 0) ? true : false);

We have a lot of practical trainees in our company. After seeing hundreds
and thousands of such lines I cannot laugh about such things anymore..
 
cody said:
We have a lot of practical trainees in our company. After seeing hundreds
and thousands of such lines I cannot laugh about such things anymore..

Hehe cody.
I rather laugh than cry.
If you find something stupid, you can always send it here...

http://thedailywtf.com/

Happy Laughing
- Michael S
 
Back
Top