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

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(MyTypeClass));

MethodInfo[] myArrayMethodInfo =
myType.GetMethods(BindingFlags.Public|BindingFlags .Instance|BindingFlags.DeclaredOnly);

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

--
======================
Clive Dixon
Digita Ltd. (www.digita.com)
"jibesh.vp" <ji*******@gmail.com> wrote in message
news:%2****************@TK2MSFTNGP03.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(MyTypeClass));

MethodInfo[] myArrayMethodInfo =
myType.GetMethods(BindingFlags.Public|BindingFlags .Instance|BindingFlags.DeclaredOnly);

- 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*******@gmail.com> wrote in message
news:%2****************@TK2MSFTNGP03.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(MyTypeClass));

MethodInfo[] myArrayMethodInfo =
myType.GetMethods(BindingFlags.Public|BindingFlags .Instance|BindingFlags.DeclaredOnly);

- 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@NoSpamPlease_Digita.com> wrote in message
news:uG**************@TK2MSFTNGP02.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*******@gmail.com> wrote in message
news:%2****************@TK2MSFTNGP03.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(MyTypeClass));

MethodInfo[] myArrayMethodInfo =
myType.GetMethods(BindingFlags.Public|BindingFlags .Instance|BindingFlags.Dec
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
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...
2
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
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...
4
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...
5
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...
1
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...
17
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...
0
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
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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...

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.