开发者

Organizing Extensions Functions in a Lib

In designing a library that is fluent and that relies on extension functions what would be a way to provide an alternative behavior of an extensions function?

So for instance a library that does some kind of formatting:

(123.45687开发者_如何学Go9)
   .RoundTo(2) // Rounds to 2 places
   .ToCurrency() // Applies the appropriate currency symbol
   .ToString()

Given that RoundTo, and ToCurrency would be extension functions, what would be a way to change the behavior of RoundTo and/or ToCurrency?

Thanks, L-


If by overriding you mean having an extension function virtual in a base class and overridden in a derived class, then you cannot - extension functions must be static, and static functions cannot be overridden.

EDIT: after your clarification, maybe you could write a configuration section for the library (or just use the application settings) and have your library read the configuration parameters.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