c#-7.0

Should I await ValueTask<T>?

那年仲夏 提交于 2019-12-07 16:32:53
问题 Which would be a valid implementation of ValueTask please? Cache service returns data either from cache or DB. public async ValueTask<IList<HrEmploymentDataCustom>> GetEmployeesFacts() { try { var facts = (List<HrEmploymentDataCustom>) _memoryCache.Get("facts"); return facts ?? await _accountService.GetEmploymentFacts(DetailsRequestType.All, null); } catch (Exception e) { var tc = new TelemetryClient(); tc.TrackException(e); return null; } } Would this be: var employeesFacts = await

MSBuild 15: The “Error” task could not be instantiated

不问归期 提交于 2019-12-07 08:19:26
问题 I'm attempting to programmatically build a project which uses C#7, and therefore MSBuild 15, but this task is failing seemingly because of mismatched assembly references. Here is my code: string projectFilePath = Path.Combine(args.Any() ? args.First() :@"C:\Users\newsoni\Documents\Visual Studio 2017\Projects\ConsoleApp2\ConsoleApp2.sln"); ProjectCollection pc = new ProjectCollection(); Dictionary<string, string> globalProperty = new Dictionary<string, string>(); globalProperty.Add(

How to create named reference-type tuples?

…衆ロ難τιáo~ 提交于 2019-12-07 06:14:16
问题 The following line creates a named ValueTuple : var tuple = (a:1, b:2, c:3, d:4, e:5, f:6); Value types can not be passed around efficiently. Does C#7 offer a way to create named tuples of the Tuple type? 回答1: If you mean if there's a way to attach other names to the properties of System.Tuple<...> instances, no there isn't. Depending on why you want it, you might get around it by converting System.Tuple<...> instances to System.ValueTuple<...> instances using the ToValueTuple overloads in

Which C# version .NET Core uses?

北战南征 提交于 2019-12-06 16:54:19
问题 I know that C# version depends on .NET Framework. But .NET Core which version uses? Particularly .NET Core 2? C#7? 回答1: .NET Core 2.0 references Roslyn 2.3, which corresponds to Visual Studio 2017 version 15.3 and supports C# 7.1. 回答2: The C# what's new version history page gives a list of all versions plus their associated Visual Studio and .NET core version: C# 7.3 Visual Studio 2017 version 15.7, and in the .NET Core 2.1 SDK 2.1.300 RC1 C# 7.2 Visual Studio 2017 version 15.5, and in the

Convert anonymous type to new C# 7 tuple type

我只是一个虾纸丫 提交于 2019-12-06 16:36:36
问题 The new version of C# is there, with the useful new feature Tuple Types: public IQueryable<T> Query<T>(); public (int id, string name) GetSomeInfo() { var obj = Query<SomeType>() .Select(o => new { id = o.Id, name = o.Name, }) .First(); return (id: obj.id, name: obj.name); } Is there a way to convert my anonymous type object obj to the tuple that I want to return without mapping property by property (assuming that the names of the properties match)? The context is in a ORM, my SomeType object

How to use C# 7 within Web Application ASPX code-before pages?

∥☆過路亽.° 提交于 2019-12-06 04:45:31
问题 (This is kind of a follow-up to my question "How to use C# 6 with Web Site project type?") I'm trying to use C# 7 features with Visual Studio 2017. For this, I've updated the Microsoft.Net.Compilers NuGet package to v2.0.0-rc4 in my existing ASP.NET WebForms 4.6.2 application. It seems to work well from inside Visual Studio 2017. When deployed to my website, all I see is a yellow screen of death: Compiler error with error code 255. [Detailed compiler output] Version information: Microsoft

Should I await ValueTask<T>?

半城伤御伤魂 提交于 2019-12-06 03:40:58
Which would be a valid implementation of ValueTask please? Cache service returns data either from cache or DB. public async ValueTask<IList<HrEmploymentDataCustom>> GetEmployeesFacts() { try { var facts = (List<HrEmploymentDataCustom>) _memoryCache.Get("facts"); return facts ?? await _accountService.GetEmploymentFacts(DetailsRequestType.All, null); } catch (Exception e) { var tc = new TelemetryClient(); tc.TrackException(e); return null; } } Would this be: var employeesFacts = await _cacheService.GetEmployeesFacts(); or var employeesFacts = _cacheService.GetEmployeesFacts().Result; Little bit

MSBuild 15: The “Error” task could not be instantiated

早过忘川 提交于 2019-12-05 14:57:08
I'm attempting to programmatically build a project which uses C#7, and therefore MSBuild 15, but this task is failing seemingly because of mismatched assembly references. Here is my code: string projectFilePath = Path.Combine(args.Any() ? args.First() :@"C:\Users\newsoni\Documents\Visual Studio 2017\Projects\ConsoleApp2\ConsoleApp2.sln"); ProjectCollection pc = new ProjectCollection(); Dictionary<string, string> globalProperty = new Dictionary<string, string>(); globalProperty.Add("Configuration", "Debug"); globalProperty.Add("Platform", "x86"); BuildParameters bp = new BuildParameters(pc); bp

How to create named reference-type tuples?

ε祈祈猫儿з 提交于 2019-12-05 08:33:59
The following line creates a named ValueTuple : var tuple = (a:1, b:2, c:3, d:4, e:5, f:6); Value types can not be passed around efficiently. Does C#7 offer a way to create named tuples of the Tuple type? If you mean if there's a way to attach other names to the properties of System.Tuple<...> instances, no there isn't. Depending on why you want it, you might get around it by converting System.Tuple<...> instances to System.ValueTuple<...> instances using the ToValueTuple overloads in TupleExtensions and back using the ToTuple overloads. If you don't really need the tuples, you can deconstruct

Any reason tu use out parameters with the C# 7 tuple return values? [closed]

℡╲_俬逩灬. 提交于 2019-12-04 23:14:46
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 2 years ago . I have just watched a video presenting the new features of C# 7. Among others, it introduces the possibility to return a tuple type (e.g.: (int, int) , which, I believe, is just a syntactic sugar for Tuple<int, int> ). Thus, if we have a method returning multiple values,