Assert.That is a trick to overcome the lack of Extension Methods for static methods but it’s simple and elegant: MSTest v2: Create new asserts – Meziantou’s blog.
C#
Extension to Razor HtmlHelper
How to export a C# enum:
public enum AssetStatusEnum { Free, Reserved, Inactive, UnderMaintenance }
to
var assetStatusEnum = {"Free":0,"Reserved":1,"Inactive":2,"UnderMaintenance":3}
In implementing an extension method:
public static class HtmlEnumExtensions { public static MvcHtmlString EnumToString<T>(this HtmlHelper helper) { var values = Enum.GetValues(typeof(T)).Cast<int>(); var enumDictionary = values.ToDictionary(value => Enum.GetName(typeof(T), value)); return new MvcHtmlString(JsonConvert.SerializeObject(enumDictionary)); } }
and using it like this:
var assetStatusEnum = @(Html.EnumToString())
Converting C# enums to JavaScript | Gunnar Peipman – Programming Blog
Json.Net 10 removes Silverlight support
With this single line in change log:
Change – Removed .NET 4 portable class library target from NuGet package
Json.Net has also removed the Silverlight 5 support.
James Newton-King – Json.NET 10.0 Release 1 – Async, performance, documentation and more
A good summary of new Features in C# 7.0
Impacts of new() contraint in C#
“Disecting the new() constraint” is very instructive: new() constraint has a big performance impact and we must know its implementation to understand why ctor exceptions are wrapped to a TargetInvocationException.
By the way, in same blog post, I’ve discovered that some well known static functions can be custom replaceable. It means you can locally redefined them. System.Activator.CreateInstance<T> is replaced by a faster one.
Beware, this is a completly not documented behavior than can be theoretically remove any time. Just to mitigate previous remark, this undocumented behavior is so important survived the Roslyn transition.
Customizing git diff to understand C# method syntax
Not activated by default and a bit outdated: C# methods in git diff hunk headers » Thomas Levesque’s .NET blog.
Enhance properties with a reactive mind
Two ways to enhance properties with a reactive mind to allow composition:
The implementation of anonymous methods in C# and its consequences
When we use anomymous lambda in C#, we can have to choose between passing values as parameter or using lambda capture. Second one is elegant and easy: we “just” us enclosing variables.
It is good to remember that capturing has a cost which should be understood and taken into account. For this, we can refer to : The implementation of anonymous methods in C# and its consequences – The Old New Thing.
Knowing this, we can think that C++ 11 solution is better. We have to choose wich variables are captured and if capture is a copy or a modifiable reference in capture specification block ([]). And, by default, there is no capture. That way, overhead it is not a hazard but a deliberate choice. Perhaps for C# 7 but with breaking changes.
WebSockets managed and SignalR client in Cpp
A managed implementation of WebSocket and a SignalR client implemented in cpp. This comes from Asp.net vNext effort. Cool.
Microsoft/Win2D
An attempt to create a easy to use DirectX wrapper and it’s open source from the ground: Microsoft/Win2D · GitHub.
Documentation is available here.