WritingMango.AttributeHelper
1.0.0
dotnet add package WritingMango.AttributeHelper --version 1.0.0
NuGet\Install-Package WritingMango.AttributeHelper -Version 1.0.0
<PackageReference Include="WritingMango.AttributeHelper" Version="1.0.0"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="WritingMango.AttributeHelper" Version="1.0.0" />
<PackageReference Include="WritingMango.AttributeHelper"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add WritingMango.AttributeHelper --version 1.0.0
#r "nuget: WritingMango.AttributeHelper, 1.0.0"
#:package WritingMango.AttributeHelper@1.0.0
#addin nuget:?package=WritingMango.AttributeHelper&version=1.0.0
#tool nuget:?package=WritingMango.AttributeHelper&version=1.0.0
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++;
}
}
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 |