CodeChops.SourceGeneration.Utilities
0.8.3
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package CodeChops.SourceGeneration.Utilities --version 0.8.3
NuGet\Install-Package CodeChops.SourceGeneration.Utilities -Version 0.8.3
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.8.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CodeChops.SourceGeneration.Utilities --version 0.8.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: CodeChops.SourceGeneration.Utilities, 0.8.3"
#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.8.3 // Install CodeChops.SourceGeneration.Utilities as a Cake Tool #tool nuget:?package=CodeChops.SourceGeneration.Utilities&version=0.8.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Source generation utilities
Utilities for easy implementation of source generators. A big thanks to TheArchitectDev for providing many of these extensions.
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 theSystem
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 notnull
.
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 asstring
. - GetStableStringHashCode64**: Gets a stable
ulong
hash code asstring
. - ToBase32Chars8**: Converts the given 8
bytes
to 13 base32chars
. - 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 aTypeDeclarationSyntax
.
TypeSymbolExtensions
- IsType**: Returns whether the
ITypeSymbol
is of a specific type. - IsOrInheritsClass**: Returns whether the
ITypeSymbol
is or inherits from a certainclass
, as determined by the given predicate. - IsOrImplementsInterface**: Returns whether the
ITypeSymbol
is or implements a certaininterface
, 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
orulong
. - 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
toglobal::System.String
excluding generic parameter names (if used). - GetFullTypeNameWithGenericParameters: Converts names like
string
toglobal::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', aninterface
will be 'interface'. - GetObjectDeclaration: Gets the declaration of a
class
,record
orinterface
. 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
becomesSystem.Collections.Generic.Dictionary<System.String,System.Object>
.
** Has been provided by TheArchitectDev.
Product | Versions 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.
Fixed NameHelpers.GetGenericsParameters() 2.