自动实现的属性必须同时定义 get 和 set 访问器 [英] Automatically implemented properties must define both get and set accessors

查看:42
本文介绍了自动实现的属性必须同时定义 get 和 set 访问器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SQLCLR Visual Studio 2015

SQLCLR Visual Studio 2015

我刚开始编写 CLR 代码.

I'm new to writing CLR code.

编译 SQL CLR 函数时出现以下错误

I'm getting the following error when compiling a SQL CLR Function

我正在使用 .Net 坐标库.

有问题的代码是

public Datum.Datum Datum { get; }

在 C# 控制台应用程序(不是 CLR)中编译时,相同的库使用 Visual Studio 2015 构建并成功执行.

The same library when compiled in a C# console application (not CLR) builds and executes successfully using Visual Studio 2015.

我的理解是,通过使用 Visual Studio,我使用的是 C# v6.

My understanding is that by using Visual Studio I'm using C# v6.

.sqlproj 是否会强制使用早期版本的 C#?

Could the .sqlproj be forcing the use of a earlier version of C#?

推荐答案

主要问题似乎是 Visual Studio 和 .NET Framework/CLR 之间的脱节.Visual Studio 似乎可以更新为使用较新版本的 C#,独立于您计算机上实际存在的任何新版本.

The main issue seems to be a disconnect between Visual Studio and the .NET Framework / CLR. Visual Studio, it seems, can be updated to use newer versions of C#, independently of any new version(s) actually existing on your machine.

不应该需要在高级 SQLCLR 构建属性中指定 using C# 6.0,但这样做会为您提供一个有见地的错误消息:

You shouldn't need to specify using C# 6.0 in the advanced SQLCLR build properties, but doing so gives you an error message that is insightful:

/langversion 的选项6"无效;必须是 ISO-1、ISO-2、3、4、5 或默认

Invalid option '6' for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default

查看输出消息(假设级别足够高)它应该表明您正在使用 C:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe,所以.sqlproj 文件或 SSDT 似乎没有在此处强制执行任何操作.但是,如果您转到命令提示符,请转到包含 Csc.exe 的文件夹并直接运行它(即在提示符下仅使用 Csc),您应该看到以下内容注意:

Looking at the output messages (assuming a high-enough level) it should show that you are using C:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe, so it doesn't appear that the .sqlproj file or SSDT is forcing anything here. But, if you go to a command prompt, go to the folder containing Csc.exe and run it directly (i.e. just Csc at the prompt), you should see the follow note:

Microsoft (R) Visual C# 编译器版本 4.6.1590.0
用于 C# 5
版权所有 (C) 微软公司.版权所有.

Microsoft (R) Visual C# Compiler version 4.6.1590.0
for C# 5
Copyright (C) Microsoft Corporation. All rights reserved.

此编译器作为 Microsoft (R) .NET Framework 的一部分提供,但仅支持最高 C# 5 的语言版本,该版本不再是最新版本.有关支持更新版本的 C# 编程语言的编译器,请参阅 http://go.microsoft.com/fwlink/?LinkID=533240

This compiler is provided as part of the Microsoft (R) .NET Framework, but only supports language versions up to C# 5, which is no longer the latest version. For compilers that support newer versions of the C# programming language, see http://go.microsoft.com/fwlink/?LinkID=533240

该链接会将您带到 Roslyn 的 GitHub 存储库.为方便起见,这里是该页面的直接链接,从下载编译器部分开始,无需下载 Visual Studio(因为您已经拥有了):

That link takes you to the GitHub repository for Roslyn. To make things easier, here is the link directly to that page, starting at the section for downloading the compiler without also downloading Visual Studio (since you already have that):

https://github.com/dotnet/roslyn#download-c-and-visual-basic

这篇关于自动实现的属性必须同时定义 get 和 set 访问器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