I have a common interface:
public interface IUnauthorizedRequestRespondable<out T> where T:class { T GetResponseForUnauthorizedRequest(); }
(I'm not sure why Resharper recommended T "out", but that is not a question).In my script, the object returned GetResponseForUnauthorizedRequestis always of type implementing the interface.
GetResponseForUnauthorizedRequest
So, all interface implementations look like this:
public class SignInReturnedObject : IUnauthorizedRequestRespondable<SignInReturnedObject>
(class name and type in parentheses always match).Which seems a bit inconvenient - is there a tidier way to tell the compiler that the interface method returns the type of which it is part?
Thank.
If the only way you want to use this template would be this way:
public interface IUnauthorizedRequestRespondable<T> where T:IUnauthorizedRequestRespondable<T> { T GetResponseForUnauthorizedRequest(); }
, - .
, . , , .
, # .
. , , self-, #. , , this, , self, , , - :
this
self
public interface IUnauthorizedRequestRespondable { self GetResponseForUnauthorizedRequest(); }
... , self, SignInReturnedObject, SignInReturnedObject, , , #: -)
SignInReturnedObject
, . .
, .NET IEquatable inteface - , .
, , .
, , ,
public interface ICastUnauthorizedRequestRespondable : IUnauthorizedRequestRespondable<SignInReturnedObject> { }
T ( , ), .
public class SignInReturnedObject : IUnauthorizedRequestRespondable<ANYCLASS>
Source: https://habr.com/ru/post/1768984/More articles:An API for implementing document editing and viewing functions for a web application? - c #Edge length in adjacency list - cChanging the type of an object at some point in its life - javamysql: What is the ROW_COUNT () information function for SELECT? - mysqlCATiledLayer: Code Example - iphoneDownload file from java application - javaEnum type with values containing spaces on it - enumsSitecore - создание нового элемента события OnSavingItem перенаправляет оболочку на вновь созданный элемент - sitecoreInheritance in Enterprise Architect - architectureProject Structure jsf 2 - jsf-2All Articles