很酷的 PostSharp 方面

发布于 2024-07-13 10:19:49 字数 1436 浏览 7 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

呆萌少年 2024-07-20 10:19:49

对我来说最酷的一点是它可以帮助我实现单一责任原则

< em>“在面向对象的编程中,单一责任原则规定每个对象都应该有单一的责任,并且它的所有服务都应该与该责任紧密结合。”

我希望更全面地采用这一点未来的经验,但现在,我刚刚开始将其内置到我的日志记录需求中:

Log4PostSharp,我可以这样做:

[Log(LogLevel.Info, "Counting characters.")]
int CountCharacters(string arg) {
   return arg.Length;
}

这意味着,日志记录的责任归因于其他地方(编码方面),并通过 PostSharp 和 Log4PostSharp 魔法从单独的源注入。

The coolest aspect of it for me is that it can help me implement the single responsibility principle:

"In object-oriented programming, the single responsibility principle states that every object should have a single responsibility, and that all its services should be narrowly aligned with that responsibility."

I hope to adopt this more fully with more experience in the future, but for now, I have just started with having it built in to my logging needs:

together with Log4PostSharp, I can do:

[Log(LogLevel.Info, "Counting characters.")]
int CountCharacters(string arg) {
   return arg.Length;
}

What this means is that, the responsibility of logging is ascribed elsewhere (coding wise), and injected from a separate source by PostSharp and Log4PostSharp magic.

只是我以为 2024-07-20 10:19:49

D. Patrick Caldwell 在他的博客上有一些很酷的想法。

使用属性和 PostSharp 验证参数
http://dpatrickcaldwell.blogspot.com/2009/03/ validate-parameters-using-attributes.html

  • 使用 PostSharp 实现编码契约。

使用 PostSharp 的 Memoizer 属性
http://dpatrickcaldwell.blogspot.com/2009/02/ memoizer-attribute-using-postsharp.html

  • 基本上是一种轻量级字段值缓存机制。

D. Patrick Caldwell has some cool ideas on his blog.

Validate Parameters Using Attributes and PostSharp
http://dpatrickcaldwell.blogspot.com/2009/03/validate-parameters-using-attributes.html

  • Implmementing Coding Contracts using PostSharp.

Memoizer Attribute Using PostSharp
http://dpatrickcaldwell.blogspot.com/2009/02/memoizer-attribute-using-postsharp.html

  • Basically, a light-weight field-value caching mechanism.
赠意 2024-07-20 10:19:49

愚蠢的问题,但这不是 贡献目录 的目的吗?

有一个自动属性更改实现的示例 - INotifyPropertyChanged

Daft question, but isn't that the purpose of the Contributions Directory?

There is an example of automatic property-change implementation - INotifyPropertyChanged.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文