In my C# project I have a dependency on a 3rd party library. Now I want to write an automated acceptance test for my project. However to invoke the test I need an instance of a class from the 3rd party library. Using reflection I managed to set the values as I needed them apart from one.
Here is the relevant class that I am having the issue with:
public class SystemResults
{
// There must be something like this. However I cannot see it as it is private.
private List<Positions> xyz = new List<Positions>();
public IList<Positions> Positions
{
get
{
return xyz;
}
// This property does not have a set method
}
}
Here is what I have tried so far:
private void InitSystemResults(Type trueSysResType, SystemResults sysRes)
{
List<Position> positions = ImporterTools.GetPositions(PositionsCsv);
trueSysResType.GetProperty("Positions").SetValue(sysRes, positions); // ==> Here I get an exception
}
When I invoke the SetValue()
method the following exception is thrown.
System.ArgumentException : Property set method not found.
From this information I figured out, that the class must look as I described above.
Now I would like to proceed with this some how. Has anybody an idea how I can achieve that when I access sysRes.Positions
my positions
are returned by the get method? Or is there a way to change the get method?