Allow this keyword to be used as type argument #7647
Unanswered
martinrhan
asked this question in
Language Ideas
Replies: 2 comments
-
That's interesting. And what about public this WithArgs(string[] args) {
// ...
return this;
} And for type parameter like internal interface IResponse<TResponse, TData>
where TResponse : this, new()
{
TData? Data { get; set; }
string Message { get; set; }
bool Success { get; set; }
abstract static implicit operator TResponse(TData data);
abstract static implicit operator TData?(TResponse response);
}
public class ServiceResponse<T> : IResponse<this, T>
{
public T? Data { get; set; }
public bool Success { get; set; } = true;
public string Message { get; set; } = string.Empty;
public static implicit operator ServiceResponse<T>(T data) => new() { Data = data };
public static implicit operator T?(ServiceResponse<T> response) => response.Data;
} I don't really favor this, I don't think csharp will add much implicit stuff. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
We usually have something like this
Dependency property is a good example as well. Even with code snippet we still need to manually write down 'MyClass'. It is going to be nice if we can write
Beta Was this translation helpful? Give feedback.
All reactions