I have a class called Structure<A, E, B, V, K>
which inherits a generic method FireEdges<TA, TE, TB, TV, TK>(Func<TE, TK> transformer)
through an interface.
I would like to run different code depending on whether the types passed to FireEdges
match the instance types or not.
For example, if I have:
Structure<int, int, int, int, int> s = new ...
Then if I call s.FireEdges<int, int, int, int, int>(Func<int, int> transformer)
it should run separate code than if I were to call s.FireEdges<A, B, C, D, E>(Func<B, E> transformer)
, for example.
To do this I've tried doing something like this:
public override void FireEdges<TA, TE, TB, TV, TK>(Func<TE, TK> transformer) {
if (typeof(TE) == typeof(E) && ... ) //Check other types too
foreach (E e in Edges)
e.Target.Data = transformer(e);
else
//Do something else since not all types match
}
I am getting this error :
Argument type 'E' is not assignable to parameter type 'TE'
even though I'm only trying to assign after checking they are indeed the same type.
Clearly I'm doing something very wrong, but I have no idea what it could be.
Thanks