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

Invoke Methods with Arbitrary (Known) Parameters From a Single Method

I'm looking for a way to invoke methods with an arbitrary number of
parameters of arbitrary type from within a single method, when those
parameters are known at the time of invocation of the containing
method. I don't see a reason why this shouldn't work. I also can't
find the language feature which implements it. More details below.

As part of the creation of a set of classes for doing unit testing I
want to create a generic 'RunTestMethod' method. This method will
encapsulate my reporting and data collection (whether a given test
passed or failed, how many tests have passed or failed so far). In
order to be useful it also needs to be capable of calling a method
with an arbitrary number of parameters (whose values are known when
the 'RunTestMethod' method is called). This is to preserve the
generality of the testing framework.

My first thought was to use delegates. This allows me to pass a
variety of methods to another method and invoke them therein. However,
I have yet to find a way of allowing a delegate to have arguments
whose number and type differ from the method to be invoked, even when
the arguments are known at the point of instantiation.

Can any of you think of a way of implementing this that doesn't
sacrifice generality?

Mar 12 '07 #1
2 1960
<wa*********@gmail.comwrote in message
news:11**********************@8g2000cwh.googlegrou ps.com...
I'm looking for a way to invoke methods with an arbitrary number of
parameters of arbitrary type from within a single method, when those
parameters are known at the time of invocation of the containing
method. I don't see a reason why this shouldn't work. I also can't
find the language feature which implements it. More details below.

As part of the creation of a set of classes for doing unit testing I
want to create a generic 'RunTestMethod' method. This method will
encapsulate my reporting and data collection (whether a given test
passed or failed, how many tests have passed or failed so far). In
order to be useful it also needs to be capable of calling a method
with an arbitrary number of parameters (whose values are known when
the 'RunTestMethod' method is called). This is to preserve the
generality of the testing framework.

My first thought was to use delegates. This allows me to pass a
variety of methods to another method and invoke them therein. However,
I have yet to find a way of allowing a delegate to have arguments
whose number and type differ from the method to be invoked, even when
the arguments are known at the point of instantiation.

Can any of you think of a way of implementing this that doesn't
sacrifice generality?
You can do this using reflection. See System.Type.GetMethod(),
System.Reflection.MethodInfo.Invoke().

-cd
Mar 12 '07 #2
On 12 Mar 2007 14:13:27 -0700, wa*********@gmail.com wrote:
>Can any of you think of a way of implementing this that doesn't
sacrifice generality?
The most general way would be to declare your delegate and its methods
as receiving a params object[] array. That way they can all get an
arbitrary number of arbitrary parameters. However, they have to
figure out the type and purpose of these parameters on their own.
--
http://www.kynosarges.de
Mar 13 '07 #3

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

Similar topics

99
by: David MacQuigg | last post by:
I'm not getting any feedback on the most important benefit in my proposed "Ideas for Python 3" thread - the unification of methods and functions. Perhaps it was buried among too many other less...
0
by: Anthony Baxter | last post by:
To go along with the 2.4a3 release, here's an updated version of the decorator PEP. It describes the state of decorators as they are in 2.4a3. PEP: 318 Title: Decorators for Functions and...
2
by: Neil Fedin via .NET 247 | last post by:
I am writing a testing application that uses reflection to open assemblies and call methods. I have a function that looks like this... public void Method1 (int IDArray, bool SomethingElse){...
0
by: Alex Zhitlenok | last post by:
Hi, On Google, one can find a lot of statements that Invoke and InvokeMemeber work alike. However, my own experience contradicts this statement. 1. Surprisingly, Invoke and InvokeMember methods...
14
by: stic | last post by:
Hi, I'm in a middle of writing something like 'exception handler wraper' for a set of different methodes. The case is that I have ca. 40 methods form web servicem, with different return values...
10
by: John | last post by:
Trying to find out what is essential / optional, I made an extremely simple Class and Module combination to add two numbers. (see below) It appears that an empty constructor is needed n order to...
2
by: John Lutz | last post by:
Our app is mainly COM based. We allow .NET plug-ins. When a plug-in is installed, it receives a COM pointer to the app. The plug-in implements our IExtensionImpl interface and gets the app...
26
by: Cliff Williams | last post by:
Can someone explain the pros/cons of these different ways of creating a class? // 1 function myclass() { this.foo1 = function() {...} } // 2a
2
by: AlbertoCanabal | last post by:
Hi everybody. I'm developing an app in c# that requires an invocation on some methods of different web services. The point is that the web service's name, parameters, URL and the method name and...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.