Potential misuse
Closed this issue · 5 comments
md-redwan-hossain commented
The current API allows the following which is not the intended use.
public ErrorOr<string> SendMessage()
{
return new ErrorOr<string>();
}
It must be like this. However the API does not enforces it because struct
must have a default constructor.
public ErrorOr<string> SendMessage()
{
return "Hello";
}
amantinband commented
Thanks Hossain, that's a good point, but as you said, there isn't much we can do about this. I don't want to give up on ErrorOr being a struct since it doesn't allocate memory
md-redwan-hossain commented
you can throw an error if the default constructor is called like the following, this will at least inform the consumer about the misuse.
public ErrorOr()
{
throw new InvalidOperationException("Invoking Parameterless constructor is not allowed.");
}
amantinband commented
added as part of #105
amantinband commented
will be available as part of ErrorOr 3.x