ScottLilly.CSharpExtender 2.2.0

dotnet add package ScottLilly.CSharpExtender --version 2.2.0                
NuGet\Install-Package ScottLilly.CSharpExtender -Version 2.2.0                
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="ScottLilly.CSharpExtender" Version="2.2.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ScottLilly.CSharpExtender --version 2.2.0                
#r "nuget: ScottLilly.CSharpExtender, 2.2.0"                
#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.
// Install ScottLilly.CSharpExtender as a Cake Addin
#addin nuget:?package=ScottLilly.CSharpExtender&version=2.2.0

// Install ScottLilly.CSharpExtender as a Cake Tool
#tool nuget:?package=ScottLilly.CSharpExtender&version=2.2.0                

CSharpExtender

Collections

GenericCache

This class creates a cache object with a generic key and generic value.

  • Clear: Remove all items from the cache.
  • Get: Retrieves a value from the cache, or default, if not in the cache.
  • Set: Adds or updates a value in the cache.
  • Remove: Remove an entry fom the cache.
  • RemoveExpiredItems: Removes all expired items fromthe cache.

Extension Methods

DataSetExtensionMethods

This class provides extension methods for DataTables and DataSets

  • Get<T>: Gets a typed value from a column in a DataRow.
  • HasColumn: Checks if a DataSet has a column with the specified name.
  • HasRows: Checks if a DataSet has any rows.

DateTimeExtensionMethods

This class provides extension methods for DateTime in C#.

  • EndOfDay: Returns the end of the day 23:59:59 for the provided date.
  • EndOfMonth: Returns the date for the end of the month, at 23:59:59, for the provided date.
  • IsWeekday: Checks if the given date is a weekday.
  • IsWeekend: Checks if the given date is a weekend.
  • NextDay: Gets the next day from the given date.
  • PreviousDay: Gets the previous day from the given date.
  • StartOfDay: Returns the start of the day 00:00:00 for the provided date.
  • StartOfMonth: Returns the date for the start of the month, at 00:00:00, for the provided date.
  • ToIso8601String: Converts the provided date to an ISO 8601 string.

EnumExtensionMethods

This class provides extension methods for Enums in C#.

  • GetEnumDescription: Gets the description of an enum value.
  • GetEnumDescriptions: Gets all descriptions of a specific enum type.
  • GetEnumValues: Gets all values of a specific enum type.
  • ParseEnum: Parses a string to an enum value.

JsonExtensionMethods

This class provides extension methods for JSON manipulation in C#.

  • AsDeserializedJson: Deserializes the JSON string to an object of the specified type.
  • AsSerializedJson: Serializes the specified object to a JSON string.
  • GetValueFromJsonPath: Retrieves a value from a JSON string using a JSON path.
  • GetValueFromJsonPath<T>: Retrieves a typed value from a JSON string using a JSON path.
  • PrettyPrintJson (string): Formats the JSON string with indented formatting.
  • PrettyPrintJson (object): Serializes the specified object to a JSON string with indented formatting.

LinqExtensionMethods

This class provides LINQ-related extension methods in C#.

  • ForEach (IEnumerable): Applies an action to each element in the collection.
  • ForEach (List): Applies an action to each element in the list.
  • HasDuplicatePropertyValue<T, TProperty>: Checks if any objects have the same value in the specified property.
  • HasDuplicatePropertyValue<T>: Checks if any objects have the same value in the specified string property.
  • None: Checks if none of the elements in the collection satisfy the provided condition. If no condition is provided, it checks if the collection is empty.
  • RandomElement: Returns a random element from the list.

NumericExtensionMethods

This class provides extension methods for numerical operations in C#.

  • IsEven: Checks if the given integer is even.
  • IsEvenlyDivisibleBy: Checks if the given integer is evenly divisible by another integer.
  • IsNegative: Checks if the given integer is negative.
  • IsOdd: Checks if the given integer is odd.
  • IsPositive: Checks if the given integer is positive.

ObjectExtensionMethods

