c#-6.0

Dynamically load assemblies in ASP.NET 5

爱⌒轻易说出口 提交于 2019-12-03 08:54:05
I used to have some code which scanned the bin directory of my application for assemblies which weren't loaded in the AppDomain yet and loaded them. It basically looked like: foreach (var assemblyPath in Directory.GetFiles("path\to\bin", "*.dll")) { var inspected = Assembly.ReflectionOnlyLoadFrom(assemblyPath); Assembly.Load(inspected.GetName()); } I skipped the try/catch clauses, etc for brevity. This allowed me to drop assemblies in the bin folder at run-time with implementations for certain interfaces and let the IoC container pick them up automatically. Now with the new Roslyn magic, there

Interpolate string c# 6.0 and Stylecop

ぃ、小莉子 提交于 2019-12-03 05:43:08
I am using Stylecop version : 4.7.49.0 Has anyone used the latest interpolate string functionality in c# 6.0 example var totalUnits = GetUnitsGetTotalIssuedShares(myId); var testString = $"Test Units :{totalUnits}, have been shipped."; When I build i get the stylecop error SA0102 - because stylecop cant parse the file. It doesn't seem like there is a new version of stylecop that can handle 6.0 yet? error :SA0102: A syntax error has been discovered in file Is there anyway around this error? SA0102 is an internal stylecop error so can't be supressed or ignored via a settings file. You can

Why does string interpolation is not working with const strings

自闭症网瘾萝莉.ら 提交于 2019-12-03 05:29:28
Why does string interpolation in c# does not work with const strings? For example: private const string WEB_API_ROOT = "/private/WebApi/"; private const string WEB_API_PROJECT = $"{WEB_API_ROOT}project.json"; From my point of view, everything is known at compile time. Or is that a feature that will be added later? Compiler message: The expression being assigned to 'DynamicWebApiBuilder.WEB_API_PROJECT' must be constant. Thanks a lot! Interpolated strings are simply converted to calls to string.Format . So your above line actually reads private const string WEB_API_PROJECT = string.Format("{0

Null-conditional operator evaluates to bool not to bool? as expected

六眼飞鱼酱① 提交于 2019-12-03 01:22:14
I've just upgraded from VS 2010 to 2015. I like the new null-conditional operator which is also known as null-propagation. This enables to simplify your code, for example: string firstCustomerName = customers?[0].Name; // null if customers or the first customer is null another one: int? count = customers?[0]?.Orders?.Count(); // null if customers, the first customer, or Orders is null which returns a Nullable<int> even if Enumerable.Count returns an int to differentiate between a valid count and any nulls before. That's quite intuitive and very useful. But why does this compile and work as

RyuJit producing incorrect results

萝らか妹 提交于 2019-12-03 01:02:38
After recently upgrading to .net 4.6 we discovered a bug where RyuJit produces incorrect results, we were able to work around the issue for now by adding useLegacyJit enabled="true" to the app.config. How can I debug the machine code generated by the following? I created a new console project in VS 2015 RTM, set to Release, Any CPU, unchecked Prefer 32 bit, running with and without debugger attached produces the same result. using System; using System.Runtime.CompilerServices; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { Console.WriteLine(Calculate());

Null propagation operator and extension methods

萝らか妹 提交于 2019-12-02 21:48:54
I've been looking at Visual Studio 14 CTP along with C# 6.0 and playing with the null-propagation operator. However, I couldn't find why the following code does not compile. The features are not yet documented so I'm not sure whether this is a bug or extension methods simply are not supported with the ?. operator and the error message is misleading. class C { public object Get() { return null; } } class CC { } static class CCExtensions { public static object Get(this CC c) { return null; } } class Program { static void Main(string[] args) { C c = null; var cr = c?.Get(); //this compiles (Get

Enums in lambda expressions are compiled differently; consequence of overload resolution improvements?

我怕爱的太早我们不能终老 提交于 2019-12-02 17:13:58
While trying out the Visual Studio 2015 RC, I received a run-time error on previously working code. Given the lambda (x => x.CustomerStatusID == CustomerStatuses.Active) which was passed to a function as an Expression<> , the debugger shows a difference in the expression tree. Formerly it compiled as this: .Lambda #Lambda1<System.Func`2[Services.DataClasses.CustomerDC,System.Boolean]>(Services.DataClasses.CustomerDC $x) { (System.Int32)$x.CustomerStatusID == 0 } But in C# 6.0 it now compiles as .Lambda #Lambda1<System.Func`2[Services.DataClasses.CustomerDC,System.Boolean]>(Services.DataClasses

Using C# 6's using static syntax in MVC App_Code display helpers

爷,独闯天下 提交于 2019-12-02 12:37:01
问题 Is it possible to use C# 6.0's new "using static" notation inside of display helpers in App_Code in MVC 5? I attempted to do so but it did not seem to like the syntax. I created a static helper class to expose UrlHelper and HtmlHelper within App_Code. I was hoping to include it with the "using static" syntax in order to use the properties of the class as I would as if the file had a ViewPage base class. @using static Example.Core.ViewHelper @helper ExampleUsingUrl() { @Url.Action("Index",

Writing a nested join with LINQ to Entities

谁说我不能喝 提交于 2019-12-02 05:06:47
问题 I'm pretty sure there's an example of this somewhere on here, I just can't find it as I don't know the exact terms. So please, be kind. The problem should be a simple one: I have an Azure SQL database, somewhat badly designed (ie missing foreign keys and such). As I cannot redesign the database at this point, I have to handle relations manually via queries. As the database is also the bottleneck of our software, I must try and complete queries with as little database hits as possible. I have

Using C# 6's using static syntax in MVC App_Code display helpers

好久不见. 提交于 2019-12-02 04:48:33
Is it possible to use C# 6.0's new "using static" notation inside of display helpers in App_Code in MVC 5? I attempted to do so but it did not seem to like the syntax. I created a static helper class to expose UrlHelper and HtmlHelper within App_Code. I was hoping to include it with the "using static" syntax in order to use the properties of the class as I would as if the file had a ViewPage base class. @using static Example.Core.ViewHelper @helper ExampleUsingUrl() { @Url.Action("Index", "Home") } With a ViewHelper looking like this. namespace Example.Core { public static class ViewHelper {