Comments (4)
Good Q, but I do think it was convenience to not have to invoke the ensure with (int)myLong
What's funnier though (just noticed) is the array version... it does not use LongLength
for that overload.
from ensure.that.
Woah, I didn't even know LongLength
was a thing. I guess we really do have lots of memory these days! I hope not many people are using this, sad LOH allocations 😞.
What would you like to see here?
- Obviously we can update the array version to
LongLength
(given the next few items) - Should an IEnumerable version be exposed? (with comment & [InstantHandle] annotation to signal that it will actually enumerate it - unless )
- I'd personally recommend not doing this because it's unlikely IMO that a user actually wants to enumerate such a sequence, especially more than once
- Array seems to be the only exposed way of getting a long count in O(1) time in the current BCL, unless I am missing something
- Should we continue to expose a
long
version?- I'd tentatively say yes after further thinking, but wanteto make sure there is a discussion/thought here. See example below.
// Example supporting the long version
void Example()
{
var collection = new[] { 1, 2 };
Console.WriteLine("How many items do you demand to have in the collection?");
long input = long.Parse(Console.ReadLine());
// Here we have 1 of 3 behaviors
// Option 1: we throw ArgumentOutOfRangeException
// Option 2 (they have to cast): if they are unchecked{} - they get off values like wrapping around if the input is in the > int.MaxValue
// Option 3 (they have to cast): if they are checked{} - they get an OverflowException
Ensure.That(collection).SizeIs(input);
}
from ensure.that.
So my suggestion would be to correct the Array version, leave the long version, and omit adding an IEnumerable version (e.g. make sure all exposed versions right now won't accept IEnumerable but only ICollection/IList)
from ensure.that.
Good morning. I agree to the last comment. IEnumerable overloads should not be added even if attributes can help with discoverability. Keep the long for convenience and correct array.
from ensure.that.
Related Issues (20)
- Breaking change from 8.1.2 to 8.2.0 HOT 4
- EnsureArg.IsNotNull without class requirement HOT 7
- Add the ability to check that a string is made up of a certain type of character(s) HOT 4
- Please add TimeSpan Lt, Gt, etc
- StringParam.* SizeIs and HasLengthBetween are congruent methods, but have inconsistent naming style HOT 2
- Ensure.That(enumerable).HasItems() HOT 3
- Return Guid from string.IsGuid
- EnsureArg.IsNotNull for nullable value type HOT 9
- Default exception factory takes account of CustomExceptionFactory for ArgumentNullException only HOT 1
- Drop support for .NET 4.5.1 and .NET Standard 1.1 HOT 5
- CollectionArg methods disregard optsFn for null checks HOT 6
- Use Scope instead of argument passing of Options HOT 5
- Digitally signed assemblies HOT 8
- No more OPTS
- Fix S4144 in AnyArg
- Enable analyzers
- Chaining clauses HOT 6
- Change InvokerParameterNameAttribute to CallerMemberNameAttribute HOT 3
- Use CallerArgumentExpression attribute to capture parameter name HOT 2
- Missing validation for double and float against NaN 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 ensure.that.