-
Notifications
You must be signed in to change notification settings - Fork 22
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
Generic math #15
Generic math #15
Conversation
Important: Removed all target frameworks except .NET 7. Removed `stackalloc`, because it is impossible to use it with T.
`sizeof(T)` is impossible, so `sizeof(long)` was chosen as a fallback.
Thank you, @Arasfon
It's better to preserve support for older frameworks while having them only support |
See the docs. #if NET7_0_OR_GREATER
public T[] Decode(string id) => Decode(id.AsSpan());
#else
public int[] Decode(string id) => Decode(id.AsSpan());
#endif |
Generic math only for .NET 7 or later, and previous implementation for other frameworks.
@aradalvand, Check latest commit, everything is under preprocessor directives now. |
@Arasfon Great, thanks! |
@aradalvand I have added tests for both single and multiple numbers. Check them out |
Added because it depends on SqidsEncoder.
I wonder if source generators would be a better way to accomplish this? Then we could output only |
This isn't really the type of scenario you would use source generators for. That would introduce far too much complexity for something that simple preprocessor directives are currently accomplishing. And we already are reusing most of the code; so that's not a concern. |
Works only with .NET 7 TFM.
Why: All frameworks older than .NET 7 do not support generic math in any way as far as I know as I said in #11.
Replaced
sizeof(int)
withsizeof(long)
instackalloc
bounds calculation, because it is impossible to calculatesizeof(T)
withoutunsafe
. However ifunsafe
is not a bad thing to add,sizeof(T)
can be added.