I am struggling with calling a method with reflection...
The method signature is as follows: (changed the actual names...)
I have a interface called :
public interface ICharacteristics
{
Score calculateScore(int ScorecardID, string UniqueID, ArrayList CharacteristicsValues);
}
Then i have another class called:
public class ScoreSmartCharValues
{
private string name;
private int value;
public int Value
{
get { return this.value; }
set { this.value = value; }
}
public string Name
{
get { return name; }
set { name = value; }
}
public ScoreSmartCharValues(int value, string name)
{
this.name = name;
this.value = value;
}
public ScoreSmartCharValues()
{
}
}
another class as follow:
public Score calculateScore(int ScorecardID, string UniquesID, ArrayList CharacteristicsValues)
{
//Do something and return Score;
return new Score();
}
Ok so once build... generates a DLL score.dll
The code that i use is simple to call reflection and invoke the method:
Assembly assembly = Assembly.LoadFrom(@"Score.dll");
foreach (Type type in assembly.GetTypes())
{
if (type.IsClass == true)
{
Console.WriteLine("...Found Class : {0}", type.FullName);
if (type.GetInterface("ICharacteristics") == null)
{
continue;
}
object ibaseObject = Activator.CreateInstance(type);
List<ScoreSmartCharValues> CharacteristicsValues = new List<ScoreSmartCharValues>();
CharacteristicsValues.Add(new ScoreSmartCharValues(1, "robs"));
object oObjectType = new object();
oObjectType = CharacteristicsValues;
object[] arguments = new object[] { 10, "test", CharacteristicsValues };
object result;
Console.WriteLine("......Dynamically Invoking compute() on {0} Class", type.FullName);
result = type.InvokeMember("calculateScore",
BindingFlags.Default |BindingFlags.InvokeMethod,
null,
ibaseObject,
arguments);
Console.WriteLine("......Result is: {0}", result);
}
}
I get a method not found...
If i change the argument to send in Null in the place of the list it works...