Daniel Crabtree https://www.danielcrabtree.com/blog Daniel Crabtree Copyright (c) Daniel Crabtree 2003 - 2017 C# 7: Ref Returns, Ref Locals, and how to use them https://www.danielcrabtree.com/blog/128/c-sharp-7-ref-returns-ref-locals-and-how-to-use-them Fri, 24 Mar 2017 15:53:00 GMT <p>C# has always supported the ability to pass by reference using the <code>ref</code> keyword on method parameters. C# 7 adds the ability to return by reference and to store references in local variables.</p> <p>The primary reason for using ref returns and ref locals is performance. If you have big structs, you can now reference these directly in safe code to avoid copying. Before C# 7 you had &hellip;</p> https://www.danielcrabtree.com/blog/128/c-sharp-7-ref-returns-ref-locals-and-how-to-use-them C# 7: Dynamic types and Reflection cannot access Tuple fields by name https://www.danielcrabtree.com/blog/99/c-sharp-7-dynamic-types-and-reflection-cannot-access-tuple-fields-by-name Sun, 19 Mar 2017 09:49:00 GMT <p><a href="https://www.danielcrabtree.com/blog/17/c-sharp-7-preview-using-tuples-to-return-multiple-values">Tuples</a> are a great new feature in C# 7 and I've used them a few times already. The syntax is great, they're easy to use, and they're a whole lot better than the alternatives.</p> <p>Tuples are implemented using <code>ValueTuple</code>, with <a href="https://github.com/dotnet/roslyn/blob/master/docs/features/tuples.md#name-erasure-at-runtime-">name erasure at runtime</a> &hellip;</p> https://www.danielcrabtree.com/blog/99/c-sharp-7-dynamic-types-and-reflection-cannot-access-tuple-fields-by-name C# 7: Local Functions are Funcs too https://www.danielcrabtree.com/blog/84/c-sharp-7-local-functions-are-funcs-too Wed, 15 Mar 2017 09:00:00 GMT <p>Local functions in C# 7 are versatile: they can be passed as <code>Func&lt;&gt;</code> and <code>Action&lt;&gt;</code> to other methods and they can be defined using the inline expression bodied syntax.</p> <p>Because local functions are compiled into static methods, you should be able to pass them to any method that requires a <code>Func&lt;&gt;</code> or <code>Action&lt;&gt;</code> and sure &hellip;</p> https://www.danielcrabtree.com/blog/84/c-sharp-7-local-functions-are-funcs-too C# 7: Dissecting Local Functions to understand how they capture local variables https://www.danielcrabtree.com/blog/73/c-sharp-7-dissecting-local-functions-to-understand-how-they-capture-local-variables Tue, 14 Mar 2017 03:14:00 GMT <p>One of the new language features in C# 7 is local functions. This feature lets you define functions within the scope of other functions. The main benefit of local functions is encapsulation and a secondary benefit is that they bring local variables into scope.</p> <p>Although local functions appear simple, their interaction with other language features quickly leads to questions. I wondered &hellip;</p> https://www.danielcrabtree.com/blog/73/c-sharp-7-dissecting-local-functions-to-understand-how-they-capture-local-variables How to set a custom Code Analysis Rule Set on an ASP.NET Core project https://www.danielcrabtree.com/blog/64/how-to-set-a-custom-code-analysis-rule-set-on-an-asp-net-core-project Sun, 12 Mar 2017 10:43:00 GMT <p>If you want to set a custom code analysis rule set on an ASP.NET Core project, there is currently no UI tooling in Visual Studio 2017 to support this scenario. However, you can add it manually to the <code>csproj</code> file.</p> <p>To set a custom code analysis rule set on an ASP.NET Core project, right click on the project in solution explorer, select <code>Edit &lt;YourProjectName&gt;.csproj</code> &hellip;</p> https://www.danielcrabtree.com/blog/64/how-to-set-a-custom-code-analysis-rule-set-on-an-asp-net-core-project Favorite features in Visual Studio 2017 https://www.danielcrabtree.com/blog/53/favorite-features-in-visual-studio-2017 Sat, 11 Mar 2017 02:05:00 GMT <p>Visual Studio 2017 is now available, <a href="https://www.visualstudio.com/downloads/">download it here</a>. I've been converting my projects over to VS2017 and wanted to share my favorite features of the new IDE.</p> <p>My favorites are Go To All, move type to matching file, string splitting, and coding conventions via EditorConfig. Other notable mentions are the overhauled Find All &hellip;</p> https://www.danielcrabtree.com/blog/53/favorite-features-in-visual-studio-2017 Gotchas with upgrading to Visual Studio 2017 https://www.danielcrabtree.com/blog/42/gotchas-with-upgrading-to-visual-studio-2017 Fri, 10 Mar 2017 07:12:00 GMT <p>While upgrading several projects to Visual Studio 2017 I was caught out by three gotchas: I was unable to push changes to remote Git repositories, I had ASP.NET Core applications failing under both Kestrel and IIS Express, and I had ASP.NET Core projects that stopped working under Visual Studio 2015.</p> <p>This post documents these three issues and provides the solutions I used to work &hellip;</p> https://www.danielcrabtree.com/blog/42/gotchas-with-upgrading-to-visual-studio-2017 Gotchas with HttpClient's CancelPendingRequests and Timeout in .NET https://www.danielcrabtree.com/blog/33/gotchas-with-httpclients-cancelpendingrequests-and-timeout-in-net Tue, 20 Dec 2016 17:08:00 GMT <p><code>HttpClient</code> provides a convenient way to make web requests in .NET. But if you want to cancel all pending requests using <code>CancelPendingRequests</code> or use the <code>Timeout</code> functionality, you must be aware of the gotchas.</p> <p>I recently encountered some strange behaviour where some requests were not cancelled when <code>CancelPendingRequests</code> was called and &hellip;</p> https://www.danielcrabtree.com/blog/33/gotchas-with-httpclients-cancelpendingrequests-and-timeout-in-net Gotchas with dynamically adding script tags to HTML https://www.danielcrabtree.com/blog/25/gotchas-with-dynamically-adding-script-tags-to-html Sat, 10 Dec 2016 12:19:00 GMT <p>Sometimes you need to dynamically add a script tag to HTML. But there are some gotchas that might get you if you don't know to look out for them.</p> <p>You might ask, why add scripts dynamically at all? Well, here's two reasons:</p> <ol> <li>When you don't know what to load until runtime.</li> <li>When you want to load scripts without blocking the page load.</li> </ol> <p>I recently &hellip;</p> https://www.danielcrabtree.com/blog/25/gotchas-with-dynamically-adding-script-tags-to-html C# 7 Preview: Using tuples to return multiple values https://www.danielcrabtree.com/blog/17/c-sharp-7-preview-using-tuples-to-return-multiple-values Fri, 04 Nov 2016 19:37:00 GMT <p>Microsoft is hard at work on C# 7, the next version of C#. In this post, I'll look at tuples, one of the new features proposed for C# 7. So what are tuples, why do we need them, and how do they differ from what we have already.</p> <p>Tuples are a way to temporarily group multiple values together. Currently, C# handles inputs and outputs asymmetrically. There is syntactic support for passing &hellip;</p> https://www.danielcrabtree.com/blog/17/c-sharp-7-preview-using-tuples-to-return-multiple-values