Reputation: 244
I have a mapping class that contains a mapping of custom objects:
public class MappingType
{
public Type source {get;set;}
public Type dest {get;set;}
}
Why is it I can't use them as below (mappinglist
is object of MappingType
)?
IEnumerable<mappinglist[0].source,mappinglist[0].dest> customlist;
What are my options? How can I use it in such context?
Upvotes: 1
Views: 1560
Reputation: 150228
The C# generics system works for types known at compile time. You cannot provide types known only at runtime as type parameters.
Additionally, as @JonSkeet points out, IEnumerable<T>
only takes one type parameter.
If your types have anything in common (shared base class, shared interface) you can use that "thing in common" with generics, e.g.
IEnumerable<ISomeSharedInterface> customList;
If they have nothing in common, you can still use the non-generic IEnumerable
.
Upvotes: 2