Skip to content

Commit

Permalink
Сделал неявное приведение ErrorInfo к ModelResult
Browse files Browse the repository at this point in the history
  • Loading branch information
rgaynetdinov committed Feb 27, 2024
1 parent 32827a8 commit ad3a7c8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ModelResult/ModelResults/ErrorModelResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public ErrorModelResult(string code, string message, ErrorInfoItem[]? items = nu

public ErrorInfoItem[] ErrorItems => Error.Items;

public override ModelResultType Type { get; } = ModelResultType.Error;
public override ModelResultType Type => ModelResultType.Error;
}

public class ErrorModelResult<T> : ModelResult<T>
Expand Down
10 changes: 10 additions & 0 deletions src/ModelResult/ModelResults/ModelResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public ErrorModelResult AsError()
}

public ErrorInfo GetError() => AsError().Error;

public static implicit operator ModelResult(ErrorInfo errorInfo)
{
return new ErrorModelResult(errorInfo);
}
}

public abstract class ModelResult<T> : IModelResult<T>
Expand Down Expand Up @@ -93,6 +98,11 @@ public static implicit operator ModelResult<T>(ErrorModelResult modelResult)
return (ErrorModelResult<T>) modelResult;
}

public static implicit operator ModelResult<T>(ErrorInfo errorInfo)
{
return new ErrorModelResult(errorInfo);
}

public bool TryGetResult(out T resultValue)
{
if (IsOk())
Expand Down

0 comments on commit ad3a7c8

Please sign in to comment.