Skip to content

Commit

Permalink
Added setter to ValueType. (ardalis#46)
Browse files Browse the repository at this point in the history
* Added setter to ValueType.

* Set ValueType if value not null.

* Value.GetType removed from private Result(ResultStatus status).

* Result to be partial.

* Partial removed from Result

* ClearValueType and ValueType private set.

Co-authored-by: Steve Smith <[email protected]>
  • Loading branch information
ShadyNagy and ardalis authored Sep 4, 2020
1 parent ac5e391 commit f500b6a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Ardalis.Result/Ardalis.Result.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<Summary>A simple package to implement the Result pattern for returning from services.</Summary>
<RepositoryUrl>https://github.com/ardalis/result</RepositoryUrl>
<PackageTags>result pattern web api aspnetcore mvc</PackageTags>
<PackageReleaseNotes>Updating icon to remove deprecated PackageIconUrl</PackageReleaseNotes>
<Version>3.0.1</Version>
<PackageReleaseNotes>Added setter to ValueType</PackageReleaseNotes>
<Version>3.0.2</Version>
<AssemblyName>Ardalis.Result</AssemblyName>
<PackageIcon>icon.png</PackageIcon>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
Expand Down
12 changes: 10 additions & 2 deletions src/Ardalis.Result/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ public class Result<T> : IResult
public Result(T value)
{
Value = value;
if (Value != null)
{
ValueType = Value.GetType();
}

}
private Result(ResultStatus status)
{
Expand All @@ -18,11 +23,14 @@ private Result(ResultStatus status)
public static implicit operator Result<T>(T value) => Success(value);

public T Value { get; }
public Type ValueType => Value.GetType();

public Type ValueType { get; private set; }
public ResultStatus Status { get; } = ResultStatus.Ok;
public IEnumerable<string> Errors { get; private set; } = new List<string>();
public List<ValidationError> ValidationErrors { get; private set; } = new List<ValidationError>();

public void ClearValueType() => ValueType = null;

public object GetValue()
{
return this.Value;
Expand Down Expand Up @@ -51,6 +59,6 @@ public static Result<T> NotFound()
public static Result<T> Forbidden()
{
return new Result<T>(ResultStatus.Forbidden);
}
}
}
}

0 comments on commit f500b6a

Please sign in to comment.