Rougamo.Fody 1.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package Rougamo.Fody --version 1.0.3                
NuGet\Install-Package Rougamo.Fody -Version 1.0.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="Rougamo.Fody" Version="1.0.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Rougamo.Fody --version 1.0.3                
#r "nuget: Rougamo.Fody, 1.0.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 Rougamo.Fody as a Cake Addin
#addin nuget:?package=Rougamo.Fody&version=1.0.3

// Install Rougamo.Fody as a Cake Tool
#tool nuget:?package=Rougamo.Fody&version=1.0.3                

Rougamo - �����

rougamo��ʲô

��̬����֯��AOP��.NET��õ�AOPӦ����Castle DynamicProxy��rougamo�Ĺ����������ƣ�����ʵ��ȴ��Ȼ��ͬ�� DynamicProxy������ʱ����һ�������࣬ͨ��������д�ķ�ʽִ��֯����룬rougamo���Ǵ������ʱֱ���޸�IL���룬 .NET��̬AOP������һ���ܺõ����PostSharp��rougamo��ע�뷽ʽҲ���������Ƶġ�

���ٿ�ʼ(MoAttribute)

// 1.NuGet����Rougamo.Fody
// 2.������̳�MoAttribute��ͬʱ������Ҫ֯��Ĵ���
public class LoggingAttribute : MoAttribute
{
    public override void OnEntry(MethodContext context)
    {
        // ��context��������ȡ��������Ρ���ʵ����������������Ϣ
        Log.Info("����ִ��ǰ");
    }

    public override void OnException(MethodContext context)
    {
        Log.Error("����ִ���쳣", context.Exception);
    }

    public override void OnExit(MethodContext context)
    {
        Log.Info("�����˳�ʱ�����۷���ִ�гɹ������쳣������ִ��");
    }

    public override void OnSuccess(MethodContext context)
    {
        Log.Info("����ִ�гɹ���");
    }
}

// 3.Ӧ��Attribute
public class Service
{
    [Logging]
    public static int Sync(Model model)
    {
        // ...
    }

    [Logging]
    public async Task<Data> Async(int id)
    {
        // ...
    }
}
���ݷ����ɷ���������Ӧ��

�ڿ��ٿ�ʼ�н�������ν�����֯�뵽ָ�������ϣ���ʵ��ʹ��ʱ��һ���Ӵ����Ŀ���ÿ��������ܶ෽����ȥ�������Attribute ���ܻ�ܷ���������MoAttribute���Ϊ����Ӧ���ڷ���(method)����(class)������(assembly)��ģ��(module)��ͬʱ������ �ɷ��������ԣ����������

// 1.�ڼ̳�MoAttribute��ͬʱ����дFlags���ԣ�δ��дʱĬ��InstancePublic(publicʵ������)
public class LoggingAttribute : MoAttribute
{
    // ��Ϊ����public������Ч��������ʵ���������Ǿ�̬����
    public override AccessFlags Flags => AccessFlags.Public;

    // ������дʡ��
}

// 2.Ӧ��
// 2.1.Ӧ��������
[Logging]
public class Service
{
    // ��̬֯�뽫��Ӧ��
    public static void M1() { }

    // ��̬֯�뽫��Ӧ��
    public void M2() { }

    // ����Ӧ�þ�̬֯��
    protected void M3() { }
}
// 2.2.Ӧ���ڳ����ϣ��ó�������public��������Ӧ�þ�̬֯��
[assembly: Logging]

����֯��(IgnoreMoAttribute)

�ڿ��ٿ�ʼ�У����ǽ������������Ӧ�ã������������õĹ���ֻ�޶��˷����ɷ����ԣ����Կ�����Щ���Ϲ���ķ���������Ӧ��֯�룬 ��ʱ���ʹ��IgnoreMoAttribute��ָ������/����б�ǣ���ô�÷���/��(�����з���)��������֯�롣�����IgnoreMoAttribute Ӧ�õ�����(assembly)��ģ��(module)����ô�ó���(assembly)/ģ��(module)����������֯�롣���⣬��Ӧ��IgnoreMoAttribute ʱ������ͨ��MoTypesָ�����Ե�֯�����͡�

