c#-7.1

Using C# 7.1 default literal in nullable optional argument causes unexpected behavior

只谈情不闲聊 提交于 2021-02-07 11:53:30
问题 C# 7.1 introduces a new feature called "Default Literals" that allows new default expressions. // instead of writing Foo x = default(Foo); // we can just write Foo x = default; For Nullable<T> types, the default value is null , and with the usual usage this works as expected: int? x = default(int?); // x is null int? x = default; // x is null However, when I try to use the new default literal as an optional argument (parameter) of a function, it's not working as expected: static void Foo(int?

Switch based on generic argument type

一笑奈何 提交于 2020-08-24 08:34:17
问题 In C# 7.1 the below is valid code: object o = new object(); switch (o) { case CustomerRequestBase c: //do something break; } However, I want to use the pattern switch statement in the following scenario: public T Process<T>(object message, IMessageFormatter messageFormatter) where T : class, IStandardMessageModel, new() { switch (T) { case CustomerRequestBase c: //do something break; } } The IDE gives me the error "'T' is a type, which is not valid in the given context" Is there an elegant

Switch based on generic argument type

安稳与你 提交于 2020-08-24 08:31:32
问题 In C# 7.1 the below is valid code: object o = new object(); switch (o) { case CustomerRequestBase c: //do something break; } However, I want to use the pattern switch statement in the following scenario: public T Process<T>(object message, IMessageFormatter messageFormatter) where T : class, IStandardMessageModel, new() { switch (T) { case CustomerRequestBase c: //do something break; } } The IDE gives me the error "'T' is a type, which is not valid in the given context" Is there an elegant

C# 7.1 can't be published

旧巷老猫 提交于 2019-12-18 14:12:24
问题 I have ASP.NET Core C# web application. I made some changes that now use C# 7.1 features. I changed project version, so it compiles and runs fine. However, when I try to publish the project, I am getting an error: Feature 'default literal' is not available in C# 7.0. Please use language version 7.1 or greater. Compile command that I see is: C:...\.nuget\packages\microsoft.net.compilers\2.6.1\tools\csc.exe /noconfig /unsafe- /checked- /nowarn:1701,1702,1705,1701,1702,2008 /nostdlib+

Using C# 7.1 with MSBuild

早过忘川 提交于 2019-12-09 07:41:27
问题 To use the new C# 7.1 language features with Visual Studio 2017, you add the setting <LangVersion>latest</LangVersion> to your project file(s). However, building such projects from MSBuild (version 15.3.409.57025, located at C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin ) results in an error: CSC : error CS1617: Invalid option 'latest' for /langversion; must be ISO-1, ISO-2, Default or an integer in range 1 to 6. Is this feature just not yet supported by

Using C# 7.1 with MSBuild

假如想象 提交于 2019-12-03 09:41:05
To use the new C# 7.1 language features with Visual Studio 2017, you add the setting <LangVersion>latest</LangVersion> to your project file(s). However, building such projects from MSBuild (version 15.3.409.57025, located at C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin ) results in an error: CSC : error CS1617: Invalid option 'latest' for /langversion; must be ISO-1, ISO-2, Default or an integer in range 1 to 6. Is this feature just not yet supported by MSBuild, or is it possible to get this working? This covers 200+ projects that were originally created