gpt4 book ai didi

c# - 我们什么时候需要使用System.AppContext?

转载 作者:太空狗 更新时间:2023-10-29 17:50:34 25 4
gpt4 key购买 nike

AppContext 似乎只有一个名为 BaseDirectory 的属性。但是 Environment 类似乎有更多的属性和方法。

那么 AppContext 现在是否被 Environment 类取代了?

最佳答案

AppContext 已随 .NET 4.6 引入,因此不会被替换。

MSDN说:

AppContext is a new compatibility feature that enables library writersto provide a uniform opt-out mechanism for new functionality for theirusers. It established a loosley-coupled contract between components inorder to communicate an opt-out request. This capability is typicallyimportant when a change is made to existing functionality. Conversely,there is already an implicit opt-in for new functionality.

With AppContext, libraries define and expose compatibility switches,while code that depends on them can set those switches, to affect thelibrary behavior. By default libraries provide the new functionalityand only alter it (e.g. provide the old behavior) if the switch isset.

总而言之,它提供了处理同一个 dll 的多个版本的功能。

代码示例在提供的链接中。

关于c# - 我们什么时候需要使用System.AppContext?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31152167/

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