CodeChops.SourceGeneration.Utilities 0.9.1

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

// Install CodeChops.SourceGeneration.Utilities as a Cake Tool
#tool nuget:?package=CodeChops.SourceGeneration.Utilities&version=0.9.1

Source generation utilities

Utilities for easy implementation of source generators. A big thanks to TheArchitectDev for providing many of these extensions.

Check out CodeChops projects for more projects.

Extensions

AttributeDataExtensions

  • TryGetArguments: Tries to get the arguments of the attribute.
  • GetArgumentOrDefault: Gets the value of the attribute argument, or the (provided) default value if the argument was not provided.
  • TryGetArgument: Tries to get the value of the attribute argument.

NamespaceSymbolExtensions

  • IsInSystemNamespace**: Returns whether the given INamedTypeSymbol is or resides in the System namespace.
  • HasFullName**: Returns whether the given INamedTypeSymbol has the given 'fullName'.

NameSyntaxExtensions

  • HasAttributeName: Checks if a name syntax has a specific attribute of provided 'expectedName'.
  • ExtractAttributeName: Extracts the attribute name from the name syntax.

StringBuilderExtensions

  • TrimEnd: Trims the end of a StringBuilder.
  • AppendLine: Appends the StringBuilder with the provided text retriever (Func<string?>) and adds a newline if the resulting text is not null.

StringExtensions

  • ToTitleCase: Returns the input with the first character converted to uppercase.
  • NormalizeWhitespace**: Normalizes the whitespace for the given C# source code as much as possible.
  • GetStableHashCode32**: Gets a stable hash code (int).
  • GetStableHashCode64**: Gets a stable hash code (ulong).
  • GetStableStringHashCode32**: Gets a stable int hash code as string.
  • GetStableStringHashCode64**: Gets a stable ulong hash code as string.
  • ToBase32Chars8**: Converts the given 8 bytes to 13 base32 chars.
  • Write: Returns specific text when the provided value is not null.

TypeDeclarationSyntaxExtensions

  • GetClassGenericConstraints: Gets the generic constraints of a TypeDeclarationSyntax.
  • GetUsings: Gets the usings of a TypeDeclarationSyntax.

TypeSymbolExtensions

  • IsType**: Returns whether the ITypeSymbol is of a specific type.
  • IsOrInheritsClass**: Returns whether the ITypeSymbol is or inherits from a certain class, as determined by the given predicate.
  • IsOrImplementsInterface**: Returns whether the ITypeSymbol is or implements a certain interface, as determined by the given predicate.
  • HasSingleGenericTypeArgument**: Returns whether the <see cref="ITypeSymbol"/> is a constructed generic type with a single type argument matching the provided 'requiredTypeArgument'.
  • IsNumeric: Returns whether the <see cref="ITypeSymbol"/> represents an numeric type, such as an int or ulong.
  • IsGeneric**: Returns whether the <see cref="ITypeSymbol"/> is a generic type (with the given number of type parameters).
  • IsNullable**: Returns whether the <see cref="ITypeSymbol"/> is a Nullable<T>.
  • IsSelfEquatable**: Returns whether the given <see cref="ITypeSymbol"/> implements IEquatable{T} against itself.
  • IsComparable**: Returns whether the <see cref="ITypeSymbol"/> implements any IComparable or <see cref="IComparable{T}"/> interface.
  • IsEnumerable**: Returns whether the <see cref="ITypeSymbol"/> is or implements System.Collections.IEnumerable.
  • HasEqualsOverride**: Returns whether the <see cref="ITypeSymbol"/> or a base type has an override of <see cref="Object.Equals(object)"/> more specific than Object's implementation.
  • HasAttribute**: Returns whether the <see cref="ITypeSymbol"/> is annotated with the specified attribute(s).
  • HasConversionTo**: Returns whether the <see cref="ITypeSymbol"/> defines a conversion to the specified type.
  • HasConversionFrom**: Returns whether the <see cref="ITypeSymbol"/> defines a conversion from the specified type.
  • GetAvailableConversionsFromNatives**: Enumerates the native types (string, int, bool, decimal, double, char, etc.) from which the given <see cref="ITypeSymbol"/> is convertible.
  • CreateStringExpression**: Returns the code for a string expression of the given <paramref name="memberName"/> of "this".
  • CreateComparisonExpression**: Returns the code for a comparison expression on the given 'memberName' between "this" and "other".
  • GetFullTypeNameWithoutGenericParameters: Converts names like string to global::System.String excluding generic parameter names (if used).
  • GetFullTypeNameWithGenericParameters: Converts names like string to global::System.String including generic parameter names (if used).
  • GetTypeNameWithGenericParameters: Gets the type name including generic parameters (without namespace).
  • GetTypeKindName: Gets the name of the TypeKind. For example: a record class will be 'record class', an interface will be 'interface'.
  • GetObjectDeclaration: Gets the declaration of a class, record or interface. E.g.: 'public abstract (partial) class Test'.

Helpers

FileNameHelpers

  • GetFileName: Gets a unique source generation file name (takes namespaces and generic parameters into account).
    • Removes 'global::' from the start of the name if it exists.
    • Replaces invalid file name characters to '_'.
    • Removes the root namespace of the source assembly from the start file name.
    • Adds suffix '.g.cs' to the file name, if needed.

NameHelpers

  • GetNameWithoutGenerics: Gets the name without generic parameters.
  • HasGenericParameter: Checks if a name contains a generic parameter.
  • GetNameWithGenerics: Gets the name of a class including the generic types. E.g: System.Collections.Generic.Dictionary'2 becomes System.Collections.Generic.Dictionary<System.String,System.Object>.

** Has been provided by TheArchitectDev.

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 netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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.
  • .NETStandard 2.0

    • 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
0.9.1 168 2/28/2024
0.9.0 424 1/3/2023
0.8.3 423 12/22/2022
0.8.0 421 12/12/2022

Added extra chars to InvalidFileNameChars. Updated packages.