I want to create a class like Nullable except for the moment that it could work with classes and structures:
public class MyWrapper<T>
{
public MyWrapper(T value)
{
Value = value;
}
public T Value { get; set; }
}
Then I want to add implicit conversion of Nullable to MyWrapper:
public static implicit operator MyWrapper<T> (Nullable<T> value)
{
return new MyWrapper<T>(value);
}
And of course, it fails because of Nullable restrictions:
Only non-nullable value type could be underlying of 'System.Nullable'
It is a pretty understandable error but in theory, I could convert any Nullable to MyWrapper, because of restrictions of Nullable harder than MyWrapper's restrictions.
So it there any workaround for Nullable to MyWrapper implicit conversion?
Why do I need to use MyWrapper for classes?
We use some sort of bad GraphQl on the backend and sent updation objects like this:
class UpdateProductRequest
{
public MyWrapper<string> Country {get;set;}
public MyWrapper<string> Title {get;set;}
}
So
new UpdateProductRequest
{
Title = "new title"
}
update the title, but not the country.