Releases: skybrud/Skybrud.Essentials
v1.1.47
Installation
Install via NuGet - either via the .NET CLI:
dotnet add package Skybrud.Essentials --version 1.1.47
or the NuGet package manager:
Install-Package Skybrud.Essentials -Version 1.1.47
Changelog
-
Added misc
Parse{Type}OrNull
methods (see ada8998)
The methods tries to parse a string value to a desired value type. Opposed to the existingParse{Type}
methods, which returns the default value for the respective value types, the new methods returnnull
if the parsing fails. -
Added new
To{Type}OrNull
extension methods (see 053a536)
The methods tries to parse a string value to a desired value type. Opposed to the existingTo{Type}
extension methods, which returns the default value for the respective value types, the new methods returnnull
if the parsing fails. -
Introduced new
ParseEnumOrNull
utility method andToEnumOrNull
extension method (see a4baefb)
As an alternative to the existingParseEnum
utility method and theToEnum
extension method, this release introducesParseEnumOrNull
andToEnumOrNull
alternatives that returnnull
if the parsing fails.
v1.1.46
Installation
Install via NuGet - either via the .NET CLI:
dotnet add package Skybrud.Essentials --version 1.1.46
or the NuGet package manager:
Install-Package Skybrud.Essentials -Version 1.1.46
Changelog
This release fixed a few minor bugs, but mainly adds additional functionality for working with date and time.
StringExtensions
- Added
[NotNullWhen(true)]
attribute toHasValue
out parameter (see 79fedd9)
The out parameter of theStringExtensions.HasValue
method is known to be not null when the method returnstrue
, so the API contract should reflect that.
EssentialsTime
-
Fixed issue with time zone not being set via
EssentialsTime
constructor (see d57979b)
Since the constructor takes aTimeZoneInfo
parameter as it's second parameter, we also need to set that time zone on the createdEssentialsTime
instance. -
Added
To{Type}
methods to theEssentialsTime
class (see dc512ef)
The new methods allow converting toEssentialsDate
,EssentialsWeek
,EssentialsMonth
andEssentialsYear
respectively. The four types already have constructors for create a new instance from anEssentialsTime
instance. The new method does the same, but may be more useful in some scenarios - eg. when using method chaining.
EssentialsMonth
-
Added static
Current
property to theEssentialsMonth
class (see b926f20)
The newEssentialsMonth.Current
property allows getting a reference to the current month. -
Added
IsCurrent
property to theEssentialsMonth
class (see e431ff7)
The new property returns whether aEssentialsMonth
instance represents the current month. -
Added new constructors to the
EssentialsMonth
class (see d1820c9)
As an alternative to the existing constructors, the new constructors allow creating new instances based on eitherDateTime
,DateTimeOffset
orEssentialsDate
.
EssentialsWeek
- Added
IsCurrent
property to theEssentialsWeek
class (see 9b806f0)
The property returns whether anEssentialsWeek
instance equals the current ISO 8601 week.
EssentialsYear
-
Added static
Current
property to theEssentialsYear
class (see 9ff4b84)
The property allows getting a reference to anEssentialsYear
instance representing the current year. -
Added
IsCurrent
property to theEssentialsYear
class (see fdb52e9)
The property returns whether anEssentialsYear
instance equals the current year. -
Additional constructors to the
EssentialsYear
class (see 7e880de)
The two new constructors allow creating a newEssentialsYear
instance from anEssentialsDate
instance.
TimeUtils
- Added additional utility methods for working with
DateTime
(see 433548f)
The new methods allow similar functionality as already available forDateTimeOffset
and other classes.
EssentialsDateUtils
- Introduced new
EssentialsDateUtils
class (see 0c7e76b)
The new class provides a number of static utility methods for various date and time operations where the return value is an instance ofEssentialsDate
.
Other
-
Misc improvements to the
EssentialsWeekRange
class (see 0add3b3)
Mainly theEssentialsWeekRange
class now implements theIReadOnlyList<EssentialsWeek>
rather thanIEnumerable<EssentialsWeek>
. -
Introduced the
EssentialsMonthRange
class (see f55300d)
The newEssentialsMonthRange
allows representing a range of months in either ascending or descending order.
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.GetStartOfWeek
andEssentialsWeek.GetEndOfWeek
methods (see c1782ab)
The two methods would return wrong results if theEssentialsWeek
instance wasn't created from theTimeZoneInfo
as 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 theParseEnumArray
andParseEnumList
methods respectively.ToEnumArray
andToEnumList
extension 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}Hash
utility methods. MatchingTo{Algorithm}Hash
extension 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.String
method should use invariant culture (see 2e6c476)
The method is used internally in the package for converting aJToken
to a string representation, and as such it's important that the method uses an invariant culture instead of the current culture. -
Added
Get{ValueType}OrNull
andGet{ValueType}OrNullByPath
extension methods to theNewtonsoftJsonObjectExtensions
class (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
Start
andEnd
properties for theEssentialsYear
class (see cc4bdca)
TheEssentialsYear
class inherits theStart
andEnd
properties fromEssentialsPeriod
, but asEssentialsPeriod
on it's own allows the to properties to be null. As a result, the newStart
andEnd
are not nullable as we know them to never be null for anEssentialsYear
instance. -
Added
GetStartOfYear
andGetEndOfYear
methods to theEssentialsYear
class (see 2520688)
The two methods getting either the the start or end of the year, according to a specific time zone. -
Added static
Min
andMax
methods to theEssentialsYear
class (see 6e08cbb)
The methods allow finding either the minimum or maximum value of twoEssentialsYear
instances. Method overloads also support specifying multipleEssentialsYear
instances. -
Added
GetStartOfYear
andGetEndOfYear
method overloads to theEssentialsYear
class (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
Start
andEnd
properties for theEssentialsMonth
class (see 02df0a3)
TheEssentialsMonth
class inherits theStart
andEnd
properties fromEssentialsPeriod
, but asEssentialsPeriod
on it's own allows the to properties to be null. As a result, the newStart
andEnd
are not nullable as we know them to never be null for anEssentialsMonth
instance. -
Added static
Min
andMax
methods to theEssentialsMonth
class (see 355aa85)
The methods allow finding either the minimum or maximum value of twoEssentialsMonth
instances. Method overloads also support specifying multipleEssentialsMonth
instances. -
Added
GetStartOfMonth
,GetStartOfYear
,GetEndOfMonth
andGetEndOfYear
methods to theEssentialsMonth
class (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
ToString
method in theEssentialsWeek
class (see 5459a90)
TheToString
now returns an ISO 8601 string representation of the week. -
Added
GetYear
method to theEssentialsWeek
class (see 2df2c99)
The method returns anEssentialsYear
instance representing the year of the week. -
Added
Parse
andTryParse
methods to theEssentialsWeek
class (see ec9c8fd)
The methods allow parsing a ISO 8601 week string representation into an instance ofEssentialsWeek
. -
Added static
Min
andMax
methods to theEssentialsWeek
class (see f256ee3)
The methods allow finding either the minimum or maximum value of twoEssentialsWeek
instances. Method overloads also support specifying multipleEssentialsWeek
instances. -
Added
GetStartOfWeek
andGetEndOfWeek
methods to theEssentialsWeek
class (see 1cc68c1)
The two methods allows getting theEssentialsTime
for either the start of the week or end of the week respectively.
EssentialsDate
-
Added static
Min
andMax
methods to theEssentialsDate
class (see 13db5d2)
The methods allow finding either the minimum or maximum value of twoEssentialsDate
instances. Method overloads also support specifying multipleEssentialsDate
instances. -
Added static
Min
andMax
methods to theEssentialsTime
class (see e5b0fb9)
The methods allow finding either the minimum or maximum value of twoEssentialsTime
instances. Method overloads also support specifying multipleEssentialsTime
instances.
EssentialsPeriod
- Added
EssentialsPeriod
constructor overload (see afded4a)
The overload takes aTimeZoneInfo
instance as the third parameter to determine the time zone to be used for theStart
andEnd
properties.
EssentialsWeekRange
- Added
ToString
,Parse
andTryParse
methods to theEssentialsWeekRange
class (see #34 and 9fc08fb)
This adds logic for converting aEssentialsWeekRange
to a string and parsing from a string back to aEssentialsWeekRange
instance.
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 fromNameValueCollection
instances - eg.TryGetBoolean
,TruGetGuid
,TryGetInt32
and similar. -
Added additional extension methods for
DateTime
andDateTimeOffset
(see 7311284)
TheIsToday
,IsTomorrow
andIsYesterday
extension methods are now available for bothDateTime
andDateTimeOffset
. -
Added static utility methods for working with ISO 8601 durations (see 0cd5538)
The ISO 8601 standard also describes a way to specify durations - eg.PT30M
or evenP1Y2M10DT2H30M
. Static methods for converting back and forth between this format andTimeSpan
are now available in theIso8601Utils
class. -
Introduced new extension methods for
JObject
andJArray
(see 8e75a29, 24ded82 and 6034cfa)
Skybrud.Essentials have had similar extension methods in theSkybrud.Essentials.Json.Extensions
namespace 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.Extensions
namespace. 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.FormatFileSize
methods 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
this
keyword toToHexString
extension 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
IsBoolean
method overloads to theStringExtensions
class (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
TryParseInt32
methods to theStringUtils
class + unit tests (see #30 and 1caee9f)
The new methods provides a culture invariant way to try/parsing integers. -
Introduced new
StringUtils.Parse{Type}List
methods andStringUtils.To{Type}List
extension 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 theStringExtensions
class (see #30 and fd0b70a)
The methods includeIsBoolean
,IsInt32
,IsInt64
and similar to quickly test whether an input string matches a given simple type.
Enums
- Added
IsBetween
methods to theEnumUtils
andEnumExtensions
classes (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.ToString
method 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.ToString
method where the XML declaration is omitted. -
Added new
XmlUtils.ToString
method 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
RandomOrDefault
andOrderByRandom
methods (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
,GetInformationalVersion
andGetFileVersionInfo
method overloads (see 5074590)
The new overloads take aType
instance as a single parameter, thereby supporting a few extra scenarios where usingType
makes sense. -
Added new
IsExtensionClass
andIsExtensionMethod
methods to theReflectionUtils
andReflectionExtensions
classes (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.ToString
to include milliseconds (see #23 and ef6deac)
In previous releases, theIso8601Utils.ToString
method 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:ssK
format rather thanyyyy-MM-ddTHH:mm:ss.fffK
). With this release, the method now usesyyyy-MM-ddTHH:mm:ss.fffK
for timestamps with an offset to UTC andyyyy-MM-ddTHH:mm:ss.fffZ
for 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 theEssentialsTime
class (see #24 and 878b381)
Like theDateTimeOffset.Subtract
methods allows subtracting aTimeSpan
instance of aDateTimeOffset
, theEssentialsTime.Subtract
method 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 resultingEssentialsTime
instance. -
EssentialsTime.ToLocalTime
andEssentialsTime.ToUniversalTime
methods should set the time zone for the resultingEssentialsTime
(see #25 and 6cff8d5)
The time zone is now set toTimeZoneInfo.Local
andTimeZoneInfo.Utc
respectively for the resultingEssentialsTime
instances returned by the two methods. -
Introduced new
RegexUtils.IsMatch
method overloads (see #26 cad2474)
The method overloads utilizesout
parameters 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
TimeSpanSecondsConverter
class to supportTimeSpan?
(see #21 and b8d8fc9)
TheTimeSpanSecondsConverter
JSON converter now supports serializing and deserializing bothTimeSpan
andTimeSpan?
- opposed to onlyTimeSpan
in earlier releases.