Finalizers in C#

,
October 14, 2016 / No Comment

The following is an Expert from Chapter 9 of Essential C#.
Finalizers allow developers to write code that will clean up a class’s resources. Unlike constructors that are called explicitly using the new operator, finalizers cannot be called explicitly from within the code. There is no new equivalent such as a delete operator. Rather, the garbage collector is responsible for […]
Read more

AUTHOR: CATEGORY: .Net, Blog, C#

Creating a Fody Add-in

,
September 22, 2016 / 1 Comment

Fody is a fantastic framework for creating IL weavers. For those who are unfamiliar with IL weaving, it is the art (and at times a seemingly magical incantation) of modifying an assembly post-compile. In this article we will walk through creating a library that can modify an existing .NET assembly.
Let’s start by looking at what actually happens when you […]
Read more

AUTHOR: CATEGORY: .Net, C#, Visual Studio

Displaying the Build Date on your Web Pages

,
August 26, 2016 / No Comment

The Build Date Problem
I have struggled to find a good way to communicate with users the version of a web site. Version numbers are tricky and only meaningful to people close to the project. I like dates but they are often tricky to implement.
My default choice has always been dates because they are easy for customers to understand. […]
Read more

Making unit testing easier

,
August 4, 2016 / No Comment

I love unit tests. Specifically, I love unit tests that are easy to maintain. When I spend more time setting up a test then doing actual testing, it is a very strong code smell. Sloppy unmaintainable code has no place in your projects, especially not in your unit test project.
 
In this post I would like to present two […]
Read more

AUTHOR: CATEGORY: .Net, Blog, C#

Locking a Block of Code With an Integer

,
June 27, 2016 / No Comment

I was talking with a developer recently who was convinced that you could use a static integer variable to lock a block of code merely by casting it to an object, like this

First it must be noted that an integer cannot be used by itself in a lock statement because it is a value type. But when you […]
Read more

AUTHOR: CATEGORY: .Net, Blog, C#

JSON serializer that doesn’t serialize other properties if Deleted is true

,
May 13, 2016 / No Comment

I was recently working on a project using Azure Mobile Services (AMS) as the backend for our Android and iOS mobile apps. Using the built-in offline sync feature of AMS, you can delete records on the backend and when the mobile app synchronizes its data, the record will be deleted from the mobile device. While taking a look at some […]
Read more

AUTHOR: CATEGORY: .Net, Azure, Blog, C#, Cloud

Xamarin Forms EnumBindablePicker

,
April 5, 2016 / 2 Comments

One of the controls missing from Xamarin Forms is a “BindablePicker” that allows you to dynamically bind an ItemsSource and SelectedItem from your view model. Fortunately, the Xamarin forums provide a solution to this problem found here:
https://forums.xamarin.com/discussion/30801/xamarin-forms-bindable-picker
The original implementation of this BindablePicker worked great as long as you had a list of strings as your ItemSource. But what […]
Read more

Implementing a Custom ILogger with Exception Handling for .NET Core

,
March 4, 2016 / 2 Comments

This article corresponds with the MSDN article: Essential .NET – Logging with .NET Core. This github repo contains the code referenced in the article. Not in particular the unit test LogCritical_Exception_Success for an example of handling an exception using the custom logger.

The Custom Logger implementation is straightforward:

Here is the the extension method for adding a custom […]
Read more

AUTHOR: CATEGORY: .Net, .NET Core, C#

Self-Hosted Integration Testing Of OData and WebApi

,
January 15, 2016 / No Comment

Full-stack testing of OData 4.0 and Web API 2.2 ASP.Net MVC controllers
Why Are Unit Tests of OData Web API Controllers Insufficient?
A common pattern for testing ASP.Net Web API 2 controller methods is to call them directly after mocking or setting up the Request and Configuration properties. When OData v4 is then added to this mix, more setup or […]
Read more

AUTHOR: CATEGORY: .Net, ASP.Net, Blog, C#

Essential .NET – C# Scripting (MSDN)

,
January 6, 2016 / No Comment

With the arrival of Visual Studio 2015 Update 1, henceforth Update 1, comes a new C# read-evaluate-print-loop (REPL), available as a new interactive window within Visual Studio 2015 or as a new command-line interface (CLI) called CSI. In addition to bringing the C# language to the command line, Update 1 also introduces a new C# scripting language, traditionally saved into […]
Read more

AUTHOR: CATEGORY: .Net, Blog, C#, Headlines