Skip to content

Commit f1421a4

Browse files
committed
AsResult
1 parent dfa20ee commit f1421a4

10 files changed

Lines changed: 42 additions & 20 deletions

File tree

Directory.Build.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
<RepositoryUrl>https://github.com/managedcode/Communication</RepositoryUrl>
2525
<PackageProjectUrl>https://github.com/managedcode/Communication</PackageProjectUrl>
2626
<Product>Managed Code - Communication</Product>
27-
<Version>8.0.3</Version>
28-
<PackageVersion>8.0.3</PackageVersion>
27+
<Version>8.0.4</Version>
28+
<PackageVersion>8.0.4</PackageVersion>
2929

3030
</PropertyGroup>
3131
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">

ManagedCode.Communication.Orleans/Converters/CommandSurrogateConverter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using ManagedCode.Communication.Extensions;
12
using ManagedCode.Communication.Surrogates;
23
using Orleans;
34

@@ -13,6 +14,6 @@ public Command ConvertFromSurrogate(in CommandSurrogate surrogate)
1314

1415
public CommandSurrogate ConvertToSurrogate(in Command value)
1516
{
16-
return new CommandSurrogate(value.Id, value.CommandType);
17+
return new CommandSurrogate(value.CommandId, value.CommandType);
1718
}
1819
}

ManagedCode.Communication.Orleans/Converters/CommandTSurrogateConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ public Command<T> ConvertFromSurrogate(in CommandTSurrogate<T> surrogate)
1313

1414
public CommandTSurrogate<T> ConvertToSurrogate(in Command<T> value)
1515
{
16-
return new CommandTSurrogate<T>(value.Id, value.CommandType, value.Value);
16+
return new CommandTSurrogate<T>(value.CommandId, value.CommandType, value.Value);
1717
}
1818
}

ManagedCode.Communication.Tests/Commands/CommandTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public void FromValue()
1616
public void FromIdValue()
1717
{
1818
var command = Command<string>.From(nameof(CommandTests), nameof(Command));
19-
command.Id.Should().Be(nameof(CommandTests));
19+
command.CommandId.Should().Be(nameof(CommandTests));
2020
command.Value.Should().Be(nameof(Command));
2121
}
2222
}

ManagedCode.Communication/Command/Command.From.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace ManagedCode.Communication;
66

7-
public partial struct Command
7+
public partial class Command
88
{
99
public static Command<T> From<T>(string id, T value)
1010
{

ManagedCode.Communication/Command/Command.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
namespace ManagedCode.Communication;
66

77
[Serializable]
8-
[DebuggerDisplay("Id: {Id}")]
9-
public partial struct Command : ICommand
8+
[DebuggerDisplay("CommandId: {CommandId}")]
9+
public partial class Command : ICommand
1010
{
11-
internal Command(string id, string commandType)
11+
internal Command(string commandId, string commandType)
1212
{
13-
Id = id;
13+
CommandId = commandId;
1414
CommandType = commandType;
1515
}
1616

17-
public string Id { get; set; }
17+
public string CommandId { get; set; }
1818
public string CommandType { get; set; }
1919
}

ManagedCode.Communication/Command/CommandT.From.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace ManagedCode.Communication;
66

7-
public partial struct Command<T>
7+
public partial class Command<T>
88
{
99
public static Command<T> From(string id, T value)
1010
{

ManagedCode.Communication/Command/CommandT.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@
66
namespace ManagedCode.Communication;
77

88
[Serializable]
9-
[DebuggerDisplay("Id: {Id}; {Value?.ToString()}")]
10-
public partial struct Command<T> : ICommand<T>
9+
[DebuggerDisplay("CommandId: {CommandId}; {Value?.ToString()}")]
10+
public partial class Command<T> : ICommand<T>
1111
{
12-
internal Command(string id, T? value)
12+
internal Command(string commandId, T? value)
1313
{
14-
Id = id;
14+
CommandId = commandId;
1515
Value = value;
1616
CommandType = Value?.GetType().Name ?? string.Empty;
1717
}
1818

19-
internal Command(string id, string commandType, T? value)
19+
internal Command(string commandId, string commandType, T? value)
2020
{
21-
Id = id;
21+
CommandId = commandId;
2222
Value = value;
2323
CommandType = commandType;
2424
}
2525

26-
public string Id { get; set; }
26+
public string CommandId { get; set; }
2727
public string CommandType { get; set; }
2828

2929
public T? Value { get; set; }
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
3+
namespace ManagedCode.Communication.Extensions;
4+
5+
public static class ResultExtension
6+
{
7+
public static Result<T> AsResult<T>(this T result)
8+
{
9+
return Result<T>.Succeed(result);
10+
}
11+
12+
public static Result<T> AsResult<T>(this Exception exception)
13+
{
14+
return Result<T>.Fail(exception);
15+
}
16+
17+
public static Result AsResult(this Exception exception)
18+
{
19+
return Result.Fail(exception);
20+
}
21+
}

ManagedCode.Communication/ICommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public interface ICommand
99
/// Gets the unique identifier for the command.
1010
/// </summary>
1111
/// <value>The unique identifier for the command.</value>
12-
string Id { get; }
12+
string CommandId { get; }
1313

1414
/// <summary>
1515
/// Gets the type of the command.

0 commit comments

Comments
 (0)