J
JH
Fairly new to c# so please forgive any simple oversights.
I'm developing a console app that loads dll assemblies at run time. The app
scans a "plugin" directory for these dlls. Each dll is loaded into an
Assembly object, the types in the assembly are extracted and the methods on
each type are extracted. If a method matches certain criteria (i.e. public
static, a specific argument list(string, string, boolean)) then i store
details about the method. Any method "matches" that are found will be
invoked at a later time.
My problem is that while most of these "target" methods will have the same
argument list (string,string,boolean) some may have additonal parameters
e.g. string, string, boolean, int, int. I also need to store these new
methods and if possible i will need to get some information on the new
parameters to identify them to the user i.e. parameter name.
Is what i describe about the variable arguments possible to do? if so how?
Thanks in advance for any help provided.
For reference here is a snippet of the code i currently have:
foreach (Type t in types)
{
if (t.IsClass)
{
// Find any target methods for this class and add references to the
hashtables
MethodInfo[] methodsList = t.GetMethods(BindingFlags.Public |
BindingFlags.Static | BindingFlags.DeclaredOnly);
foreach(MethodInfo mtdInfo in methodsList)
{
ParameterInfo[] paramTypes = mtdInfo.GetParameters();
if (paramTypes.Length == 3)
{
if ((paramTypes[0].ParameterType == Type.GetType("System.string"))&&
(paramTypes[1].ParameterType == Type.GetType("System.string"))&&
(paramTypes[2].ParameterType == Type.GetType("System.Boolean")))
{
// Add method name + assembly to hashtables
}
}
}
}
}
I'm developing a console app that loads dll assemblies at run time. The app
scans a "plugin" directory for these dlls. Each dll is loaded into an
Assembly object, the types in the assembly are extracted and the methods on
each type are extracted. If a method matches certain criteria (i.e. public
static, a specific argument list(string, string, boolean)) then i store
details about the method. Any method "matches" that are found will be
invoked at a later time.
My problem is that while most of these "target" methods will have the same
argument list (string,string,boolean) some may have additonal parameters
e.g. string, string, boolean, int, int. I also need to store these new
methods and if possible i will need to get some information on the new
parameters to identify them to the user i.e. parameter name.
Is what i describe about the variable arguments possible to do? if so how?
Thanks in advance for any help provided.
For reference here is a snippet of the code i currently have:
foreach (Type t in types)
{
if (t.IsClass)
{
// Find any target methods for this class and add references to the
hashtables
MethodInfo[] methodsList = t.GetMethods(BindingFlags.Public |
BindingFlags.Static | BindingFlags.DeclaredOnly);
foreach(MethodInfo mtdInfo in methodsList)
{
ParameterInfo[] paramTypes = mtdInfo.GetParameters();
if (paramTypes.Length == 3)
{
if ((paramTypes[0].ParameterType == Type.GetType("System.string"))&&
(paramTypes[1].ParameterType == Type.GetType("System.string"))&&
(paramTypes[2].ParameterType == Type.GetType("System.Boolean")))
{
// Add method name + assembly to hashtables
}
}
}
}
}