473,786 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Some doubt about reflection

Hi all,

I have a doubt in using C# Reflection mechanism .

What i need is to get method info alone from a class type.

Following code gets all the Properties inside the class too and there is no
way to
differentiate a method from property.

MemberType propertie of the MethodInfo class always have the value " Method
" for all the methods and properites

Any Help
sample:

public class MyTypeClass

{

public void MyMethods() { }

private int data;

public int Data

{

get{ return this.data; }

set { this.data = value; }

}

}

public class TypeMain

{

public static void Main()

{

Type myType =(typeof(MyType Class));

MethodInfo[] myArrayMethodIn fo =
myType.GetMetho ds(BindingFlags .Public|Binding Flags.Instance| BindingFlags.De claredOnly);

- Jibesh.V.P
May 3 '06 #1
3 2318
Check the MemberType property of the MemberInfo base class of the MethodInfo
class?

--
=============== =======
Clive Dixon
Digita Ltd. (www.digita.com)
"jibesh.vp" <ji*******@gmai l.com> wrote in message
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
Hi all,

I have a doubt in using C# Reflection mechanism .

What i need is to get method info alone from a class type.

Following code gets all the Properties inside the class too and there is
no way to
differentiate a method from property.

MemberType propertie of the MethodInfo class always have the value "
Method " for all the methods and properites

Any Help
sample:

public class MyTypeClass

{

public void MyMethods() { }

private int data;

public int Data

{

get{ return this.data; }

set { this.data = value; }

}

}

public class TypeMain

{

public static void Main()

{

Type myType =(typeof(MyType Class));

MethodInfo[] myArrayMethodIn fo =
myType.GetMetho ds(BindingFlags .Public|Binding Flags.Instance| BindingFlags.De claredOnly);

- Jibesh.V.P

May 3 '06 #2
> Following code gets all the Properties inside the class too and there is
no way to
differentiate a method from property.
That's because properties are implemented using methods. So in your example
for property 'Data' you will see methods:

Int32 get_Data()
Void set_Data(Int32)

You have two choices as I see it if you want to differentiate between
methods that aren't being used for properties. The first is to look for get_
and set_ patterns in the methods and hide them or alternatively iterate over
the properties first for a class getting their associated get and set method
infos and then remove them from your methods list.

I prefer the last approach as this guarantees what you want.

HTH

Regards
Lee

"jibesh.vp" <ji*******@gmai l.com> wrote in message
news:%2******** ********@TK2MSF TNGP03.phx.gbl. .. Hi all,

I have a doubt in using C# Reflection mechanism .

What i need is to get method info alone from a class type.

Following code gets all the Properties inside the class too and there is
no way to
differentiate a method from property.

MemberType propertie of the MethodInfo class always have the value "
Method " for all the methods and properites

Any Help
sample:

public class MyTypeClass

{

public void MyMethods() { }

private int data;

public int Data

{

get{ return this.data; }

set { this.data = value; }

}

}

public class TypeMain

{

public static void Main()

{

Type myType =(typeof(MyType Class));

MethodInfo[] myArrayMethodIn fo =
myType.GetMetho ds(BindingFlags .Public|Binding Flags.Instance| BindingFlags.De claredOnly);

- Jibesh.V.P

May 3 '06 #3
Yes.. Thank you Lee thats what i did last.

But its preferable that if we can identify propertie using MemberType.

Why did they miss this checking ? then whats the need of a MemberType enum
object
in the MethodInfo class where Type.GetMethods (....) always returns methods
only
no property or constructor etc ( i mean its not possible to differentiate
them)..

Thanks
Jibesh.V.P

"Lee Alexander" <lee@NoSpamPlea se_Digita.com> wrote in message
news:uG******** ******@TK2MSFTN GP02.phx.gbl...
Following code gets all the Properties inside the class too and there is
no way to
differentiate a method from property.
That's because properties are implemented using methods. So in your

example for property 'Data' you will see methods:

Int32 get_Data()
Void set_Data(Int32)

You have two choices as I see it if you want to differentiate between
methods that aren't being used for properties. The first is to look for get_ and set_ patterns in the methods and hide them or alternatively iterate over the properties first for a class getting their associated get and set method infos and then remove them from your methods list.

I prefer the last approach as this guarantees what you want.

HTH

Regards
Lee

"jibesh.vp" <ji*******@gmai l.com> wrote in message
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
Hi all,

I have a doubt in using C# Reflection mechanism .

What i need is to get method info alone from a class type.

Following code gets all the Properties inside the class too and there is
no way to
differentiate a method from property.

MemberType propertie of the MethodInfo class always have the value "
Method " for all the methods and properites

Any Help
sample:

public class MyTypeClass

{

public void MyMethods() { }

private int data;

public int Data

{

get{ return this.data; }

set { this.data = value; }

}

}

public class TypeMain

{

public static void Main()

{

Type myType =(typeof(MyType Class));

MethodInfo[] myArrayMethodIn fo =
myType.GetMetho ds(BindingFlags .Public|Binding Flags.Instance| BindingFlags.De c
laredOnly);
- Jibesh.V.P


May 3 '06 #4

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

Similar topics

2
1636
by: Baskar RajaSekharan | last post by:
Hi I have one doubt in C#. I created one component called CustomTesting in VC7. The DLL contains Two Method called Execute and SetOCxInterface. I want to Load the Dll from my Sample application(which is in C#) with out Addeing it in Reference. ie i want to load it dynamically with the help of Activator.CreateInstance. Then i want to access those method. How to Do that?
2
2061
by: Marco | last post by:
Hi, I try to use reflection to retrieve class B members and not inherited members. I wonder why the myMember value is nothing. Any suggestions? Thanks Module Module1 Sub Main()
2
7775
by: Jeff | last post by:
I am trying to dynamically load an assembly via reflection and then invoke a method of that assembly that will populate a custom type collection passed into the method byref. I am able to dynamically load both the DALC component (for the method call) and the Entity component (for the custom type collection to pass in), but I keep getting an error ( Message "Object type cannot be converted to target type.") when invoking the method. If I...
4
1486
by: Vai2000 | last post by:
Hi All, I am using Reflection for invoking an assembly.I use the LoadFrom(string) Method, have few doubts, will appreciate all your answers. 1. Should the assembly resides in GAC or at my custom location? (Please tell me pros/cons) 2. If multiple calls are made to the target assembly by a Multithreaded app..it should be fine? (tips to keep in mind) TIA
5
1863
by: heddy | last post by:
I understand that reflection allows me to discover the metadata of a class at runtime (properties, methods etc). What I don't understand is where this is useful. For example: If I am the sole author of an application, I already know the metadata about my classes - I wrote them. And even if I did not - Let's say I buy a 3rd party class lib, it will be documented for me with that lib. If I am part of a dev team, the same is true - If...
1
1719
by: John Bode | last post by:
I need a way to fake reflection in C++ code that makes as few assumptions about the data types involved as possible. I suspect there is no good answer for what I need to do, but I'll present the case anyway. We have a class that normally registers with another service, which then executes callbacks in our class. Since that other service isn't going to be available for testing for a while, we're simulating it with a simple script-based...
17
2312
by: raylopez99 | last post by:
What good is C# Reflection, other than to find out what types are in an assembly? And to dynamically invoke methods in an assembly (.dll or .exe)? Also, bonus question, can you use Reflection to build a compiler? One that will construct a user defined class "on the fly" (literally, the user defines a class, instantiates it, and runs it from the console mode, all the while prompted by the program)? I guess so, but my final question...
0
1702
by: Gustavo Arriola | last post by:
Hola a todos! Estoy intentando ejecutar un método usando Reflection. El código es el siguiente: public static void SoapHandler(Exception Error) { try { Type assemblyType;
6
1971
by: Cralis | last post by:
Hi guys, Someone once said, 'You can do that with reflection'. I can't recall what it was I was trying to do at the time, but then he said, 'Any developer knows what reflection is...'. I kept quiet and smiled. What is reflection!? I have been reading it up, and all I can work out is that it has something to do with Late Binding, and the use of GetType and Type.
0
9496
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10164
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8989
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7512
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4066
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3669
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.