Skip to content

Commit 7744acc

Browse files
committed
fix "fromBytes" logic to be more formal, and more importantly: to keep Nick happy
1 parent 6803031 commit 7744acc

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

eng/StackExchange.Redis.Build/AsciiHashGenerator.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,26 @@ private static string GetRawValue(string name, AttributeData? asciiHashAttribute
211211

212212
var arg = method.Parameters[0];
213213
if (arg is not { IsOptional: false, RefKind: RefKind.None or RefKind.In or RefKind.Ref or RefKind.RefReadOnlyParameter }) return default;
214+
215+
static bool IsBytes(ITypeSymbol type)
216+
{
217+
// byte[]
218+
if (type is IArrayTypeSymbol { ElementType: { SpecialType: SpecialType.System_Byte } })
219+
return true;
220+
221+
// Span<byte> or ReadOnlySpan<byte>
222+
if (type is INamedTypeSymbol { TypeKind: TypeKind.Struct, Arity: 1, Name: "Span" or "ReadOnlySpan",
223+
ContainingNamespace: { Name: "System", ContainingNamespace.IsGlobalNamespace: true },
224+
TypeArguments: { Length: 1 } ta }
225+
&& ta[0].SpecialType == SpecialType.System_Byte)
226+
{
227+
return true;
228+
}
229+
return false;
230+
}
231+
214232
var fromType = arg.Type.ToDisplayString(SymbolDisplayFormat.CSharpErrorMessageFormat);
215-
bool fromBytes = fromType is "byte[]" || fromType.EndsWith("Span<byte>");
233+
bool fromBytes = IsBytes(arg.Type);
216234
var from = (fromType, arg.Name, fromBytes, arg.RefKind);
217235

218236
arg = method.Parameters[1];

0 commit comments

Comments
 (0)