This class provides extension methods for objects in C#.

  • DeepClone: Creates a deep clone of the source object.
  • HasCustomAttributeOfType: Checks if the property info has a custom attribute of a specific type.
  • IsFloatingPointType: Checks if the object is of a floating point type.
  • IsIntegerType: Checks if the object is of an integer type.
  • IsNotNull: Checks if the object is not null.
  • IsNotOfType (with Type parameter): Checks if the object is not of a specific type.
  • IsNotOfType (for Type with baseType parameter): Checks if the type is not of a specific type.
  • IsNotOfType<T>: Checks if the object is not of a specific type.
  • IsNotOfType<T> (for Type): Checks if the type is not of a specific type.
  • IsNotOfTypeOrSubclass (with Type parameter): Checks if the object is not of a specific type and not a subclass of that type.
  • IsNotOfTypeOrSubclass (for Type with baseType parameter): Checks if the type is not of a specific type and not a subclass of that type.
  • IsNotOfTypeOrSubclass<T>: Checks if the object is not of a specific type and not a subclass of that type.
  • IsNotOfTypeOrSubclass<T> (for Type): Checks if the type is not of a specific type and not a subclass of that type.
  • IsNull: Checks if the object is null.
  • IsNumericType: Checks if the object is of a numeric type.
  • IsOfType (with Type parameter): Checks if the object is of a specific type.
  • IsOfType (for Type with baseType parameter): Checks if the type is of a specific type.
  • IsOfType<T>: Checks if the object is of a specific type.
  • IsOfType<T> (for Type): Checks if the type is of a specific type.
  • IsOfTypeOrSubclass (with Type parameter): Checks if the object is of a specific type or a subclass of that type.
  • IsOfTypeOrSubclass (for Type with baseType parameter): Checks if the type is of a specific type or a subclass of that type.
  • IsOfTypeOrSubclass<T>: Checks if the object is of a specific type or a subclass of that type.
  • IsOfTypeOrSubclass<T> (for Type): Checks if the type is of a specific type or a subclass of that type.

StringExtensionMethods

This class provides extension methods for string manipulations in C#.

  • ConvertFromString<T>: Converts a string to the specified type, if possible.
  • DoesNotHaveText: Returns 'true' if the string is null, empty, or only contains whitespace.
  • DoesNotMatch: Check if strings are not equal, using InvariantCultureIgnoreCase.
  • HasText: Returns 'true' if the string is not null, empty, or only contains whitespace.
  • IncludesTheWords: Checks if a string contains all the words in the specified array.
  • IsDigitsOnly: Returns 'true' if the string only contains digits.
  • Matches: Check if strings are equal, using InvariantCultureIgnoreCase.
  • NullIfEmpty: Returns a null if the string is null, empty, or only contains whitespace.
  • RemoveText: Removes all instances of the specified text from the string.
  • Repeat: Returns a string with the text repeated the specified number of times.
  • SplitPath: Convert a file path into an array of the individual directories.
  • ToDigitsOnly: Returns a string with all non-digits removed.
  • ToStringWithLineFeeds: Converts an IEnumerable of strings to a single string with line feeds between each string.

StringBuilderExtensionMethods

This class provides extension methods for StringBuilder objects in C#.

  • AppendLineIfNotEmpty: If the passed in line is not empty, it will be appended to the StringBuilder object.

XmlExtensionMethods

This class provides extension methods for XML handling in C#.

  • AttributeAsBool: Returns the value of the specified attribute as a boolean.
  • AttributeAsDateTime: Returns the value of the specified attribute as a DateTime.
  • AttributeAsInt: Returns the value of the specified attribute as an integer.
  • AttributeAsString: Returns the value of the specified attribute as a string.
  • ElementAsInt: Returns the inner text of the specified child element as an integer.
  • ElementAsString: Returns the inner text of the specified child element as a string.

RngCreator

This class is designed to create cryptographically random numbers in C#.

  • GetNumberBetween: Generates a cryptographically random number between the specified minimum and maximum values.

Models

These classes can be used as base classes for models and handle property changed notification and logging of changed property values.

ObservableModel

Base class that handles property changed notification.

-SetProperty<T>: Used to set a property's backing field and raise property changed event.

PropertyChangeTrackingModel

Base class that inherits from ObservableModel (to handle property change notification) and also logs the values of the changed properties. Implements IChangeTracking.

-AcceptChanges: Clears the PropertyChangeLog -PropertyChangeLog: ObservableCollection of properties values that were changed.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
2.2.0 96 9/1/2024
2.1.0 175 1/20/2024
2.0.0 136 1/7/2024
1.0.0 579 8/16/2022

Replaced Newtonsoft with System.Text.Json. Added new StringBuilder extention method to only append non-blank lines. Added string and JSON converters to different datatypes.