// ��ǰ���򼯺�������֯��
[assembly: IgnoreMo]
// ��ǰ���򼯺���TheMoAttribute��֯��
[assembly: IgnoreMo(MoTypes = new[] { typeof(TheMoAttribute))]

// ��ǰ���������֯��
[IgnoreMo]
class Class1
{
    // ...
}

// ��ǰ�����TheMoAttribute��֯��
[IgnoreMo(MoTypes = new[] { typeof(TheMoAttribute))]
class Class2
{
    // ...
}

ͨ��ʵ�ֿսӿڵķ�ʽ����֯��(IRougamo<>)

���ÿ����������Attribute��Ǹо�̫����������ͨ�������ɷ����Խ�������֯���ֲ����Զ��壬��ô�÷�ʽ�����������������

// 1.������Ҫ֯��Ĵ��룬Ҳ����ֱ��ʹ�ÿ��ٿ�ʼ�ж����LoggingAttribute
public class LoggingMo : IMo
{
    public override AccessFlags Flags => AccessFlags.All;

    public override void OnEntry(MethodContext context)
    {
        // ��context��������ȡ��������Ρ���ʵ����������������Ϣ
        Log.Info("����ִ��ǰ");
    }

    public override void OnException(MethodContext context)
    {
        Log.Error("����ִ���쳣", context.Exception);
    }

    public override void OnExit(MethodContext context)
    {
        Log.Info("�����˳�ʱ�����۷���ִ�гɹ������쳣������ִ��");
    }

    public override void OnSuccess(MethodContext context)
    {
        Log.Info("����ִ�гɹ���");
    }
}

// 2.����սӿ�
public interface ILoggingRougamo : IRougamo<LoggingMo>
{
}

// 3.Ӧ�ÿսӿڣ��������ʱϰ�߽�ͬһ����/������ඨ��һ�����ӿ�/���࣬��ôֻ��Ҫ���ӿ�/����ʵ�ָýӿڼ���
public interface IRepository<TModel, TId> : ILoggingRougamo
{
    // ...
}

֯�뻥��

�����ͻ���(IRougamo<,>)

����������Attribute��Ǻͽӿ�ʵ������֯�뷽ʽ����ô�Ϳ��ܳ���ͬʱӦ�õ���������������֯�����������ͬ�ģ��Ǿͻ���� �ظ�֯��������Ϊ�˾�����������������ڽӿڶ���ʱ�����Զ��廥�����ͣ�Ҳ����ͬʱֻ��һ������Ч�������ĸ���Ч������ ���ȼ�����

public class Mo1Attribute : MoAttribute
{
    // ...
}
public class Mo2Attribute : MoAttribute
{
    // ...
}
public class Mo3Attribute : MoAttribute
{
    // ...
}

public class Test : IRougamo<Mo1Attribute, Mo2Attribute>
{
    [Mo2]
    public void M1()
    {
        // Mo2AttributeӦ���ڷ����ϣ����ȼ����ڽӿ�ʵ�ֵ�Mo1Attribute��Mo2Attribute����Ӧ��
    }

    [Mo3]
    public void M2()
    {
        // Mo1Attribute��Mo3Attribute�����⣬����������Ӧ��
    }
}
�����ͻ���(IRepulsionsRougamo<,>)

IRougamo<,>ֻ����һ�����ͻ��⣬IRepulsionsRougamo<,>������������ͻ���

public class Mo1Attribute : MoAttribute
{
}
public class Mo2Attribute : MoAttribute
{
}
public class Mo3Attribute : MoAttribute
{
}
public class Mo4Attribute : MoAttribute
{
}
public class Mo5Attribute : MoAttribute
{
}

public class TestRepulsion : MoRepulsion
{
    public override Type[] Repulsions => new[] { typeof(Mo2Attribute), typeof(Mo3Attribute) };
}

[assembly: Mo2]
[assembly: Mo5]

public class Class2 : IRepulsionsRougamo<Mo1Attribute, TestRepulsion>
{
    [Mo3]
    public void M1()
    {
        // Mo1��Mo2��Mo3���⣬������Mo3���ȼ�����Mo1������Mo1����Чʱ�����л������Ͷ�����Ч
        // ��������Mo2Attribute��Mo3Attribute��Mo5Attribute����Ӧ��
        Console.WriteLine("m1");
    }

    [Mo4]
    public void M2()
    {
        // Mo1��Mo2��Mo3���⣬������Mo1���ȼ�����Mo2������Mo2������Ч
        // ����Mo1Attribute��Mo4Attribute��Mo5Attribute����Ӧ��
        Console.WriteLine("m2");
    }
}

<font color=red>ͨ����������ӣ������ע�⵽����������ͻ��Ⲣ���Ƕ�����֮�以�໥�⣬���ǵ�һ��������ڶ������Ͷ�������ͻ��⣬ �ڶ�������֮�䲢�����⣬Ҳ���������ʾ����������Mo1Attribute����Чʱ�����������Mo2Attribute��Mo3Attribute������Ч�� ������Ҫ��⣬���廥���ԭ����Attribute�Ϳսӿ�ʵ�����ַ�ʽ���ܴ��ڵ��ظ�Ӧ�ã���������Ϊ���ų�����֯����ظ���ͬʱҲ���Ƽ�ʹ�� �໥�ⶨ�壬�������׳����߼����ң�������Ӧ��֯��ǰ��ϸ˼��һ��ͳһ�Ĺ��򣬶��������ⶨ�壬Ȼ����ͼʹ�ö໥�����������</font>

Attribute����֯��(MoProxyAttribute)

������Ѿ�ʹ��һЩ�����������һЩ����������Attribute��ǣ�������ϣ������Щ��ǹ��ķ�������aop���������ֲ���һ��һ���ֶ�����rougamo ��Attribute��ǣ���ʱ�����ͨ������ķ�ʽһ�����aop֯�롣�ٱ��������Ŀ�����кܶ�����ObsoleteAttribute�Ĺ�ʱ��������ϣ�� �ڹ��ڷ����ڱ�����ʱ������ö�ջ��־�������Ų�������Щ�����ʹ����Щ���ڷ�����Ҳ����ͨ���÷�ʽ��ɡ�

public class ObsoleteProxyMoAttribute : MoAttribute
{
    public override void OnEntry(MethodContext context)
    {
        Log.Warning("���ڷ����������ˣ�" + Environment.StackTrace);
    }
}

[module: MoProxy(typeof(ObsoleteAttribute), typeof(ObsoleteProxyMoAttribute))]

public class Cls
{
    [Obsolete]
    private int GetId()
    {
        // �÷�����Ӧ��֯�����
        return 123;
    }
}

���ȼ�(Priority)

  1. IgnoreMoAttribute
  2. Method MoAttribute
  3. Method MoProxyAttribute
  4. Type MoAttribute
  5. Type MoProxyAttribute
  6. Type IRougamo<>, IRougamo<,>, IRepulsionsRougamo<,>
  7. Assembly & Module MoAttribute

����(enable/disable)

Rougamo�ɸ��˿����������������ޣ���IL���о�Ҳ������ô����͸������������.NET�ķ�չҲ�᲻�ϵij���һЩ�µ����͡��µ����������µ�ILָ� Ҳ��˿��ܻ����һЩBUG������IL�����BUG�����޷����ٶ�λ�����Ⲣ�޸������������ṩ��һ�����ؿ����ڲ�ȥ��Rougamo���õ�����²����д���֯�룬 Ҳ����Ƽ���λ��ʹ��Rougamo���д���֯��ʱ��֯��Ĵ����Dz�Ӱ��ҵ��ģ�������־��APM�����ϣ��ʹ���ȶ��������������ܹ����ٵõ�֧�ֵľ�̬֯�� ������Ƽ�ʹ��PostSharp

Rougamo����fody�Ļ������з��ģ�����Rougamo���״α��������һ��FodyWeavers.xml�ļ���Ĭ����������

<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
  <Rougamo />
</Weavers>

��ϣ������Rougamoʱ����Ҫ�������ļ���Rougamo�ڵ���������enabled������ֵΪfalse

<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
  <Rougamo enabled="false" />
</Weavers>

��¼yield return IEnumerable/IAsyncEnumerable����ֵ

����֪����ʹ��yield return�﷨��+IEnumerable����ֵ�ķ������ڵ��÷��������󣬸÷����Ĵ���ʵ�ʲ�û��ִ�У������ʵ��ִ����������� ���IEnumerable�������Ԫ��ʱ�򣬱�����ȥforeach���������ߵ���ToList/ToArray��ʱ�򣬲��ҷ��ص���ЩԪ�ز�û��һ������/������� ͳһ�ı��棨����ԭ�������ﲻչ��˵���ˣ�������Ĭ���������û�а취ֱ�ӻ�ȡ��yield return IEnumerable���ص�����Ԫ�ؼ��ϵġ�

��������Щ�Դ����رȽ��ϸ�ij�����Ҫ��¼���з���ֵ��������ʵ�����Ҵ�����һ�����鱣�������еķ���Ԫ�أ�����������������Ƕ��ⴴ���ģ���ռ �ö�����ڴ�ռ䣬ͬʱ�ֲ�������IEnumerable���ص�Ԫ�ؼ����ж������Ϊ�˱�����ܶ������������ڴ����ģ�Ĭ��������Dz����¼ yield return IEnumerable����ֵ�ģ������Ҫ��¼����ֵ����Ҫ��FodyWeavers.xml��Rougamo�ڵ�������������enumerable-returns="true"

<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
  <Rougamo enumerable-returns="true" />
</Weavers>

todo

  1. ���Դ���
  2. Ӣ���ĵ�
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

NuGet packages (42)

Showing the top 5 NuGet packages that depend on Rougamo.Fody:

Package Downloads
HandeSoft.Core

Package Description

HandeSoft.Web.Core

Package Description

BotSharp.Abstraction

Package Description

Ray.Infrastructure

This client library is a infrastructure that including extensions and helpers etc.

HZY.Framework.Core

HZY Framework 核心 1、ScheduledAttribute 定时任务特性标记 2、IServerMetricMonitoringService 服务器指标监控 CPU、内存、硬盘、运行时长 3、HZY.Framework.DynamicApiController 动态Api控制器 4、HZY.Framework.DependencyInjection 依赖注入

GitHub repositories (6)

Showing the top 5 popular GitHub repositories that depend on Rougamo.Fody:

Repository Stars
RayWangQvQ/BiliBiliToolPro
B 站(bilibili)自动任务工具,支持docker、青龙、k8s等多种部署方式。敏感肌也能用。
dotnetcore/FreeSql
🦄 .NET aot orm, C# orm, VB.NET orm, Mysql orm, Postgresql orm, SqlServer orm, Oracle orm, Sqlite orm, Firebird orm, 达梦 orm, 人大金仓 orm, 神通 orm, 翰高 orm, 南大通用 orm, 虚谷 orm, 国产 orm, Clickhouse orm, DuckDB orm, TDengine orm, QuestDB orm, MsAccess orm.
SciSharp/BotSharp
AI Multi-Agent Framework in .NET
ThingsGateway/ThingsGateway
ThingsGateway is a cross platform high-performance edge acquisition gateway based on Net8, providing underlying PLC communication libraries, communication debugging software, and more.
2881099/FreeSql.AdminLTE
这是一个 .NETCore MVC 中间件,基于 AdminLTE 前端框架动态产生 FreeSql 实体的增删查改界面。
Version Downloads Last updated
4.0.4 4,388 9/29/2024
4.0.4-preview-1727349912 97 9/26/2024
4.0.3 1,244 9/16/2024
4.0.3-preview-1726120802 101 9/12/2024
4.0.3-preview-1725957423 109 9/10/2024
4.0.2 545 9/9/2024
4.0.2-preview-1725956948 100 9/10/2024
4.0.2-preview-1725875652 99 9/9/2024
4.0.2-preview-1725466232 101 9/4/2024
4.0.1 2,642 9/2/2024
4.0.1-preview-1725141430 93 8/31/2024
4.0.0 6,362 8/10/2024
4.0.0-priview-1723306347 114 8/10/2024
4.0.0-priview-1722831925 91 8/5/2024
3.1.0 1,516 7/16/2024
3.0.2 447 7/8/2024
3.0.2-priview-1720363148 108 7/7/2024
3.0.2-priview-1720251661 106 7/6/2024
3.0.1 190 7/4/2024
3.0.1-priview-1720089186 111 7/4/2024
3.0.1-priview-1720085112 94 7/4/2024
3.0.0 3,554 5/4/2024
3.0.0-priview-1714754497 83 5/3/2024
3.0.0-priview-1714407561 136 4/29/2024
2.3.1 7,581 4/23/2024
2.3.1-priview-1713854631 119 4/23/2024
2.3.1-priview-1713791514 107 4/22/2024
2.3.0 3,812 3/10/2024
2.3.0-priview-1709894403 120 3/8/2024
2.2.0 2,998 1/20/2024
2.2.0-priview-1705656978 114 1/19/2024
2.2.0-priview-1705571301 108 1/18/2024
2.2.0-priview-1705566213 116 1/18/2024
2.2.0-priview-1702899195 187 12/18/2023
2.1.1 4,646 12/14/2023
2.1.1-priview-1702545048 147 12/14/2023
2.1.1-priview-1702542781 145 12/14/2023
2.0.1 1,259 11/16/2023
2.0.0 3,018 10/8/2023
2.0.0-priview-1696783135 140 10/8/2023
2.0.0-priview-1696592398 135 10/6/2023
2.0.0-priview-1695658688 159 9/25/2023
2.0.0-priview-1695465141 152 9/23/2023
2.0.0-priview-1680984436 224 4/8/2023
2.0.0-priview-1680981587 186 4/8/2023
1.4.1 11,579 3/12/2023
1.4.1-priview-1678603084 193 3/12/2023
1.4.1-priview-1678557697 194 3/11/2023
1.4.1-priview-1678557463 190 3/11/2023
1.4.0 2,680 3/1/2023
1.4.0-beta 367 2/27/2023
1.4.0-alpha 237 2/25/2023
1.3.4 58,023 2/17/2023
1.3.3 984 1/17/2023
1.3.2 18,581 12/20/2022
1.3.1 344 12/20/2022
1.3.1-beta 181 12/14/2022
1.3.0 1,284 12/8/2022 1.3.0 is deprecated because it has critical bugs.
1.2.3 350 1/17/2023
1.2.2 323 12/20/2022
1.2.2-beta 171 12/14/2022
1.2.1 699 11/29/2022
1.2.1-beta 168 11/29/2022
1.2.0 2,067 9/14/2022 1.2.0 is deprecated.
1.2.0-beta 188 9/12/2022
1.2.0-alpha2 176 9/12/2022
1.2.0-alpha1 183 8/31/2022
1.2.0-alpha 176 8/30/2022
1.1.4 376 11/29/2022
1.1.4-alpha 192 12/25/2022
1.1.3 535 9/11/2022 1.1.3 is deprecated because it has critical bugs.
1.1.2 1,653 8/22/2022
1.1.2-beta 183 8/22/2022
1.1.1 2,870 8/8/2022
1.1.1-beta 193 8/1/2022
1.1.0 633 7/28/2022
1.1.0-beta 208 7/15/2022
1.1.0-alpha4 191 6/24/2022
1.1.0-alpha3 178 6/24/2022
1.1.0-alpha2 177 6/23/2022
1.1.0-alpha1 179 6/22/2022
1.1.0-alpha 193 5/22/2022
1.0.3 717 5/6/2022
1.0.3-beta 198 4/26/2022
1.0.2 706 12/23/2021
1.0.1 7,751 11/23/2021
1.0.1-beta 4,922 11/23/2021

fix #2, Execute OnException, OnSuccess, OnExit in reverse order, add configuration 'reverse-call-ending' that can be adjusted for executeion order.