Releases: skybrud/Skybrud.Essentials
v1.1.45
Installation
Install via NuGet - either via the .NET CLI:
dotnet add package Skybrud.Essentials --version 1.1.45
or the NuGet package manager:
Install-Package Skybrud.Essentials -Version 1.1.45
Changelog
-
Fixed time zone issues with
EssentialsWeek.GetStartOfWeekandEssentialsWeek.GetEndOfWeekmethods (see c1782ab)
The two methods would return wrong results if theEssentialsWeekinstance wasn't created from theTimeZoneInfoas specified as parameter for the two methods. -
Added utility and extension methods for parsing enum lists (see bf4557d)
This release introduces static utility methods for converting a CSV sting value into a corresponding an array or a list of enum values via theParseEnumArrayandParseEnumListmethods respectively.ToEnumArrayandToEnumListextension methods are now also available to be called directly on a string values. -
Added extension methods for encoding and hashing string values (see ffd61ca)
Skybrud.Essentials already contains a number of staticGet{Algorithm}Hashutility methods. MatchingTo{Algorithm}Hashextension methods have now been added as well allowing them to be called directly on string values.
v1.1.44
Installation
Install via NuGet - either via the .NET CLI:
dotnet add package Skybrud.Essentials --version 1.1.44
or the NuGet package manager:
Install-Package Skybrud.Essentials -Version 1.1.44
Changelog
JSON
-
Internal
JsonTokenUtils.Stringmethod should use invariant culture (see 2e6c476)
The method is used internally in the package for converting aJTokento a string representation, and as such it's important that the method uses an invariant culture instead of the current culture. -
Added
Get{ValueType}OrNullandGet{ValueType}OrNullByPathextension methods to theNewtonsoftJsonObjectExtensionsclass (see 743ba7a)
The new method allows getting nullable value types as an alternative to the default non-nullable value types already in the package.
EssentialsYear
-
Added explicit
StartandEndproperties for theEssentialsYearclass (see cc4bdca)
TheEssentialsYearclass inherits theStartandEndproperties fromEssentialsPeriod, but asEssentialsPeriodon it's own allows the to properties to be null. As a result, the newStartandEndare not nullable as we know them to never be null for anEssentialsYearinstance. -
Added
GetStartOfYearandGetEndOfYearmethods to theEssentialsYearclass (see 2520688)
The two methods getting either the the start or end of the year, according to a specific time zone. -
Added static
MinandMaxmethods to theEssentialsYearclass (see 6e08cbb)
The methods allow finding either the minimum or maximum value of twoEssentialsYearinstances. Method overloads also support specifying multipleEssentialsYearinstances. -
Added
GetStartOfYearandGetEndOfYearmethod overloads to theEssentialsYearclass (see 8783f57)
The two method overloads don't have any paramters, and the returned values will be based on the local time zone.
EssentialsMonth
-
Added explicit
StartandEndproperties for theEssentialsMonthclass (see 02df0a3)
TheEssentialsMonthclass inherits theStartandEndproperties fromEssentialsPeriod, but asEssentialsPeriodon it's own allows the to properties to be null. As a result, the newStartandEndare not nullable as we know them to never be null for anEssentialsMonthinstance. -
Added static
MinandMaxmethods to theEssentialsMonthclass (see 355aa85)
The methods allow finding either the minimum or maximum value of twoEssentialsMonthinstances. Method overloads also support specifying multipleEssentialsMonthinstances. -
Added
GetStartOfMonth,GetStartOfYear,GetEndOfMonthandGetEndOfYearmethods to theEssentialsMonthclass (see fafd25a)
The methods allows finding the start and end of either the month or the year - and based on either the local time zone or a specific time zone. The methods will take daylight savings into account if used by the time zone.
EssentialsWeek
-
Implemented
ToStringmethod in theEssentialsWeekclass (see 5459a90)
TheToStringnow returns an ISO 8601 string representation of the week. -
Added
GetYearmethod to theEssentialsWeekclass (see 2df2c99)
The method returns anEssentialsYearinstance representing the year of the week. -
Added
ParseandTryParsemethods to theEssentialsWeekclass (see ec9c8fd)
The methods allow parsing a ISO 8601 week string representation into an instance ofEssentialsWeek. -
Added static
MinandMaxmethods to theEssentialsWeekclass (see f256ee3)
The methods allow finding either the minimum or maximum value of twoEssentialsWeekinstances. Method overloads also support specifying multipleEssentialsWeekinstances. -
Added
GetStartOfWeekandGetEndOfWeekmethods to theEssentialsWeekclass (see 1cc68c1)
The two methods allows getting theEssentialsTimefor either the start of the week or end of the week respectively.
EssentialsDate
-
Added static
MinandMaxmethods to theEssentialsDateclass (see 13db5d2)
The methods allow finding either the minimum or maximum value of twoEssentialsDateinstances. Method overloads also support specifying multipleEssentialsDateinstances. -
Added static
MinandMaxmethods to theEssentialsTimeclass (see e5b0fb9)
The methods allow finding either the minimum or maximum value of twoEssentialsTimeinstances. Method overloads also support specifying multipleEssentialsTimeinstances.
EssentialsPeriod
- Added
EssentialsPeriodconstructor overload (see afded4a)
The overload takes aTimeZoneInfoinstance as the third parameter to determine the time zone to be used for theStartandEndproperties.
EssentialsWeekRange
- Added
ToString,ParseandTryParsemethods to theEssentialsWeekRangeclass (see #34 and 9fc08fb)
This adds logic for converting aEssentialsWeekRangeto a string and parsing from a string back to aEssentialsWeekRangeinstance.
EssentialsDateRange
v1.1.43
Installation
Install the NuGet package - either via the .NET CLI:
dotnet add package Skybrud.Essentials --version 1.1.43
or the NuGet package manager:
Install-Package Skybrud.Essentials -Version 1.1.43
Changelog
-
Added support for nullable reference types (see b25e281, acbee18)
This includes adding .NET 5 and .NET 6 as additional target frameworks, as they come with extended code analysis functionality out of the box. The Nullable package is added a development dependency to older target frameworks to provide the same code analysis functionality. -
Added additional extension methods for
NameValueCollection(see f0fb6bf)
The .NET Framework versions of this package now features a number of new extension method for reading fromNameValueCollectioninstances - eg.TryGetBoolean,TruGetGuid,TryGetInt32and similar. -
Added additional extension methods for
DateTimeandDateTimeOffset(see 7311284)
TheIsToday,IsTomorrowandIsYesterdayextension methods are now available for bothDateTimeandDateTimeOffset. -
Added static utility methods for working with ISO 8601 durations (see 0cd5538)
The ISO 8601 standard also describes a way to specify durations - eg.PT30Mor evenP1Y2M10DT2H30M. Static methods for converting back and forth between this format andTimeSpanare now available in theIso8601Utilsclass. -
Introduced new extension methods for
JObjectandJArray(see 8e75a29, 24ded82 and 6034cfa)
Skybrud.Essentials have had similar extension methods in theSkybrud.Essentials.Json.Extensionsnamespace for a while now, but the new extension methods are added to clean up the implementation and indicate that they are specifically for Newtonsoft.Json, and they are therefore located in theSkybrud.Essentials.Json.Newtonsoft.Extensionsnamespace. The old extension methods still exist, but will likely be marked as obsolete in a future release.
v1.1.42
Installation
Install the NuGet package - either via the .NET CLI:
dotnet add package Skybrud.Essentials --version 1.1.42
or the NuGet package manager:
Install-Package Skybrud.Essentials -Version 1.1.42
Changelog
Formatting
-
Introduced
StringUtils.FormatFileSizemethods for formatting file size (see #29, 1b15443 and f6acd89)
Depending on the input, file sixes may be formatted using either kilobytes, kibibytes, or a mix of the two. -
Added missing
thiskeyword toToHexStringextension method (see 50f616a)
The method doesn't really work as an extension method without the keyword.
Parsing
-
Added
TryParse{Type}method overloads support a nullable result (see #30, 003a1f8) -
Added
IsBooleanmethod overloads to theStringExtensionsclass (see #30 and 4239551)
The first method overload takes a string as it's only parameter, and returns whether the string value can be parsed and converted into a bool equivalent.The second method overload does the same, but has an additional parameter that uses the "out" keyword to expose the "bool?" value that resulted from the conversion.
-
Added new
TryParseInt32methods to theStringUtilsclass + unit tests (see #30 and 1caee9f)
The new methods provides a culture invariant way to try/parsing integers. -
Introduced new
StringUtils.Parse{Type}Listmethods andStringUtils.To{Type}Listextension methods (see #38 and fc9476d)
This also changes the implementation of the "StringUtils.Parse{Type}Array" methods as they should never have used regular expressions for validating the individual number values. -
Added new
TryParse{Type}methods where necessary (see #30 and 589f87c)
The new methods provides a culture invariant way to try/parsing various simple types. -
Added
Is{Type}method overloads to theStringExtensionsclass (see #30 and fd0b70a)
The methods includeIsBoolean,IsInt32,IsInt64and similar to quickly test whether an input string matches a given simple type.
Enums
- Added
IsBetweenmethods to theEnumUtilsandEnumExtensionsclasses (see #31 and 09556ec)
Similar to elsewhere in the package, roughly the same functionality is implemented as both static utility methods and extensions methods.
XML
-
Updated
XmlUtils.ToStringmethod to set correct encoding in the generated XML declaration (see #37 and 7eab851) -
This ensures that the XML declaration is part of the generated XML string when using the
XmlUtils.ToString(XDocument)method - opposed to the defaultXDocument.ToStringmethod where the XML declaration is omitted. -
Added new
XmlUtils.ToStringmethod overload (see #37 and b4b10e1)
The new overload takes a second parameter of the typeSaveOptions, thereby controlling the format of the generated XML string.
Arrays & Collections
-
Implemented new
ArrayUtils.Empty<T>utility method (see #40 and eb2b19b)
As this package targets multiple frameworks, we can't really useArray.Empty<T>in all of them, so theArrayUtils.Empty<T>provides a way to accomplish the same across all target frameworks. -
Introduced new
RandomOrDefaultandOrderByRandommethods (see #39 and 49fa772)
This adds methods for getting a random item of anIEnumerable<T>as well as sorting aIEnumerable<T>.
Reflection
-
Added
GetVersion,GetFileVersion,GetInformationalVersionandGetFileVersionInfomethod overloads (see 5074590)
The new overloads take aTypeinstance as a single parameter, thereby supporting a few extra scenarios where usingTypemakes sense. -
Added new
IsExtensionClassandIsExtensionMethodmethods to theReflectionUtilsandReflectionExtensionsclasses (see 7fe6134)
The methods may be used to check whether a class is an extension class or a method is an extension method.
Time
v1.1.41
Installation
Install the NuGet package - either via the .NET CLI:
dotnet add package Skybrud.Essentials --version 1.1.41
or the NuGet package manager:
Install-Package Skybrud.Essentials -Version 1.1.41
v1.1.40
Installation
Install the NuGet package - either via the .NET CLI:
dotnet add package Skybrud.Essentials --version 1.1.40
or the NuGet package manager:
Install-Package Skybrud.Essentials -Version 1.1.40
Changelog
-
Updated
Iso8601Utils.ToStringto include milliseconds (see #23 and ef6deac)
In previous releases, theIso8601Utils.ToStringmethod and logic relying on this method, would return an ISO 8601 string representation of timestamps but, without including the milliseconds (as was using theyyyy-MM-ddTHH:mm:ssKformat rather thanyyyy-MM-ddTHH:mm:ss.fffK). With this release, the method now usesyyyy-MM-ddTHH:mm:ss.fffKfor timestamps with an offset to UTC andyyyy-MM-ddTHH:mm:ss.fffZfor UTC based timestamps (usingZ'for Zulu time instead of+00:00).All formats are valid according to the ISO 8601 specification, so this technically doesn't change the validity of the output string, but the change could be seen as a breaking change if one relies on the format being
yyyy-MM-ddTHH:mm:ssK. -
Added new
Subtract(TimeSpan)method to theEssentialsTimeclass (see #24 and 878b381)
Like theDateTimeOffset.Subtractmethods allows subtracting aTimeSpaninstance of aDateTimeOffset, theEssentialsTime.Subtractmethod now allows similar functionality. -
EssentialsTime.Add...methods should keep time zone information (see #25 and 504e158)
The variousAdd...methods now carry over the time zone (if specified) to the resultingEssentialsTimeinstance. -
EssentialsTime.ToLocalTimeandEssentialsTime.ToUniversalTimemethods should set the time zone for the resultingEssentialsTime(see #25 and 6cff8d5)
The time zone is now set toTimeZoneInfo.LocalandTimeZoneInfo.Utcrespectively for the resultingEssentialsTimeinstances returned by the two methods. -
Introduced new
RegexUtils.IsMatchmethod overloads (see #26 cad2474)
The method overloads utilizesoutparameters to make the methods easier to use in certain scenarios. See #26 for more information.
v1.1.39
Installation
Install the NuGet package - either via the .NET CLI:
dotnet add package Skybrud.Essentials --version 1.1.39
or the NuGet package manager:
Install-Package Skybrud.Essentials -Version 1.1.39
Changelog
v1.1.38
Installation
Install the NuGet package - either via the .NET CLI:
dotnet add package Skybrud.Essentials --version 1.1.38
or the NuGet package manager:
Install-Package Skybrud.Essentials -Version 1.1.38
Changelog
-
Implemented collection deconstructors (see #20 and f447c78)
This allows for tuple like deconstruction ofIEnumerable<T>based collections. -
Updated
TimeSpanSecondsConverterclass to supportTimeSpan?(see #21 and b8d8fc9)
TheTimeSpanSecondsConverterJSON converter now supports serializing and deserializing bothTimeSpanandTimeSpan?- opposed to onlyTimeSpanin earlier releases.
Skybrud.Essentials v1.1.37
Installation
Install the NuGet package - either via the .NET CLI:
dotnet add package Skybrud.Essentials --version 1.1.37
or the NuGet package manager:
Install-Package Skybrud.Essentials -Version 1.1.37
Bug Fixes
-
Fixed incorrect ISO 8601 milliseconds format (see #18 and 8ab31d6)
TheIso8601Constans.DateTimeMillisecondsconstant was missing a period in the format, causing formatted dates to be incorrect. -
The
EssentialsTime.ToString(format)method is now using an invariant culture (see #19 and 22aa776)
The point with theEssentialsTimeclass is that it should be culture invariant unless a culture is explicitly specified, so the method has now been updated to reflect this.
Skybrud.Essentials v1.1.36
Installation
Install the NuGet package - either via the .NET CLI:
dotnet add package Skybrud.Essentials --version 1.1.36
or the NuGet package manager:
Install-Package Skybrud.Essentials -Version 1.1.36
Changelog
-
Introduced new constants to the
Iso8601Constantsclass (see b6c2961)
As part of introducing better support for milliseconds, this release introduces theDate,DateTimeSecondsandDateTimeMillisecondsconstants. TheDateFormat(replaced byDate) andDateTimeFormat(replaced byDateTimeSeconds) are now marked as obsolete. -
Introduced new logic for working with Unix time in milliseconds (see fe79cb5)
New methods were added to theEssentialsTimeandUnixTimeUtilsclasses for making working with Unix time more convenient. Changes include:- Marked
EssentialsTime.FromUnixTimestampmethods as obsolete (as it was replaced byEssentialsTime.FromUnixTimeSeconds) - Introduced new
EssentialsTime.FromUnixTimeSecondsmethods - Introduced new
EssentialsTime.FromUnixTimeMillisecondsmethods - Introduced new
UnixTimeUtils.FromMillisecondsmethods - Introduced new
UnixTimeUtils.ToMillisecondsmethods
- Marked
-
Introduced new
UnixTimeFormatenum forUnixTimeConverterclass (see a6837d6)
The JSON converter now supports specifying the format of the converter - eitherUnixTimeFormat.Seconds(default) orUnixTimeFormat.Milliseconds. Until now, the converter has only supported converting back and forth between the UNIX timestamp expressed with seconds, but by setting the format toUnixTimeFormat.Milliseconds, the converter will now convert back and forth between milliseconds instead. -
Improved the Unix time logic in the
EssentialsTimeclass (see 32860ca)
New properties were added to theEssentialsTimeclass for making working with Unix time more convenient. Changes include:- Introduced new
CurrentUnixTimeSecondsstatic property - Introduced new
CurrentUnixTimeMillisecondsstatic property - Marked
UnixTimestampproperty as obsolete (as it was replaced byUnixTimeSeconds) - Introduced new
UnixTimeSecondsproperty - Introduced new
UnixTimeMillisecondsproperty - Introduced new
ToUnixTimeSecondsmethodty - Introduced new
ToUnixTimeMillisecondsmethod
- Introduced new
-
EssentialsDate.TryParsemethod should invariant culture if not a culture isn't explicitly specified (see 1733f2f)
The general idea with Skybrud.Essentials is that various logic should be culture invariant - unless specified otherwise. TheTryParse(string input, out EssentialsDate result)relied on the current culture, which was wrong. -
Added new method overloads to the
ReflectionUtilsclass (see 3753413)
As typical usage to get the version of an assembly would be something likeReflectionUtils.GetVersion(typeof(MyType).Assembly), it's now possibly to useReflectionUtils.GetVersion<MyType>()instead. -
Introduced new
TryParseJsonToken,TryParseJsonObjectandTryParseJsonArraymethod to theJsonUtilsclass (see dfef0f7)
The new methods add a more safe way of parsing JSON values - eg. if the validity of the JSON is not certain. The implementation will catch an exception should it be triggered by JSON.net's parsing logic. It may still be best to do some simple validation on the input value first - eg. if it starts with[or{. -
Introduced new
StringUtils.ParseHexStringmethod (see 3fa44a3)
The method allows parsing a HEX string into a corresponding byte array; the opposite of theStringUtils.ToHexStringmethod.