Skip to content

Commit 5213683

Browse files
committed
ResultExtensions
1 parent 38a5e23 commit 5213683

4 files changed

Lines changed: 32 additions & 11 deletions

File tree

Directory.Build.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
<PackageLicenseExpression>MIT</PackageLicenseExpression>
1414
<PackageReadmeFile>README.md</PackageReadmeFile>
1515
<Product>Managed Code - Communication</Product>
16-
<Version>0.0.1</Version>
17-
<PackageVersion>0.0.1</PackageVersion>
16+
<Version>0.0.2</Version>
17+
<PackageVersion>0.0.2</PackageVersion>
1818
</PropertyGroup>
1919
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
2020
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>

ManagedCode.Communication.Tests/ManagedCode.Communication.Tests.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
2+
33
<PropertyGroup>
44
<TargetFramework>net6.0</TargetFramework>
55
<EnableNETAnalyzers>true</EnableNETAnalyzers>
@@ -17,10 +17,10 @@
1717
</None>
1818
</ItemGroup>
1919
<ItemGroup>
20-
<PackageReference Include="FluentAssertions" Version="6.5.1" />
21-
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
22-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
23-
<PackageReference Include="xunit" Version="2.4.1" />
20+
<PackageReference Include="FluentAssertions" Version="6.5.1"/>
21+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0"/>
22+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0"/>
23+
<PackageReference Include="xunit" Version="2.4.1"/>
2424
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
2525
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2626
<PrivateAssets>all</PrivateAssets>
@@ -36,7 +36,7 @@
3636
</ItemGroup>
3737

3838
<ItemGroup>
39-
<ProjectReference Include="..\ManagedCode.Communication\ManagedCode.Communication.csproj" />
39+
<ProjectReference Include="..\ManagedCode.Communication\ManagedCode.Communication.csproj"/>
4040
</ItemGroup>
4141

4242
</Project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Threading.Tasks;
2+
3+
namespace ManagedCode.Communication;
4+
5+
public static class ResultExtensions
6+
{
7+
public static Result<T> ToSucceededResult<T>(this T value)
8+
{
9+
return new Result<T>(true, value, ResultState.Success);
10+
}
11+
12+
public static Task<Result<T>> AsTask<T>(this Result<T> value)
13+
{
14+
return Task.FromResult(value);
15+
}
16+
17+
public static Task<Result> AsTask(this Result value)
18+
{
19+
return Task.FromResult(value);
20+
}
21+
}

ManagedCode.Communication/ResultT.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ public static Result<T> Succeeded(T content, ResultState status = ResultState.Su
2525
return new Result<T>(true, content, status);
2626
}
2727

28-
public static Result<T> Failed(ResultState status, Exception? error = null)
28+
public new static Result<T> Failed(ResultState status, Exception? error = null)
2929
{
3030
return new Result<T>(error, status);
3131
}
3232

33-
public static Result<T> Failed(Exception? error, ResultState status = ResultState.Failed)
33+
public new static Result<T> Failed(Exception? error, ResultState status = ResultState.Failed)
3434
{
3535
return new Result<T>(error, status);
3636
}
3737

38-
public static Result<T> Failed()
38+
public new static Result<T> Failed()
3939
{
4040
return new Result<T>(null, ResultState.Failed);
4141
}

0 commit comments

Comments
 (0)