WM.Util 3.6.6

dotnet add package WM.Util --version 3.6.6
                    
NuGet\Install-Package WM.Util -Version 3.6.6
                    
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="WM.Util" Version="3.6.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="WM.Util" Version="3.6.6" />
                    
Directory.Packages.props
<PackageReference Include="WM.Util" />
                    
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 WM.Util --version 3.6.6
                    
#r "nuget: WM.Util, 3.6.6"
                    
#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 WM.Util@3.6.6
                    
#: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=WM.Util&version=3.6.6
                    
Install as a Cake Addin
#tool nuget:?package=WM.Util&version=3.6.6
                    
Install as a Cake Tool

WM.Util

WM.Util is a compact utility library for common .NET tasks. It provides extension methods and helper types for dates, enums, collections, reflection, text replacement, streams, and JSON serialization.

Installation

dotnet add package WM.Util

Quick start

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using WM.Util;

var age = DateTime.Now.Age();
var isAdult = DateTime.Now.IsAdult();
var germanDate = DateTime.Now.ToGermanDate();
var areEqual = new List<int> { 1, 2, 3 }.IsEqualToList(new List<int> { 1, 2, 3 });

Public API reference

DateOnlyExtensionMethods

  • Age(this DateOnly date)
var birthDate = new DateOnly(2000, 5, 10);
var age = birthDate.Age();
  • Age(this DateOnly? date)
DateOnly? birthDate = new DateOnly(2000, 5, 10);
var age = birthDate.Age();
  • IsAdult(this DateOnly date, int minAge = 18)
var isAdult = new DateOnly(2005, 1, 1).IsAdult();
  • ToGermanDate(this DateOnly? date) and ToGermanDate(this DateOnly? date, bool withLeadingZeros)
DateOnly? date = new DateOnly(2024, 3, 5);
var text = date.ToGermanDate();
var textWithZeros = date.ToGermanDate(true);
  • ToGermanDate(this DateOnly date, bool withLeadingZeros = false)
var text = new DateOnly(2024, 3, 5).ToGermanDate();
  • EndOfYear(this DateOnly datum)
var lastDay = new DateOnly(2024, 1, 15).EndOfYear();
  • EndOfHalfYear(this DateOnly datum)
var lastDay = new DateOnly(2024, 7, 1).EndOfHalfYear();
  • EndOfQuarter(this DateOnly datum)
var lastDay = new DateOnly(2024, 5, 20).EndOfQuarter();
  • EndOfMonth(this DateOnly datum)
var lastDay = new DateOnly(2024, 2, 15).EndOfMonth();

DateTimeExtensionMethods

  • Age(this DateTime date)
var age = new DateTime(2000, 5, 10).Age();
  • Age(this DateTime? date)
DateTime? birthday = new DateTime(2000, 5, 10);
var age = birthday.Age();
  • IsAdult(this DateTime date, int minAge = 18)
var isAdult = new DateTime(2010, 1, 1).IsAdult();
  • ToGermanDate(this DateTime? date) and ToGermanDate(this DateTime? date, bool withLeadingZeros)
DateTime? date = new DateTime(2024, 3, 5, 14, 30, 0);
var text = date.ToGermanDate();
  • ToGermanDate(this DateTime date, bool withLeadingZeros = false)
var text = new DateTime(2024, 3, 5).ToGermanDate();
  • EndOfYear(this DateTime datum)
var lastDay = new DateTime(2024, 1, 15).EndOfYear();
  • EndOfHalfYear(this DateTime datum)
var lastDay = new DateTime(2024, 7, 1).EndOfHalfYear();
  • EndOfQuarter(this DateTime datum)
var lastDay = new DateTime(2024, 5, 20).EndOfQuarter();
  • EndOfMonth(this DateTime datum)
var lastDay = new DateTime(2024, 2, 15).EndOfMonth();

DictionaryListExtensionMethods

  • IsEqualTo<TKey, TValue>(this IDictionary<TKey, TValue> dict1, IDictionary<TKey, TValue> dict2)
var first = new Dictionary<string, int> { ["a"] = 1 };
var second = new Dictionary<string, int> { ["a"] = 1 };
var equal = first.IsEqualTo(second);

EnumExtensionMethods

  • GetAttribute<T>(this Enum enumValue)
var attribute = MyEnum.FirstValue.GetAttribute<DisplayAttribute>();
  • GetAttributes<T>(this Enum enumValue)
var attributes = MyEnum.FirstValue.GetAttributes<DisplayAttribute>();
  • EnumMin<T>()
var min = EnumExtensionMethods.EnumMin<MyEnum>();
  • EnumMax<T>()
var max = EnumExtensionMethods.EnumMax<MyEnum>();
  • GetDisplayString(this Enum e)

Returns the display name of an enum value. If the enum member has a [Display(Name = "...")] attribute, that name is returned. Otherwise, the method falls back to ToString().

