Add support for Span and ReadOnlySpan
See original GitHub issueDescription
Add support for Span<T> and ReadOnlySpan<T>. Though they do not directly implement IEnumerable<T>
interface it would be nice to be able to assert using NotContain
etc.
Complete minimal example reproducing the issue
// Arrange
ReadOnlySpan<string> span = new ReadOnlySpan<string>(new[] {"a", "b", "c"});
// Act
span = span.Slice(1);
// Assert
span.Should().NotContain("a");
Expected behavior:
Test should pass.
Actual behavior:
Compilation error saying extension method Should does not exist for ReadOnlySpan<T>.
Versions
- Which version of Fluent Assertions are you using? 5.4.1
- Which .NET runtime and version are you targeting? .NET Core 2.1.
Issue Analytics
- State:
- Created 5 years ago
- Comments:15 (11 by maintainers)
Top Results From Across the Web
C# - All About Span: Exploring a New .NET Mainstay
In support of Span<T> and friends, hundreds of new members and types are being added across .NET. Many of these are overloads of...
Read more >Writing High-Performance Code Using Span<T> and ...
In this article, you'll be introduced to the new types introduced in C# 7.2: Span and Memory. I'll take a deep dive into...
Read more >Memory<T> and Span<T> usage guidelines
Span <T> and ReadOnlySpan<T> are lightweight memory buffers that wrap references to managed or unmanaged memory. Because these types can only ...
Read more >c# - Concatenate ReadOnlySpan<char>
I think it's worth mentioning that an overload for concatenating spans was added in .NET Core 3 and that support for .
Read more >Improve C# code performance with Span<T>
Let's use Span<T> to obtain an array of uint from the string "163,496,691,1729" . ... The method uint.Parse(ReadOnlySpan<char>) shows that it's ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Everyone who has shown interest in assertions on
Span
.Here’s an example of what we can do without converting
[ReadOnly]Span<T>
intoT[]
orstring
. It utilizes thatSpan<T>
is implicitly convertible toReadOnlySpan<T>
to avoid duplicatingReadOnlySpanAssertions<T>
.SharpLab
The major downside to that approach is that we would probably have to duplicate a lot of code for a limited benefit.
The easy way out