V
Vin
Hi,
I just wanted to check if I am missing something or if what I am
looking for isn't possible.
I have a function with 2 generic parameter types, one of these occurs
in the argument list the other doesn't.
So the function is like this:
void CreateEntities<T, IT>(IList<IT> entities){}
I'd like to be able to call it as follows:
IList<IMyType> entities = new List<IMyType>();
CreateEntities<MyType>(entities);
So 'IT' would be deduced as 'IMyType' and 'T' is explicitly set to
'MyType'.
The reasoning behind this is that in the function I will do the
following
entities.Add(new T());
I haven't been able to get this syntax to work.
I have to have:
CreateEntities<MyType, IMyType>(entities);
If I change the function to take an extra useless parameter of type
'MyType' it'll deduce the arguments.
So this will work:
void CreateEntities<T, IT>(IList<IT> entities, T t){}
CreateEntities(entities, new MyType());
but clearly that isn't a useful option.
So is it possible for the compiler to deduce one parameter type or is
it all or none?
Thanks, Vin
I just wanted to check if I am missing something or if what I am
looking for isn't possible.
I have a function with 2 generic parameter types, one of these occurs
in the argument list the other doesn't.
So the function is like this:
void CreateEntities<T, IT>(IList<IT> entities){}
I'd like to be able to call it as follows:
IList<IMyType> entities = new List<IMyType>();
CreateEntities<MyType>(entities);
So 'IT' would be deduced as 'IMyType' and 'T' is explicitly set to
'MyType'.
The reasoning behind this is that in the function I will do the
following
entities.Add(new T());
I haven't been able to get this syntax to work.
I have to have:
CreateEntities<MyType, IMyType>(entities);
If I change the function to take an extra useless parameter of type
'MyType' it'll deduce the arguments.
So this will work:
void CreateEntities<T, IT>(IList<IT> entities, T t){}
CreateEntities(entities, new MyType());
but clearly that isn't a useful option.
So is it possible for the compiler to deduce one parameter type or is
it all or none?
Thanks, Vin