gpt4 book ai didi

c# - 是否可以在命令行或通过配置文件为 "InternalsVisibleTo"添加包?

转载 作者:行者123 更新时间:2023-11-30 22:53:29 25 4
gpt4 key购买 nike

我们有一些方法是内部的,但人们可能需要在测试项目(且仅测试项目)中可见。为此,我们必须在类的顶部添加一堆 InternalsVisibleTo 语句。这是一个可以被许多其他项目使用并帮助进行测试和验证的库,我们希望制作可以在运行时设置可以看到内部结构的包。

这可能吗?

示例(伪代码):

[assembly: InternalsVisibleTo( System.ReadFromCommandLine("package"))]

最佳答案

不,这不可能。 InternalsVisibleTo 等属性的值必须是编译时常量。

An expression E is an attribute_argument_expression if all of the following statements are true:

  • The type of E is an attribute parameter type (Attribute parameter types).
  • At compile-time, the value of E can be resolved to one of the following:
    • A constant value.
    • A System.Type object.
    • A one-dimensional array of attribute_argument_expressions.

已添加粗体字,source .

关于c# - 是否可以在命令行或通过配置文件为 "InternalsVisibleTo"添加包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57166512/

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