c#-6.0

TFS 2013 building .NET 4.6 / C# 6.0

假装没事ソ 提交于 2019-11-26 13:21:28
We use TFS 2013 to as our build server. I've started a C# 6.0 project and I am trying to get it to build. I am using the new null-conditional operators, and my build chokes. I've tried installing several things on the TFS server, including the targeting pack and VS 2015. I've tried providing /tv:14.0 to the MSBuild arguments. Configuration\EntityEntityConfig.cs (270): Invalid expression term '.' Configuration\EntityEntityConfig.cs (283): Invalid expression term '.' Configuration\EntityEntityConfig.cs (283): Syntax error, ':' expected ... etc. At this point, I have no idea what else to try. Any

C# 6.0 Features Not Working with Visual Studio 2015

心已入冬 提交于 2019-11-26 12:56:42
I am testing Visual Studio 2015 with C# 6.0 but the language features are not working. In an MVC web application, the following code does compile: if (!string.IsNullOrWhiteSpace(Model.Profile?.TypeName)) { // More logic here... } However, when I run the application via Debug and IIS Express, I get the following error: CS1525: Invalid expression term '.' How do I enable these features? This works in MVC 5 (tested 5.2.3), you just need to add the roslyn code dom Nuget package CodeDOM Providers for .NET Compiler... Replacement CodeDOM providers that use the new .NET Compiler Platform ("Roslyn")

C# Null propagating operator / Conditional access expression & if blocks

痴心易碎 提交于 2019-11-26 11:36:05
问题 The Null propagating operator / Conditional access expression coming in c#-6.0 looks like quite a handy feature. But I\'m curious if it will help solve the problem of checking if a child member is not null and then calling a Boolean method on said child member inside an if block: public class Container<int>{ IEnumerable<int> Objects {get;set;} } public Container BuildContainer() { var c = new Container(); if (/* Some Random Condition */) c.Objects = new List<int>{1,2,4}; } public void Test()

String Interpolation with format variable

元气小坏坏 提交于 2019-11-26 11:28:44
问题 I can do this: var log = string.Format(\"URL: {0}\", url); or even like this var format = \"URL: {0}\"; ... var log = string.Format(format, url); I have a format defined somewhere else and use the format variable, not inline string. In C# 6, this is seems impossible: var format = $\"URL: {url}\"; // Error url does not exist ... var url = \"http://google.com\"; ... var log = $format; // The way to evaluate string interpolation here Is there anyway to use string interpolation with variable

Long string interpolation lines in C#6

牧云@^-^@ 提交于 2019-11-26 10:47:43
问题 I\'ve found that while string interpolation is really nice when applied to my existing code base\'s string Format calls, given the generally preferred column limit, the string rapidly becomes too long for a single line. Especially when the expressions being interpolated are complex. With a format string you have a list of variables that you can split into multiple lines. var str = string.Format(\"some text {0} more text {1}\", obj1.property, obj2.property); Does anyone have any preferred

C#6.0 string interpolation localization

蓝咒 提交于 2019-11-26 09:36:10
问题 C#6.0 have a string interpolation - a nice feature to format strings like: var name = \"John\"; WriteLine($\"My name is {name}\"); The example is converted to var name = \"John\"; WriteLine(String.Format(\"My name is {0}\", name)); From the localization point of view, it is much better to store strings like : \"My name is {name} {middlename} {surname}\" than in String.Format notation: \"My name is {0} {1} {2}\" How to use the string interpolation for .NET localization? Is there going to be a

What is the purpose of nameof?

南楼画角 提交于 2019-11-26 09:15:39
问题 Version 6.0 got a new feature of nameof , but I can\'t understand the purpose of it, as it just takes the variable name and changes it to a string on compilation. I thought it might have some purpose when using <T> but when I try to nameof(T) it just prints me a T instead of the used type. Any idea on the purpose? 回答1: What about cases where you want to reuse the name of a property, for example when throwing exception based on a property name, or handling a PropertyChanged event. There are

Await in catch block

十年热恋 提交于 2019-11-26 08:24:30
问题 I have the following code: WebClient wc = new WebClient(); string result; try { result = await wc.DownloadStringTaskAsync( new Uri( \"http://badurl\" ) ); } catch { result = await wc.DownloadStringTaskAsync( new Uri( \"http://fallbackurl\" ) ); } Basically I want to download from a URL and when it fails with an exception I want to download from another URL. Both time async of course. However the code does not compile, because of error CS1985: Cannot await in the body of a catch clause OK, it\

Is nameof() evaluated at compile-time?

ⅰ亾dé卋堺 提交于 2019-11-26 08:21:40
问题 In C# 6, you can use the nameof() operator to get a string containing the name of a variable or a type. Is this evaluated at compile-time, or at runtime via some Roslyn API? 回答1: Yes. nameof() is evaluated at compile-time. Looking at the latest version of the specs: The nameof expression is a constant. In all cases, nameof(...) is evaluated at compile-time to produce a string. Its argument is not evaluated at runtime, and is considered unreachable code (however it does not emit an

How do I use the C#6 “Using static” feature?

Deadly 提交于 2019-11-26 07:24:29
问题 I\'m having a look at a couple of the new features in C# 6, specifically, \"using static\" . using static is a new kind of using clause that lets you import static members of types directly into scope. (Bottom of the blog post) The idea is as follows, according to a couple of tutorials I found, Instead of: using System; class Program { static void Main() { Console.WriteLine(\"Hello world!\"); Console.WriteLine(\"Another message\"); } } You can omit the repeated Console statement, using the