Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / July 2005

Tip: Looking for answers? Try searching our database.

Type.GetMethod() with generic method parameters: a hen-or-egg problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gael Fraiteur - 14 Jul 2005 09:33 GMT
Hi there,

I wonder how to get a MethodInfo using System.Reflection.Type::GetMethod
when the method has a parameter which is a generic method parameter.

Consider this method:

void MyMethod<T>( T myParam) { ... }

I would like to use the GetMethod method to return the MethodInfo
corresponding to MyMethod. The signature of GetMethod is:

public sealed MethodInfo GetMethod(
string name,
BindingFlags bindingAttr,
Binder binder,
Type[] types,
ParameterModifier[] modifiers
);

The problem is: how to construct the 'types' argument since the 'myParams'
parameter is of a generic method parameter (!!0). If I had the MethodInfo, I
would make methodInfo.GetGenericArguments() to get the Type of 'myParam',
but obviously I cannot use this technique since I do not have the MethodInfo
at the moment where I want to get the type of the argument. There is a kind
of hen-or-egg problem.

There are of course workarounds, for instance using GetMethods() and
iterating.

But has anyone an idea how to solve this "cleanly"? Any suggestion would be
helpful.

Thank you.

Gael Fraiteur
Gael Fraiteur - 22 Jul 2005 12:19 GMT
Any taker?

Signature

Gael Fraiteur
http://gael.fraiteur.net


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.