JSON and XML to C# classes in Visual Studio

Although this feature is available for years in Visual Studio, I only recently discovered this gem that allows rapid generation of C# classes from either JSON or XML.

Here is how it works:

  1. Copy the JSON or XML code to the clipboard.
  2. In Visual Studio, go to Edit > Past Special and chose either Paste JSON as classes or Paste XML as classes.

Unit testing non-public types and members for .NET projects

Unit testing is usually used for testing public types and members. However, there are cases when you might need to test types or members that are not public. These could be internal classes or private helper methods, for instance. Whether that is proper unit testing or beyond its scope is not a discussion that I want to get into here. However, in this post, I will show how you can unit test non-public types and members from .NET assemblies.

When faced with the need for testing non-public types and members you can use several approaches:

  • change the accessibility to public; you can do that perhaps only for debug builds and keep the intended accessibility in release builds by using conditional compilation.
  • provide public members of a class that invoke private ones;
  • use reflection.

The first solutions involve changing the API only for the sake of the testing. The last solution avoids that but requires more work. To help with that, the Visual Studio unit testing framework provides some helper types that enable you to focus on the actual testing and be less concerned about the reflection details.

Troubles with Windows SDK

I recently installed a fresh copy of Visual Studio 2017 on a new machine and went on to build several projects some of them being VC++. The trouble was that I immediately run into a problem (actually the first problem was that MFC & ATL were missing because I forgot to check that in the list of Individual components so I had to install them separately). The problem was an error with a missing new.h header:

1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.15.26726\atlmfc\include\afx.h(62): fatal error C1083: Cannot open include file: 'new.h': No such file or directory

May good reads

Here is my list of good reads from May: Non-Ownership and Generic Programming and Regular types, oh my! Using C++17 std::optional Error Handling and std::optional std::accumulate vs. std::reduce How to Make SFINAE Pretty – Part 1: What SFINAE Brings to Code How to Make SFINAE Pretty – Part 2: the Hidden Beauty of SFINAE How…

Changing the color schemes of your development tools

The tools I use the most as a developer include the command prompt, notepad, Visual Studio, and Total Commander. The trouble is, I don’t really like the default colors they come with. However, some of them can be customized with different color schemes. Some very popular color schemes are Solarized and OneHalf, both having a light and a dark version. In this article, I will show how to enable Solarized for them.

Visual Studio 2017 Releases

Microsoft recently announced that it released version 15.5 of Visual Studio 2017 (and Visual Studio for Mac version 7.3). There are various improvements to performance and diagnostics (such as cutting the solution load times for large C# and VB projects by half), new features for C#, C++, F# development, and others. You can read the…

TDD with Live Unit Testing in Visual Studio 2017

Visual Studio 2017 Enterprise provides a feature called Live Unit Testing that enables developers to see live how changing C# and VB.NET code affects its corresponding unit tests. Among its features, it includes showing coverage information in the editor as you type, integration with the Test Explorer, including/excluding targeted test methods or projects for large…

C# Interactive Window in Visual Studio 2015 Update 1

The C# Interactive window has been made available again in Visual Studio with the first update to 2015, this time as a REPL window. You can type or paste and execute C# code, and it includes support for adding references to external DLLs and using namespaces. The window is intended for rapid prototyping C# code….