Code Monkey home page Code Monkey logo

Comments (8)

dahall avatar dahall commented on August 28, 2024

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.

NN--- avatar NN--- commented on August 28, 2024

Did you use IConvertible in other places where thr meaning was unmanaged constraint ?

from vanara.

dahall avatar dahall commented on August 28, 2024

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.

dahall avatar dahall commented on August 28, 2024

In this particular BitHelper extension, I was attempting to constrain to the set of items that could be converted to a number.

from vanara.

NN--- avatar NN--- commented on August 28, 2024

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.

NN--- avatar NN--- commented on August 28, 2024

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.

NN--- avatar NN--- commented on August 28, 2024

There is also possible NRE since you can pass null in 'bits' parameter.

from vanara.

dahall avatar dahall commented on August 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.