Where T: <interface>, where T: class gives cs0452

I have

public static void SecureTcpRpc<InterfaceType>(string uri, 
                                               Action<InterfaceType> action) 
                                              where InterfaceType : class;

Then I use it here

 private static AuthorizedActionResult 
                RunChannelAction<T>(IEnumerable<string> uris, 
                                    Func<T, AuthorizedActionResult> actionFunc)
                                    where T : IPingable
            {
                    WcfClient.SecureTcpRpc<T>....

The compiler does not like that I limited T to IPingable. I do not understand why this is objective. IPingable is a reference type, so it complies with the restriction on the SecureTpcRpc method. But the compiler says: "T must be a reference type"

+3
source share
2 answers

I think you need a class constraint for the function AuthorizedActionResultto work as well.

where T : class, IPingable
+5
source

Should the second be shared? If this is an interface type, it should be something like this:

private static AuthorizedActionResult RunChannelAction(
  IEnumerable<string> uris, 
  Func<IPingable, AuthorizedActionResult> actionFunc)
        {
                WcfClient.SecureTcpRpc<IPingable>....
+1
source

All Articles