Introducing Cadru 2.0
- 5 minutes to read
- edit
Just over two years ago, Cadru was released as an open source framework. Since then, there have been numerous changes, improvements, and updates. This latest update includes a lot of new features and, unfortunately, one breaking change.
First up, the breaking change.
In an earlier release, ToRelativeTimeString and ToRelativeDateString methods were added that included a formatting options enum named RelativeDateFormattingOptions. The problem is that this was a plural name for a non-flags enum and it really didn’t portray the meaning of the enum very well. This has been renamed to just RelativeDateFormatting.
Now, for the new features.
A new extension method on IEnumerable has been added called Partition. This takes an IEnumerable and breaks it up into smaller collections of equal size. If there aren’t enough elements to fully populate the final partition, it’s the size of the number of elements.
int[] numbers = { 0, 30, 20, 15, 90, 85, 40, 75 };
var partitions = numbers.Partition(3).ToArray();
// partitions[0] = { 0, 30, 20 }
// partitions[1] = { 15, 90, 85 }
// partitions[2] = { 40, 75 }
Next is a simple ReverseComparisonComparer. This takes a given Comparison
The code contracts classes, Requires and Assumes, also gained a method to test if a parameter is of a given type and one to test if it’s an enum.
The Cadru.UnitTest.Framework library also picked up a change by adding a WithInnerException method on ExceptionAssert. This allows you to assert that the inner exception of a thrown exception is a specific exception type.
Enumerated types also gained some new methods. Cadru always had extension methods on enums, one of which was GetDescription, which would return the value of an EnumDescription attribute applied to an enum member. When the strongly typed Enum
Finally, and probably the biggest addition to this release, is support for Ranges, through the Range
var range = new Range<char>('a', 'e', RangeEndpointOption.Closed);
range.SetDefaultEnumerator();
var expanded = range.ToList();
// expanded = {'b', 'c', 'd' }
Unit tests and code coverage
Ever since Cadru was first created (long before it became an open source framework), it always had good unit tests and code coverage. I’m very happy that tradition has continued. Even with all of the new changes (about 26 files spread over 15 different commits), I’m still at 89.49% code coverage for the entire library (all 4 projects) and 98.41% code coverage for Cadru.Core where almost all of these changes took place (according to the analysis tools built in to Visual Studio).
Be sure to check out the newest release on NuGet.
Bugs and feature requests
Do you have a bug or a feature request? Please use the issue tracker and search for existing and closed issues. If your problem or request isn’t addressed yet, go ahead and open a new issue.
Contributing
You can also get involved and fork the repository to submit your own pull requests. (More detailed contributor guidelines will be available soon.)