gpt4 book ai didi

asp.net - Visual Studio 2015 中的 "Visual Basic 10.0 does not support readonly auto-implemented properties"错误

转载 作者:行者123 更新时间:2023-12-02 18:12:27 26 4
gpt4 key购买 nike

我继承了一个面向 .NET 框架版本 4 的 VB.NET 网站项目,其中包括以下行:

Public ReadOnly Property Foo(Optional ByVal MyShort As Short = -1, Optional ByVal MyBool As Boolean = True) As String
Get
'logic
return Bar
End Get
End Property

我使用的是 Visual Studio 2015,无法使用该行构建项目,因为我收到错误“Visual Basic 10.0 不支持只读自动实现的属性”。

我遇到了this question其中描述了错误“VB 9 不支持自动实现的属性”,并指出 Roslyn 编译器中的错误,并建议尽可能移到 App_Code 之外以避免该问题。

有人遇到过这个错误并找到了相对轻松的解决方法吗?

我考虑过将属性更改为函数,因为当它是一个带有可选参数的内部逻辑的只读属性时,这似乎是合乎逻辑的;在这种情况下,我不知道是否允许将任何内容移出 App_Code。

最佳答案

我不知道这个错误,也不知道如何绕过它,但将此属性更改为方法的问题是有意义的。

我要问的问题是:“这个属性首先应该是一个方法吗?”

Here is some reading about that question.

除此之外,您始终可以将属性转换为方法,但您会失去一些功能( see this answer )

关于asp.net - Visual Studio 2015 中的 "Visual Basic 10.0 does not support readonly auto-implemented properties"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37188023/

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