WritingMango.AttributeHelper 1.0.0

dotnet add package WritingMango.AttributeHelper --version 1.0.0
                    
NuGet\Install-Package WritingMango.AttributeHelper -Version 1.0.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="WritingMango.AttributeHelper" Version="1.0.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="WritingMango.AttributeHelper" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="WritingMango.AttributeHelper">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
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 WritingMango.AttributeHelper --version 1.0.0
                    
#r "nuget: WritingMango.AttributeHelper, 1.0.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.
#:package WritingMango.AttributeHelper@1.0.0
                    
#: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=WritingMango.AttributeHelper&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=WritingMango.AttributeHelper&version=1.0.0
                    
Install as a Cake Tool

AttributeHelper

猜你在找:README_CN.md

Used to search for attributes usage in the current assembly at compile time.

Now only features InvokeAllMethods and GetAllMethods.

General Usage

  • Static API Only: All methods must be called statically; generic-based dynamic invocation is not supported.

    • Do not:
void TryInvoke<T>() where T : Attribute
{
	try
	{
		AttributeHelper.InvokeAllMethods<T>();
	}
	catch { }
}
  • Current Assembly Only: The search is limited to the current assembly where the helper is invoked.

  • Public/Internal Is Better: The decorated thing and the attribute should be at least internal, or it will be resolved by reflection.

    • Reflection is slower, and may throw exceptions instead of giving compile errors.
  • Cached: most results are already cached.

InvokeAllMethods

Search for any methods that are marked with the specified attribute and invoke them.

Assumes all decorated methods are static, returns void, and have no parameters or generic parameters. (or gives compile error.)

AttributeHelper.InvokeAllMethods<LoadAttribute>();

class LoadAttribute : Attribute;

class Net
{
	[Load]
	internal static void Init()
	{
		Console.WriteLine("Invoked by attribute helper.");
	}
}

GetAllMethods

Search for any methods that are marked with the specified attribute.

var methods = AttributeHelper.GetAllMethods<MakeSyncAttribute>();
...

class MakeSyncAttribute : Attribute;

class Net
{
	int i = 0;
	[MakeSync]
	internal void Advance()
	{
		i++;
	}
}
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has 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.0 129 1/24/2026