Skip to content

Commit

Permalink
Allow empty IdSpan (#9175)
Browse files Browse the repository at this point in the history
  • Loading branch information
ReubenBond authored Oct 14, 2024
1 parent 2bfd15d commit f93e742
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 10 deletions.
6 changes: 5 additions & 1 deletion src/Orleans.Core.Abstractions/IDs/ClientGrainId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ namespace Orleans.Runtime
/// <summary>
/// Creates a new <see cref="ClientGrainId"/> instance.
/// </summary>
public static ClientGrainId Create(string id) => Create(IdSpan.Create(id));
public static ClientGrainId Create(string id)
{
ArgumentNullException.ThrowIfNullOrWhiteSpace(id);
return Create(IdSpan.Create(id));
}

/// <summary>
/// Creates a new <see cref="ClientGrainId"/> instance.
Expand Down
6 changes: 5 additions & 1 deletion src/Orleans.Core.Abstractions/IDs/GrainId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ private GrainId(SerializationInfo info, StreamingContext context)
/// <summary>
/// Creates a new <see cref="GrainType"/> instance.
/// </summary>
public static GrainId Create(GrainType type, string key) => new GrainId(type, IdSpan.Create(key));
public static GrainId Create(GrainType type, string key)
{
ArgumentNullException.ThrowIfNullOrWhiteSpace(key);
return new GrainId(type, IdSpan.Create(key));
}

/// <summary>
/// Creates a new <see cref="GrainType"/> instance.
Expand Down
6 changes: 5 additions & 1 deletion src/Orleans.Core.Abstractions/IDs/GrainInterfaceType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ namespace Orleans.Runtime
/// <summary>
/// Creates a <see cref="GrainInterfaceType"/> instance.
/// </summary>
public GrainInterfaceType(string value) => _value = IdSpan.Create(value);
public GrainInterfaceType(string value)
{
ArgumentNullException.ThrowIfNullOrWhiteSpace(value);
_value = IdSpan.Create(value);
}

/// <summary>
/// Creates a <see cref="GrainInterfaceType"/> instance.
Expand Down
6 changes: 5 additions & 1 deletion src/Orleans.Core.Abstractions/IDs/GrainType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ private GrainType(SerializationInfo info, StreamingContext context)
/// <returns>
/// The newly created <see cref="GrainType"/> instance.
/// </returns>
public static GrainType Create(string value) => new GrainType(Encoding.UTF8.GetBytes(value));
public static GrainType Create(string value)
{
ArgumentNullException.ThrowIfNullOrWhiteSpace(value);
return new GrainType(Encoding.UTF8.GetBytes(value));
}

/// <summary>
/// Converts a <see cref="GrainType"/> to a <see cref="IdSpan"/>.
Expand Down
7 changes: 1 addition & 6 deletions src/Orleans.Core.Abstractions/IDs/IdSpan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,7 @@ private IdSpan(SerializationInfo info, StreamingContext context)
/// <returns>
/// A new <see cref="IdSpan"/> corresponding to the provided id.
/// </returns>
/// <exception cref="ArgumentException"/>
public static IdSpan Create(string id)
{
ArgumentException.ThrowIfNullOrWhiteSpace(id, nameof(id));
return new IdSpan(Encoding.UTF8.GetBytes(id));
}
public static IdSpan Create(string id) => new(Encoding.UTF8.GetBytes(id));

/// <summary>
/// Returns a span representation of this instance.
Expand Down
2 changes: 2 additions & 0 deletions src/Orleans.Core/Core/GrainFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public TGrainInterface GetGrain<TGrainInterface>(long primaryKey, string grainCl
public TGrainInterface GetGrain<TGrainInterface>(string primaryKey, string grainClassNamePrefix = null)
where TGrainInterface : IGrainWithStringKey
{
ArgumentNullException.ThrowIfNullOrWhiteSpace(primaryKey);
var grainKey = IdSpan.Create(primaryKey);
return (TGrainInterface)GetGrain(typeof(TGrainInterface), grainKey, grainClassNamePrefix: grainClassNamePrefix);
}
Expand Down Expand Up @@ -164,6 +165,7 @@ public IGrain GetGrain(Type grainInterfaceType, long key)
/// <inheritdoc />
public IGrain GetGrain(Type grainInterfaceType, string key)
{
ArgumentNullException.ThrowIfNullOrWhiteSpace(key);
var grainKey = IdSpan.Create(key);
return (IGrain)GetGrain(grainInterfaceType, grainKey, grainClassNamePrefix: null);
}
Expand Down

0 comments on commit f93e742

Please sign in to comment.