Answer the question
In order to leave comments, you need to log in
Connecting a DLL in C#: Run through IList
Hello.
Trying to implement modularity in the program, I ran into a small problem.
The function that I call is in the dll and returns the IList<User> type, and the program that connects the dll using Assembly does not know anything about the type, it only knows that this is a list and it has 3 elements.
How to run through them?
In other words, how to get the ID and login of each element of the list, what are the options to do this?
Thanks in advance.
Answer the question
In order to leave comments, you need to log in
With Reflection
foreach (object value in returned)
{
var id = value.GetType().GetProperty("Id").GetValue(value, null);
var login = value.GetType().GetProperty("Login").GetValue(value, null);
}
foreach (dynamic item in (dynamic)returned) {
string login = item.Login;
}
It can be made easier and more secure.
class User {
public GUID Id {get;set;}
public string Login {get;set;}
}
interface ITestInterface
{
IList<User> GetList();
}
Activator.CreateInstance(type) as ITestInterface;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question