gpt4 book ai didi

c# - 为什么不编译多次使用 PreApplicationStartMethodAttribute?

转载 作者:太空狗 更新时间:2023-10-29 22:53:09 25 4
gpt4 key购买 nike

System.Web.PreApplicationStartMethodAttribute 定义为:

[AttributeUsage(AttributeTargets.Assembly, AllowMultiple=true)]
public sealed class PreApplicationStartMethodAttribute : Attribute
{}

即它允许多次使用 (AllowMultiple=true)。但是,如果我尝试将此属性的几种用法添加到我的程序集中:

[assembly: PreApplicationStartMethod(typeof(MyType1), "Start")]
[assembly: PreApplicationStartMethod(typeof(MyType2), "Start")]

我得到编译器错误:

Error 2 Duplicate 'PreApplicationStartMethod' attribute

这是为什么?

最佳答案

我怀疑你在看 .NET 4.5 version ,它被记录为具有 AllowMultiple = True

documentation for the .NET 4.0 version显示为 AllowMultiple = false:

[AttributeUsageAttribute(AttributeTargets.Assembly, AllowMultiple = false)]
public sealed class PreApplicationStartMethodAttribute : Attribute

因此,如果您以 .NET 4.5 为目标,应该没问题。

关于c# - 为什么不编译多次使用 PreApplicationStartMethodAttribute?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11800954/

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