There is no "simple" way to do it in C# or VB.NET (that I know of).
There may be other .NET languages that allow it.
You might be able to accomplish it with some reflection code, but that
would probably be unncessarily complex (and possibly slower).
The simplest way would probably be to create a bunch of method overloads.
For example:
private void Foo(IDictionary parameters){
// this method contains the implementation of the method
// accessing all parameters by name in the IDictionary
}
// This is an example of a method that takes parameters
public void Foo(string name, int age){
// load the parameters into a dictionary
IDictionary parameters = new ListDictionary();
parameters.Add("name", name);
parameters.Add("age", age);
// call the main implemtation
this.Foo(parameters);
}
// This is an example of the same method taking different parameters
public void Foo(User user){
// load the parameters into a dictionary
IDictionary parameters = new ListDictionary();
parameters.Add("user", user);
// call the main implemtation
this.Foo(parameters);
}
etc, adding as many overloads as you want, as long as the signatures do
not conflict.
Joshua Flanagan
http://flimflan.com/blog
Mad Scientist Jr wrote:
Is it possible to write a method with a signature for x parameters (so
you get intellisense when you call it), but from within the method, be
able to access the parameter names and values in a name/value
collection (or similar, perhaps a name/value/type collection) so that
one generic function exists as the code for multiple methods/signature?