Bieber.Core.Helpers 1.0.1

dotnet add package Bieber.Core.Helpers --version 1.0.1
                    
NuGet\Install-Package Bieber.Core.Helpers -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Bieber.Core.Helpers" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Bieber.Core.Helpers" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Bieber.Core.Helpers" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Bieber.Core.Helpers --version 1.0.1
                    
#r "nuget: Bieber.Core.Helpers, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=Bieber.Core.Helpers&version=1.0.1
                    
Install Bieber.Core.Helpers as a Cake Addin
#tool nuget:?package=Bieber.Core.Helpers&version=1.0.1
                    
Install Bieber.Core.Helpers as a Cake Tool

Bieber.Core.Helpers

Bieber.Core.Helpers provides a set of utility methods for object manipulation, validation, and date/time operations.

Features

ObjectHelper

  • EnsureNotAbstract: Ensures that a specified type is not abstract.
  • EnsureNotNull: Ensures that an object is not null.
  • DeepClone: Creates a deep clone of an object using JSON serialization.
  • IsOfType: Checks if an object is of a specified type.
  • TryParse: Attempts to convert the specified string representation of a logical value to its equivalent strongly-typed value.
  • IsNullOrDefault: Checks if an object is null or the default value for its type.
  • GetPropertyValue: Retrieves the value of a specified property from an object.
  • SetPropertyValue: Sets the value of a specified property on an object.

DateTimeHelper

  • GetStartOfDay: Gets the start of the day for a given DateTime or DateOnly.
  • GetEndOfDay: Gets the end of the day for a given DateTime or DateOnly.
  • AddBusinessDays: Adds the specified number of business days to a DateTime or DateOnly.
  • Combine: Combines a DateOnly and a TimeOnly into a DateTime.
  • GetTime: Gets the TimeOnly portion of a DateTime.
  • IsWeekend: Checks if a given date falls on a weekend.
  • GetNextWeekday: Gets the next occurrence of a specific day of the week.
  • GetBusinessDaysBetween: Gets the number of business days between two dates.
  • GetWeekendsBetween: Gets the number of weekends between two dates.
  • CalculateAge: Calculates the age based on a given date of birth.

Installation

Add the Bieber.Core.Helpers library to your project using the .NET CLI:

dotnet add package Bieber.Core.Helpers

Or add the package reference directly in your .csproj file:

<PackageReference Include="Bieber.Core.Helpers" Version="1.0.0" />

Usage

ObjectHelper

EnsureNotAbstract

Ensures that a specified type is not abstract:

using Bieber.Core.Helpers;

ObjectHelper.EnsureNotAbstract<MyClass>();

EnsureNotNull

Ensures that an object is not null:

using Bieber.Core.Helpers;

ObjectHelper.EnsureNotNull(myObject, nameof(myObject));

DeepClone

Creates a deep clone of an object:

using Bieber.Core.Helpers;

var clone = ObjectHelper.DeepClone(originalObject);

IsOfType

Checks if an object is of a specified type:

using Bieber.Core.Helpers;

bool result = ObjectHelper.IsOfType<string>(myObject);

TryParse

Attempts to convert the specified string representation of a logical value to its equivalent strongly-typed value:

using Bieber.Core.Helpers;

bool success = ObjectHelper.TryParse("123", out int result);

IsNullOrDefault

Checks if an object is null or the default value for its type:

using Bieber.Core.Helpers;

bool isNullOrDefault = ObjectHelper.IsNullOrDefault(0); // true

GetPropertyValue

Retrieves the value of a specified property from an object:

using Bieber.Core.Helpers;

object? value = ObjectHelper.GetPropertyValue(myObject, "PropertyName");

SetPropertyValue

Sets the value of a specified property on an object:

using Bieber.Core.Helpers;

ObjectHelper.SetPropertyValue(myObject, "PropertyName", newValue);

DateTimeHelper

GetStartOfDay

Gets the start of the day for a given DateTime or DateOnly:

using Bieber.Core.Helpers;

DateTime startOfDay = DateTimeHelper.GetStartOfDay(myDateTime);
DateTime startOfDay = DateTimeHelper.GetStartOfDay(myDateOnly);

GetEndOfDay

Gets the end of the day for a given DateTime or DateOnly:

using Bieber.Core.Helpers;

DateTime endOfDay = DateTimeHelper.GetEndOfDay(myDateTime);
DateTime endOfDay = DateTimeHelper.GetEndOfDay(myDateOnly);

AddBusinessDays

Adds the specified number of business days to a DateTime or DateOnly:

using Bieber.Core.Helpers;

DateTime newDateTime = DateTimeHelper.AddBusinessDays(myDateTime, 3);
DateOnly newDateOnly = DateTimeHelper.AddBusinessDays(myDateOnly, 3);

Combine

Combines a DateOnly and a TimeOnly into a DateTime:

using Bieber.Core.Helpers;

DateTime combined = DateTimeHelper.Combine(myDateOnly, myTimeOnly);

GetTime

Gets the TimeOnly portion of a DateTime:

using Bieber.Core.Helpers;

TimeOnly timeOnly = DateTimeHelper.GetTime(myDateTime);

IsWeekend

Checks if a given date falls on a weekend:

using Bieber.Core.Helpers;

bool isWeekend = DateTimeHelper.IsWeekend(myDateTime);
bool isWeekend = DateTimeHelper.IsWeekend(myDateOnly);

GetNextWeekday

Gets the next occurrence of a specific day of the week:

using Bieber.Core.Helpers;

DateTime nextMonday = DateTimeHelper.GetNextWeekday(myDateTime, DayOfWeek.Monday);
DateOnly nextMonday = DateTimeHelper.GetNextWeekday(myDateOnly, DayOfWeek.Monday);

GetBusinessDaysBetween

Gets the number of business days between two dates:

using Bieber.Core.Helpers;

int businessDays = DateTimeHelper.GetBusinessDaysBetween(startDate, endDate)
GetWeekendsBetween

Gets the number of weekends between two dates.

using Bieber.Core.Helpers;

int weekends = DateTimeHelper.GetWeekendsBetween(startDate, endDate)

CalculateAge

Calculates the age based on a given date of birth

using Bieber.Core.Helpers;

int businessDays = DateTimeHelper.CalculateAge(dateOfBirth, referenceDate) // referenzDate defaults to today

License

This project is licensed under the MIT License. For more information, please see the LICENSE file.

Contributions

We welcome contributions to improve this library. Please fork the repository and submit pull requests with your changes.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net9.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Bieber.Core.Helpers:

Package Downloads
Bieber.Core.ValueObjects

Library for creating and managing value objects in your .NET applications. It provides a base implementation for value objects that are immutable and compared based on their properties.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 102 3 months ago