-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
System.Range package similar to System.ValueTuple #28285
Comments
You can use multi-targeting. So you have a code path for .NET Core 3.0 and one for .NET Standard 2.0. |
@gfoidl how would that work? I'd still need a If you are proposing to drop range indexing for .NET Standard 2.0, then that's exactly what I want to avoid. |
I meant the latter, and don't know a better way. |
/cc @terrajobst |
@tarekgh can you PTAL |
@lostmsu Index and Range are not in netstandard 2.0. These types will be in netstandard 2.1. You may look at dotnet/standard#1018. |
@tarekgh , yes, and that is the nature of the problem. The indexing feature of C# 8 will be unusable on .NET Framework. |
It's not just the indexing feature of C# 8 being available on .NET Framework that I'm concerned about. (There are other C# 8 features that flat out won't ever work on .NET Framework 4.8. See Building C# 8.0 Blog). But the core issue here is that you can't have a For example, in the To expose the All of these problems would be solved if we had a common type that encapsulated these semantics. And we do have the type, we just aren't allowing libraries less than |
Any updates on a package for |
In lieu of an official solution, I created my own unofficial one last month: |
@terrajobst @jaredpar do we have the final call on that? |
Also looking forward to a "backport" NuGet package for ranges in .NET Standard 2.0, just like And here I wondered why I never get code style hints by VS for starting to use ranges... was because I also target classic .NET Framework... 👀 |
ping @terrajobst can you please take a look? |
I've recently discussed this. The problem is this:
One could maybe argue that (1) is a thing of the past as .NET Framework 4.7 includes it in-box (and we generally recommend to be on 4.7.2 to consume .NET Standard 2.0 binaries). We should test this, but I think an OOB for range seems doable. @ericstj any other concerns? |
I think we've created a pattern with the Microsoft.Bcl additions that solves the technical problems. I briefly looked at @bgrainger's solution and it follows this pattern. There is still the annoyance that the entire stack needs to target the framework with the component inbox to eliminate the need for the package, for example #35984. |
That's still actual problem. Any chance to make this happens? |
@DjArt I've just backported a library from .NET 6.0 to .NET Standard 2.0, and one of the things I had to re-add was System.Range. Long story short:
This seemed to do the trick for my relatively simple use case (get a string's characters except for the very first and very last, with |
I wouldn't hesitate to use @bgrainger's package in an app, but as a library author, I'm more concerned about the likelihood of downstream conflicts if I were to take a dependency on it. Not being an 'official' package, it doesn't show up in places like https://apisof.net/, making it more likely a similar third-party shim or a copy/paste of the BCL source might end up in a consuming project alongside my transitive dependency. It would be really nice to see an 'official' package for this, if only to avoid such conflicts. |
@terrajobst @ericstj bump. |
This would be a huge help. I have legacy apps I still need to patch from time to time, and the ability to use one code base for both legacy and modern .NET apps is a lifesaver. I want to adapt to the newer syntax elements but them not being supported in older SDKs makes adoption very complicated. |
So I'm guessing this probably isn't coming? It's been a year since any activity here. |
@gregsdennis the abovementioned package |
@lostmsu I'm in the same boat as @saucecontrol. I'm building a library, and I have to consider downstream impacts. |
@gregsdennis @saucecontrol can’t you use |
You can't if you expose public APIs with Index or Range arguments, which I do, but FWIW I have been using the IndexRange package for over a year with no reported issues. |
Since it's not yet mentioned here, if you need Index/Range only for internal use (not exposing in public API surface), PolySharp includes those types, along with polyfills for the attribute types required to support modern C# features downlevel. PolySharp can also make its generated Index/Range public, but then each project's definition of them is distinct. For public APIs, I'd still recommend the IndexRange package, as those types can be shared between projects. |
As of .NET 9.0 release last month this package is now available publicly as Microsoft.BCL.Memory for those who were previously waiting on this please give it a try. |
My understanding is
System.Range
andSystem.Index
are going to be .NET Core 3.0 specific features.That prevents me from creating a library, that targets .NET Standard 2.0 (for I need to support .NET 4.7), and implements range indexers for the types defined in it.
I think it is a huge problem, especially considering the next .NET Standard is not going to be implemented by .NET 4.8.
Are there any plans to deal with it?
Is the problem in the desire to implement range-based indexing for the core types like
System.Array
? If so, are there ways to work around that? Can .NET Core 3.0 instead defineSystem._Range
, and have hypothetical System.Range package implementing an implicit conversionSystem._Range
->System.Range
? Any other alternatives?The text was updated successfully, but these errors were encountered: