473,385 Members | 1,518 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.

How do I acquire MethodInfo WITHOUT hardcoding the method name in GetMethod?!

hey,
How do I acquire MethodInfo WITHOUT hardcoding method name as a
string?!??!The fact I have to use xxx.Gettype.GetMethod("MyMethod",
xxx) is making me want to drive an ice pick into my eye!
I have exhausted my resources and I cannot find a way out of it.
Having to use that creates a dangerous situation because the name of
the method could change. For instance, let's say you fav 3rd party
library rolls out a new version and the hardcoded strings won't match
it. Then you have to go through your code and hope to God you nail
them all or an exception will be thrown. Thats bad for huge production
code bases with hundreds of thousands of lines of code spread out all
over the place.

I need something, (anything!), like this:
==================
public sub MyMethod()
....do something
end sub

dim oInfo as methodInfo
oInfo = xxxxx.GetType.GetMethod(xxxxx.GetType.GetMethodNam e(MyMethod))
==================

Does somebody out there know something I don't? In Delphi....all I had
to do was "Somevar := @MyMethod" and I had what I needed. Of course, I
know thats bad bad in VB.NET, but some call that returns the string
name will work because I can then use the GetMethod without being
locked to a hardcoded method name. Any ideas? I'm desperate!

-The Angry Gerbil
(who wouldn't be angry if he could figure this out!)
Nov 22 '05 #1
1 2048

"AngryGerbil" <le******@comcast.net> wrote in message
news:aa**************************@posting.google.c om...
hey,
How do I acquire MethodInfo WITHOUT hardcoding method name as a
string?!??!The fact I have to use xxx.Gettype.GetMethod("MyMethod",
xxx) is making me want to drive an ice pick into my eye!
I have exhausted my resources and I cannot find a way out of it.
Having to use that creates a dangerous situation because the name of
the method could change. For instance, let's say you fav 3rd party
library rolls out a new version and the hardcoded strings won't match
it. Then you have to go through your code and hope to God you nail
them all or an exception will be thrown. Thats bad for huge production
code bases with hundreds of thousands of lines of code spread out all
over the place.

I need something, (anything!), like this:
==================
public sub MyMethod()
....do something
end sub

dim oInfo as methodInfo
oInfo = xxxxx.GetType.GetMethod(xxxxx.GetType.GetMethodNam e(MyMethod))
==================

Does somebody out there know something I don't? In Delphi....all I had
to do was "Somevar := @MyMethod" and I had what I needed. Of course, I
know thats bad bad in VB.NET, but some call that returns the string
name will work because I can then use the GetMethod without being
locked to a hardcoded method name. Any ideas? I'm desperate!
Umm, why, if the method name changes, would MyMethod still bind properly? If
MyMethod is now MyOtherMethod, then xxxx.GetType.GetMethodName(MyMethod)
should throw an erro because there is no MyMethod anymore...I don't really
see how its easier to change a string without "'s than one with
-The Angry Gerbil
(who wouldn't be angry if he could figure this out!)

Nov 22 '05 #2

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

Similar topics

1
by: AngryGerbil | last post by:
hey, How do I acquire MethodInfo WITHOUT hardcoding method name as a string?!??!The fact I have to use xxx.Gettype.GetMethod("MyMethod", xxx) is making me want to drive an ice pick into my eye! I...
0
by: Ffelagund | last post by:
Hello I'm trying to load dinamically some dll's but when I try to invoke one method, I ever get ArgumentException if I'm not using native types. Here are the .h of the dll: #pragma once...
8
by: AngryGerbil | last post by:
hey, How do I acquire MethodInfo WITHOUT hardcoding method name as a string?!??!The fact I have to use xxx.Gettype.GetMethod("MyMethod", xxx) is making me want to drive an ice pick into my eye! I...
1
by: Sivaraman.S | last post by:
Hi, Can i pass integer array to methodInfo.Invoke(obj,args()). I am able to pass only string array to this function. This is the code i have written. Dim myType As Type = objClass.GetType()...
3
by: Me | last post by:
I am trying to figure out any issues with calling System.Reflection.MethodInfo.Invoke() when dealing with multiple threads. For instance.. Say I have a class that allows you to pass in a...
1
by: ian | last post by:
Hi, I can't find a solution to this, so I've brought it to the experts. Using reflection I can get a MethodInfo object pointing at an assembly's method. Where I have a MethodInfo object...
3
by: Lambuz | last post by:
Hi all, when I use MethosInfo.Invoke method I obtain a TargetInvocationException where inner exception is +{"classBase.OpenConn cannot be invoked directly" } System.Exception. I'm using the...
4
by: =?Utf-8?B?Um9nZXIgVHJhbmNoZXo=?= | last post by:
Question Hello, I'm trying to get a MethodInfo class with this code: --------------------------------------------- Imports System.Reflection Public Class Form1
15
by: =?Utf-8?B?VG9tIENvcmNvcmFu?= | last post by:
I've been led to believe by several articles, particularly Eric Gunnerson's C# Calling Code Dynamically, that calling a method dynamically through Reflection was much slower than through a...
11
by: KMinFL | last post by:
This is a C# VS 2008 question... Our system has 2 base classes, SingleEntity and NewPluralEntity. SingleEntity provides access to properties and methods related to manipulating data in a database...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
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?

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.