NightOwl888 opened a new issue, #954: URL: https://github.com/apache/lucenenet/issues/954
### Is there an existing issue for this? - [X] I have searched the existing issues ### Task description Per https://github.com/apache/lucenenet/pull/940#discussion_r1643205431, it would make the code easier to understand if we didn't have to manually check `Queue.Count` every time we want to call `Dequeue()` or `Peek()`. Newer versions of .NET have the methods: - [TryDequeue()](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.queue-1.trydequeue?view=net-8.0#system-collections-generic-queue-1-trydequeue(-0@)) - [TryPeek()](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.queue-1.trypeek?view=net-8.0#system-collections-generic-queue-1-trypeek(-0@)) but they are missing from `netstandard2.0` and .NET Framework. However, if we add them as extension methods, we can both solve the readability issue and also make the call a bit more performant in .NET Core. ## Specifics - File Name: `QueueExtensions.cs` - Location: `src/Lucene.Net/Support/` - Namespace: `Lucene.Net.Support` - Class Name: `QueueExtensions` - Accessibility: `static internal` - Documentation for class: `Extensions to <see cref="Queue"/>.` - Method implementations: Search the codebase for `.Dequeue()` to see an example. We just want to wrap the check for `.Count` inside of the methods. - Both methods should be marked `[MethodImpl(MethodImplOptions.AggressiveInlining)]`. - Both methods should be fully documented - copy the documentation from the above links. - Both extension methods should check for a `null` queue and if the check fails `throw new ArgumentNullException(nameof(queue))`. - The methods should have basic tests in a corresponding file `src/Lucene.Net.Tests/Support/QueueExtensionsTests.cs`. - Add a new feature named `FEATURE_QUEUE_TRYDEQUEUE_TRYPEEK` and set it up in the root `Directory.Build.targets` file to be enabled in `netstandard2.1` and all versions of .NET Core. We should conditionally compile out these extension methods in those cases by putting them inside `#if !FEATURE_QUEUE_TRYDEQUEUE_TRYPEEK` / `#endif` blocks. In a separate Git commit, search the codebase for usage of `Queue` and replace all calls with the extension methods. We don't need any conditional compilation here because we will use the same method signatures. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@lucenenet.apache.org.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org