Oyvind Andersson
Oyvind Andersson

Reputation: 362

Generic class with two type constraints, and a interface implementation

I've stumbled upon a small problem. I'm trying to declare a generic class that has two constraints and it should also implement an interface. The problem however, is that when I try to get the interface in the declaration, it is just considered a constraint of one of the two generics. As seen here:

public class T_AccountControl<T, U>
    where U : T_AccountView
    where T : T_AccountModel, IAccountControl

{ ... }

I want T_AccountControl<> to implement IAccountControl. Atm it is just in the chain of constraints to T. I've tried to paste it in before and such, but it does not seem to work.

So, can I do this? Or is it for some alternate reason not allowed?

Regards, Oyvind

Upvotes: 0

Views: 106

Answers (1)

Neil Smith
Neil Smith

Reputation: 2565

Implement IAccountControl before the constraints:

public class T_AccountControl<T, U> : IAccountControl
    where U : T_AccountView
    where T : T_AccountModel

Edit: Just noticed where you said you tried to "paste it before and such". Not sure what you did but you probably had a small error because this should work for you.

Upvotes: 2

Related Questions