var name = MyEnum.FirstValue.GetDisplayString();
  • EnumToList<T>()
var values = EnumExtensionMethods.EnumToList<MyEnum>();
  • ToEnum<T>(this string s)
var value = "FirstValue".ToEnum<MyEnum>();

EnumHelper

  • ToEnum<T>(this string value, bool ignoreCase = true)
var value = "firstvalue".ToEnum<MyEnum>(ignoreCase: true);
  • Values<T>() (obsolete)
var values = EnumHelper.Values<MyEnum>();
  • Names<T>() (obsolete)
var names = EnumHelper.Names<MyEnum>();

IntExtensionMethods

  • ToRoman(this int value)
var roman = 2024.ToRoman();

ListExtensionMethods

  • IsEqualToList<T>(this List<T> list1, List<T> list2)
var one = new List<int> { 1, 2, 3 };
var two = new List<int> { 1, 2, 3 };
var equal = one.IsEqualToList(two);

ObjectExtensionMethods

  • IsEqualTo<T>(this T obj1, T obj2)
var equal = 42.IsEqualTo(42);
  • GetAttribute<T>(this PropertyInfo prop)
var attribute = typeof(MyType).GetProperty(nameof(MyType.Name))!.GetAttribute<DisplayAttribute>();
  • GetAttributes<T>(this PropertyInfo prop)
var attributes = typeof(MyType).GetProperty(nameof(MyType.Name))!.GetAttributes<Attribute>();
  • Properties<T>(this T item, Action<PropertyInfo> action)
var names = new List<string>();
new MyType().Properties(p => names.Add(p.Name));
  • NameValue<T>(this T item, Action<string, object> action)
var values = new Dictionary<string, object>();
new MyType().NameValue((name, value) => values[name] = value);
  • GetAllProperties<T>(this T o)
var properties = new MyType().GetAllProperties();

StreamExtensionMethods

  • ToByteArray(this Stream stream)
using var stream = new MemoryStream(new byte[] { 1, 2, 3 });
var bytes = stream.ToByteArray();

TypeInfoAllMemberExtensions

  • GetAllConstructors(this TypeInfo typeInfo)
var constructors = typeof(MyType).GetTypeInfo().GetAllConstructors();
  • GetAllEvents(this TypeInfo typeInfo)
var events = typeof(MyType).GetTypeInfo().GetAllEvents();
  • GetAllFields(this TypeInfo typeInfo)
var fields = typeof(MyType).GetTypeInfo().GetAllFields();
  • GetAllMembers(this TypeInfo typeInfo)
var members = typeof(MyType).GetTypeInfo().GetAllMembers();
  • GetAllMethods(this TypeInfo typeInfo)
var methods = typeof(MyType).GetTypeInfo().GetAllMethods();
  • GetAllNestedTypes(this TypeInfo typeInfo)
var nestedTypes = typeof(MyType).GetTypeInfo().GetAllNestedTypes();
  • GetAllProperties(this TypeInfo typeInfo)
var properties = typeof(MyType).GetTypeInfo().GetAllProperties();

TextReplace

  • ErsetzeVariablen(IEnumerable<string> src)
var replacer = new TextReplace("{{", "}}", value => value.ToUpperInvariant());
var result = replacer.ErsetzeVariablen(new[] { "Hello {{name}}" });

JsonSerializerOptionsHelper

  • AddDateOnlyTimeOnlyConverter(this JsonSerializerOptions options)
var options = new JsonSerializerOptions().AddDateOnlyTimeOnlyConverter();

DateOnlyConverter and TimeOnlyConverter

  • Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
var converter = new DateOnlyConverter();
  • Write(Utf8JsonWriter writer, DateOnly value, JsonSerializerOptions options)
var converter = new TimeOnlyConverter();

Supported target frameworks

  • .NET 8
  • .NET 9
  • .NET 10
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  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.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net11.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (5)

Showing the top 5 NuGet packages that depend on WM.Util:

Package Downloads
WM.Database

Package Description

WM.MDBBlazor

A Material Design Component library for Blazor

WM.Mailgun

Package Description

WM.Latex

Package Description

WM.Bootstrap.Blazor

Component library for Blazor

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.6.6 93 11/16/2026
3.6.5 323 7/1/2026
3.6.4 152 5/28/2026
3.6.3 483 2/4/2026
3.6.2 151 2/4/2026
3.6.1 322 1/6/2026
3.6.0 546 12/9/2025
3.5.1 243 11/24/2024
3.5.0 428 11/19/2024
3.4.1 285 8/6/2024
3.4.0 757 11/23/2023
3.3.2 2,097 1/29/2023
3.3.1 4,853 4/30/2022
3.2.0 1,274 2/5/2022
3.1.1 1,827 12/29/2021
3.1.0 863 12/9/2021
3.0.2 3,719 1/6/2021
Loading failed