"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:
[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.
发布评论
评论(3)
对我来说最酷的一点是它可以帮助我实现单一责任原则:
< em>“在面向对象的编程中,单一责任原则规定每个对象都应该有单一的责任,并且它的所有服务都应该与该责任紧密结合。”
我希望更全面地采用这一点未来的经验,但现在,我刚刚开始将其内置到我的日志记录需求中:
与 Log4PostSharp,我可以这样做:
这意味着,日志记录的责任归因于其他地方(编码方面),并通过 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:
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.
D. Patrick Caldwell 在他的博客上有一些很酷的想法。
使用属性和 PostSharp 验证参数
http://dpatrickcaldwell.blogspot.com/2009/03/ validate-parameters-using-attributes.html
使用 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
Memoizer Attribute Using PostSharp
http://dpatrickcaldwell.blogspot.com/2009/02/memoizer-attribute-using-postsharp.html
愚蠢的问题,但这不是 贡献目录 的目的吗?
有一个自动属性更改实现的示例 - INotifyPropertyChanged。
Daft question, but isn't that the purpose of the Contributions Directory?
There is an example of automatic property-change implementation - INotifyPropertyChanged.