Question: Result<T,E> with interfaces
MettBeagle opened this issue · comments
MettBeagle commented
Hi,
I'm currently trying to figure out how (and when) to use this library and I'm probably missing something regarding the Result-Type.
Using the sample code below, I'm wondering why the implicit conversion from actual value to the result type doesn't work, when I try to directly return an interface instance. Could someone please explain, why that won't work or if I'm just missing another way to do that?
public class Error { }
public interface ISomething{ }
public class SomeClass : ISomething { }
public class Test
{
public Result<SomeClass, Error> Works(SomeClass data)
=> data;
public Result<ISomething, Error> Works(ISomething data)
=> Result.Success<ISomething, Error>(data);
public Result<ISomething, Error> Breaks(ISomething data)
=> data;
}
Thanks!
Sviataslau Hankovich commented
Hi, this is a C# limitation. Please check this question for details.