Comments (8)
Thanks for bringing this to my attention. I hadn't seen this yet. I'll look to implement in the next release along with all the handle changes. If you have time to do a PR for this, I'd be very appreciative.
from vanara.
Did you use IConvertible in other places where thr meaning was unmanaged constraint ?
from vanara.
I tried to follow the pattern using struct, IConvertible
constraints whenever specifying enum
or number types. I used the struct
constraint and exceptions when looking for blittable types.
from vanara.
In this particular BitHelper extension, I was attempting to constrain to the set of items that could be converted to a number.
from vanara.
So BitHelper definitely should use unmanaged to cover all blittable types.
As for enum there is Enum constraint in C# 7.3 and interesting workaround in older version.
https://stackoverflow.com/a/28527552
from vanara.
Actually if I understand correctly BitHelper is intended for types smaller or equal than Int64 ?
Is it correct ?
If yes, then a correct answer is to just have overloads for all primitive types and not using IConvertible.
In case you say it is too much code to write, just use T4.
See how CodeJam uses it to generate all required overloads: https://github.com/rsdn/CodeJam/blob/master/Main/src/Algorithms/Algorithms.EqualRange.tt
from vanara.
There is also possible NRE since you can pass null in 'bits' parameter.
from vanara.
To simplify and help make more foolproof, I have extended the list of constraints to struct, IComparable, IComparable<T>, IConvertible, IEquatable<T>, IFormattable
in 2.0. Not perfect, but better.
from vanara.
Related Issues (20)
- ShellItemImages.GetImageAsync might throw NullReferenceException HOT 3
- Using char[] in place of StringBuilder HOT 2
- DPI_AWARENESS_CONTEXT enum values missing HOT 2
- Can't use the handle to read vhdx HOT 2
- `HRESULT.ToString()` is not thread-safe due to mutable global state. HOT 2
- Usage of `LibraryImport` instead of `DllImport` HOT 1
- RtlGetVersion not found in NtDll HOT 6
- A great project! HOT 1
- #nullableenabled brunch is not being merged into master HOT 4
- Kernel32.FILE_ID_128.Identifier returns incorrect values
- [Bug] MB_GetString make exe crashed and ExitCode is 3221226356 (0xc0000374) HOT 2
- RobiniaDocs API Explorer HOT 1
- Can not GetLastError HOT 1
- CM_REGISTER_NOTIFICATION callback: Incomplete eventData.u.DeviceInstance.InstanceId HOT 2
- FindNextPrinterChangeNotification SafePRINTER_NOTIFY_INFO is invalid HOT 2
- missing definition for StorageDeviceSeekPenalty. HOT 1
- [Bug] GetRawInputDeviceInfo can not use CharSet = CharSet.Auto HOT 4
- Interface not supported Exception while using the set operaiton in IMAPI HOT 2
- User32.GetWindowLongAuto throws an exception if result is 0 HOT 1
- OverlappedAsyncBaseResult does not make processed bytes available. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vanara.