pwExtensionsLibrary 1.0.2

dotnet add package pwExtensionsLibrary --version 1.0.2
                    
NuGet\Install-Package pwExtensionsLibrary -Version 1.0.2
                    
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="pwExtensionsLibrary" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="pwExtensionsLibrary" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="pwExtensionsLibrary" />
                    
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 pwExtensionsLibrary --version 1.0.2
                    
#r "nuget: pwExtensionsLibrary, 1.0.2"
                    
#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.
#:package pwExtensionsLibrary@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=pwExtensionsLibrary&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=pwExtensionsLibrary&version=1.0.2
                    
Install as a Cake Tool

ExtensionsLibrary

Compilation of useful C# extension methods to boost productivity for the .net developers.<br> Some of them come from other projects/developers.

Minimum requirements

Framework 4.5

History

Version 1.0.1 (27/04/2023)<br> Added some extensions

Version 1.0.0 (30/09/22019)<br> First version

List extensions for objects/data type

  • Boolean
  • Comparable
  • Converter
  • DataGridView
  • Date
  • DirectoryInfo
  • Enumerable
  • Object
  • String

List extensions for Boolean

  • GetBoolString(this bool value) : returns "Yes" or "No"

List extensions for Comparable

  • IsBetween(this T value, T minValue, T maxValue)
  • IsBetween(this T value, T minValue, T maxValue, , IComparer comparer)

List extensions for DataGridView

  • DoubleBuffered(this DataGridView dgv, bool setting) : Prevents DataGridView from flickering

List extensions for Date

  • CalculateAge(this DateTime dateOfBirth) : Calculate age in year since a given date until today
  • CalculateAge(this DateTime dateOfBirth, DateTime dateReference) : Calculate age in year since a given date until reference date
  • GetCountDaysOfMonth(this DateTime value) : Returns number of days in a month
  • GetDayOfYear(this DateTime value) : Returns the day number in the year
  • GetFirstDayOfMonth(this DateTime value) : Returns first day of the month
  • GetLastDayOfMonth(this DateTime value) : Returns last day of the month in DateTime format
  • IsToday(this DateTime value) : Indicates if the specified date is the date of the day
  • IsWeekend(this DateTime value) : Indicates if the specified date is a weekend
  • GetWeekOfYear(this DateTime value) : Returns the week's number from the given date
  • IsBetween(this DateTime date, DateTime startDate, DateTime endDate, Boolean compareTime = false) : Determines if the date is between two provided dates.
  • SetTime(this DateTime date, TimeSpan time) : Sets the time on the specified DateTime value.
  • SetTime(this DateTimeOffset date, TimeSpan time, TimeZoneInfo localTimeZone) : Sets the time on the specified DateTime value using the specified time zone.
  • SetTime(this DateTimeOffset date, int hours, int minutes, int seconds) : Sets the time on the specified DateTimeOffset value using the local system time zone.
  • ToDateTimeOffset(this DateTime localDateTime) : Converts a DateTime into a DateTimeOffset using the local system time zone.
  • ToDateTimeOffset(this DateTime localDateTime, TimeZoneInfo localTimeZone) : Converts a DateTime into a DateTimeOffset using the specified time zone.
  • SetTime(this DateTimeOffset date, TimeSpan time) : Sets the time on the specified DateTimeOffest value using the local system time zone.
  • ToLocalDateTime(this DateTimeOffset dateTimeUtc, TimeZoneInfo localTimeZone) : Converts a DateTimeOffset into a DateTime using the specified time zone.

List extensions for DirectoryInfo

  • GetFiles(this DirectoryInfo directory, params string[] patterns) : Gets all files in the directory matching one of the several (!) supplied patterns (instead of just one in the regular implementation).
  • FindFileRecursive(this DirectoryInfo directory, string pattern) : Searches the provided directory recursively and returns the first file matching the provided pattern.
  • FindFileRecursive(this DirectoryInfo directory, Func<FileInfo, bool> predicate) : Searches the provided directory recursively and returns the first file matching to the provided predicate.
  • FindFilesRecursive(this DirectoryInfo directory, string pattern) : Searches the provided directory recursively and returns the all files matching the provided pattern.
  • FindFilesRecursive(this DirectoryInfo directory, Func<FileInfo, bool> predicate) : Searches the provided directory recursively and returns the all files matching to the provided predicate.
  • CopyTo(this DirectoryInfo sourceDirectory, string targetDirectoryPath) : Copies the entire directory to another one
  • CopyTo(this DirectoryInfo sourceDirectory, DirectoryInfo targetDirectory) : Copies the entire directory to another one

Sample usage

Strings
"SafeSubstring".SafeSubstring(0, 5); // returns "SafeS"
"SafeSubstring".SafeSubstring(0, 50); // returns "SafeSubstring"
"SafeSubstring".SafeSubstring(20, 5); // returns empty string

// Check email validity
"john.doe@gmail@com".IsValidEmailAddress(); // return false;
"john.doe@gmail".IsValidEmailAddress(); // return false;
"john.doe@gmail@com".IsValidEmailAddress(); // return true;

// Limit text length
"The quick brown fox jumps over the lazy dog".LimitTextLength(20, false); // returns "The quick brown fox"
"The quick brown fox jumps over the lazy dog".LimitTextLength(20, true); // returns "The quick brown f..."
Product Compatible and additional computed target framework versions.
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.5

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2 693 12/2/2025
1.0.1 568 4/27/2023
1.0.0 525 3/27/2023