Reputation: 4323
Is there way in C# to get all parameters which were used with some extension method?
Example:
public static string GlueStrings(this string mystring, string otherString)
{
return mystring + otherstring;
}
In some method in Form1
string string1 = "Glued";
string string2 = string1.GlueStrings("Strings");
In some method in Form2
string string1 = "Foo";
string string2 = string1.GlueStrings("bar");
Is there a way I can create method which would list all parameters used with that method in whole solution, I am interested in parameter otherString
from whole solution?
UPDATE:
This with strings is just an example, I need it to work with different types. Like in MVC Controller annonations where you can get all controllers where some annonation is used.
Upvotes: 0
Views: 135
Reputation: 11191
Not the best way to do it when it comes to performance
but you can use MethodBase.GetParameters
Else
how about GlueStrings(this string mystring, params object[] others)
PS: I have not tried it or unit tested it
Update: Example on request by you
Suppose Class Glue have the method GlueStrings then:
ParameterInfo[] parameterInfos = typeof (Glue).GetMethod("GlueStrings").GetParameters();
Upvotes: 0
Reputation: 102743
You could keep a static ConcurrentBag in your class and add each parameter to it at runtime.
(concurrent collection for thread safety http://msdn.microsoft.com/en-us/library/system.collections.concurrent.aspx)
Upvotes: 1