gpt4 book ai didi

c# - 使用标准 .NET Framework 的类似 AOP 属性的基本实现

转载 作者:IT王子 更新时间:2023-10-29 04:46:54 34 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
C# wrap method via attributes

我想实现这样的功能:

[Atomic]
public void Foo()
{
/* foo logic */
}

其中[Atomic] attribute 是一个属性,它把函数逻辑包装在一个事务范围内:

using(var scope = new TransactionScope())
{
/* foo logic */
scope.Complete();
}

这样的属性怎么写?

我之前问过基本一样question ,我知道这可以使用 AOP 来完成,但我没有提到我正在寻找一些最简单的概念实现证明或有用的文章,它们可以帮助我使用纯 .NET Framework 来编写它(我想使用 RealProxy MarshalByRefObject 类型,我已经阅读了浏览相关问题)。

我需要准确地解决这个显示的例子。这似乎是一件基本的事情,所以我想从头开始学习如何做。现在不需要安全和灵活。

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com