DotNetAspects.Fody
1.0.0
Suggested Alternatives
dotnet add package DotNetAspects.Fody --version 1.0.0
NuGet\Install-Package DotNetAspects.Fody -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="DotNetAspects.Fody" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DotNetAspects.Fody" Version="1.0.0" />
<PackageReference Include="DotNetAspects.Fody" />
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 DotNetAspects.Fody --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: DotNetAspects.Fody, 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 DotNetAspects.Fody@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=DotNetAspects.Fody&version=1.0.0
#tool nuget:?package=DotNetAspects.Fody&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
DotNetAspects
A lightweight AOP (Aspect-Oriented Programming) library for .NET 8+, designed as a drop-in replacement for PostSharp's core interception APIs.
Features
- MethodInterceptionAspect: Intercept method calls with full control over execution
- OnMethodBoundaryAspect: Execute code at method boundaries (entry, success, exception, exit)
- LocationInterceptionAspect: Intercept property and field access
- PostSharp-compatible API: Minimal code changes required for migration
Installation
Add a reference to the DotNetAspects project or NuGet package.
Migration from PostSharp
Namespace Changes
Replace PostSharp namespaces with DotNetAspects equivalents:
// Before (PostSharp)
using PostSharp.Aspects;
using PostSharp.Serialization;
using PostSharp.Extensibility;
// After (DotNetAspects)
using DotNetAspects.Interception;
using DotNetAspects.Serialization;
using DotNetAspects.Extensibility;
using DotNetAspects.Args;
using DotNetAspects.Internals; // For Arguments<T>
Quick Reference
| PostSharp | DotNetAspects |
|---|---|
PostSharp.Aspects.MethodInterceptionAspect |
DotNetAspects.Interception.MethodInterceptionAspect |
PostSharp.Aspects.OnMethodBoundaryAspect |
DotNetAspects.Interception.OnMethodBoundaryAspect |
PostSharp.Aspects.LocationInterceptionAspect |
DotNetAspects.Interception.LocationInterceptionAspect |
PostSharp.Aspects.MethodInterceptionArgs |
DotNetAspects.Args.MethodInterceptionArgs |
PostSharp.Aspects.MethodExecutionArgs |
DotNetAspects.Args.MethodExecutionArgs |
PostSharp.Aspects.LocationInterceptionArgs |
DotNetAspects.Args.LocationInterceptionArgs |
PostSharp.Serialization.PSerializableAttribute |
DotNetAspects.Serialization.PSerializableAttribute |
PostSharp.Extensibility.MulticastAttributeUsageAttribute |
DotNetAspects.Extensibility.MulticastAttributeUsageAttribute |
PostSharp.Aspects.Internals.Arguments<T> |
DotNetAspects.Internals.Arguments<T> |
Usage Examples
Method Interception
using DotNetAspects.Interception;
using DotNetAspects.Args;
using DotNetAspects.Serialization;
[PSerializable]
public class LoggingAspect : MethodInterceptionAspect
{
public override void OnInvoke(MethodInterceptionArgs args)
{
Console.WriteLine($"Before: {args.Method.Name}");
// Execute the original method
args.Proceed();
Console.WriteLine($"After: {args.Method.Name}, Result: {args.ReturnValue}");
}
}
Method Boundary
using DotNetAspects.Interception;
using DotNetAspects.Args;
using DotNetAspects.Serialization;
[PSerializable]
public class TimingAspect : OnMethodBoundaryAspect
{
public override void OnEntry(MethodExecutionArgs args)
{
args.Tag = Stopwatch.StartNew();
}
public override void OnExit(MethodExecutionArgs args)
{
var sw = (Stopwatch)args.Tag!;
sw.Stop();
Console.WriteLine($"{args.Method.Name} took {sw.ElapsedMilliseconds}ms");
}
}
Property Interception
using DotNetAspects.Interception;
using DotNetAspects.Args;
using DotNetAspects.Serialization;
[PSerializable]
public class NotifyPropertyChangedAspect : LocationInterceptionAspect
{
public override void OnSetValue(LocationInterceptionArgs args)
{
var oldValue = args.GetCurrentValue();
args.ProceedSetValue();
if (!Equals(oldValue, args.Value))
{
Console.WriteLine($"Property {args.Location.Name} changed");
}
}
}
API Reference
MethodInterceptionArgs
| Property/Method | Description |
|---|---|
Instance |
The object instance (null for static methods) |
Method |
The MethodBase of the intercepted method |
Arguments |
The method arguments (IArguments) |
ReturnValue |
The return value (get/set) |
Proceed() |
Execute the original method with current arguments |
Invoke(IArguments) |
Execute the original method with custom arguments |
MethodExecutionArgs
| Property/Method | Description |
|---|---|
Instance |
The object instance (null for static methods) |
Method |
The MethodBase of the executing method |
Arguments |
The method arguments (IArguments) |
ReturnValue |
The return value (available in OnSuccess/OnExit) |
Exception |
The exception (available in OnException) |
FlowBehavior |
Control flow after aspect method returns |
Tag |
Pass state between aspect methods |
LocationInterceptionArgs
| Property/Method | Description |
|---|---|
Instance |
The object instance (null for static members) |
Location |
Information about the property/field |
Value |
The value being get/set |
GetCurrentValue() |
Get the current value from the location |
SetNewValue(value) |
Set the value to the location |
ProceedGetValue() |
Proceed with getting the value |
ProceedSetValue() |
Proceed with setting the value |
Project Structure
src/DotNetAspects/
├── Args/
│ ├── IArguments.cs
│ ├── Arguments.cs
│ ├── MethodInterceptionArgs.cs
│ ├── MethodExecutionArgs.cs
│ └── LocationInterceptionArgs.cs
├── Interception/
│ ├── MethodInterceptionAspect.cs
│ ├── OnMethodBoundaryAspect.cs
│ └── LocationInterceptionAspect.cs
├── Serialization/
│ └── PSerializableAttribute.cs
├── Extensibility/
│ ├── MulticastTargets.cs
│ └── MulticastAttributeUsageAttribute.cs
└── Internals/
└── Arguments.cs (generic versions)
License
MIT License
There are no supported framework assets in this package.
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- FodyHelpers (>= 6.8.2)
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 | 793 | 12/10/2025 |