I have a DLL which contains a bunch of classes and methods. I'm calling invoke on methods within the DLL which return values. This works fine if i'm trying to return a single value such as a string or int. Now I've come across a situation where I need to return a struct and use the values from the struct in my test harness.
The DLL its calling is called WebDriver.
Heres the code im calling for the invoke:
var TestDLL = Assembly.LoadFrom(TestDLLString);
Type myClassType = TestDLL.GetType("SeleniumDPS." + testname);
var instance = Activator.CreateInstance(myClassType);
MethodInfo myResultGetter = myClassType.GetMethod("ReturnResult");
try
{
myResults = (Results)myResultGetter.Invoke(instance, null);
teststatus = Results.result;
testResultFile = Results.testFile;
StartTime = Results.startTime;
EndTime = Results.endTime;
TimeElapsed = Results.timeElapsed;
TestName = Results.testName;
}
Within my test harness I created an exact copy of the struct that I have within my webdriver DLL. Here it is:
public struct Results
{
public static string testName { get; set; }
public static int result { get; set; }
public static DateTime startTime { get; set; }
public static DateTime endTime { get; set; }
public static TimeSpan timeElapsed { get; set; }
public static string testFile { get; set; }
}
So my overall question here is why doesnt the struct called myResult have the same values as the one returned from the method I called? Ive tried debugging the DLL and its returning the struct like its supposed to, so my assumption is that its an error with the code above.
To highlight what I;m trying to do, all im trying to do is retrieve the struct, I'm not really interested in creating multiple structs etc, I just want to be able to use the data contained within the struct I'm returning from the method.
So I played around with the code and if I do:
Object myObject;
myObject = myResultGetter.Invoke(instance, null);
Then when I add myObject to watch in runtime it contains the correct values! But I need to find someway to get these values into my new struct or class (I don't mind which I use)