Visual studio feeds

All Visual Studio blogs in one place


Enter your email address:

Delivered by FeedBurner

Increase your website traffic with



Anti-spam: How many eyes has a typical person?

Follow us on FB


Dynamic code generation in C#

AddThis Social Bookmark Button
Let us assume that we have the following simple task: Given a Dictionary, convert that dictionary into a type in as performant a manner as possible. The conversion will happen many time, and first time costs are acceptable. The answer we came up with is to dynamically generate the code based on the type. Basically, here is how it looks like: public static Func, T> Generate() where T : new() { var dic = Expression.Parameter(typeof (Dictionary), "dic"); var tmpVal = Expression.Parameter(typeof (string), "tmp"); var args
= new List(); foreach (var propertyInfo in typeof(T).GetProperties()) { var tryGet = Expression.Call(dic, "TryGetValue", new Type[0], Expression.Constant(propertyInfo.Name), tmpVal); Expression value = tmpVal; if (propertyInfo.PropertyType != typeof (string)) { var convertCall = Expression.Call(typeof(Convert).GetMethod("ChangeType",...(Read whole news on source site)

The Morning Brew #2026

AddThis Social Bookmark Button
Information The Error Model – Joe Duffy Feature Toggles (Working with feature-toggled systems) – Pete Hodgson FormatFilter and MediaTypeMappings in ASP.NET Core 1.0 MVC – Filip W JavaScript Unit Test Code Coverage Using NodeJS – Dave M Bush Testing That Your Public APIs Have Not Changed Unexpectedly with PublicApiGenerator and Approval Tests – Jason Roberts […]

Data Mocking - A way to test the untestable

AddThis Social Bookmark Button
Some of the biggest challenges when testing software can be getting the software into some very specific states. You want to test that the new error message works, but this message is only shown when something on the back-end breaks and the back-end has never broken before because it always “just works”. Maybe the software you have to test is powered by other people’s data, data that you have no direct control over and you really need to manipulate this data in order to perform your tests. Imagine you are testing a piece of software which displays the names of local
businesses as values as a drop-down list. This software might look something like this… There are only three items on this list at the moment, but this may not always be the case. There is currently no option within the software itself to change or manipulate the text displayed on the list because the software retrieves this list of data from someone else’s API. We have no control over the data returned by the API, our software under test just displays it. You have been asked to test the drop-down box. What would you do? Well most testers would start by looking at it. It...(Read whole news on source site)

How to get the Process Description of an external process using C#?

AddThis Social Bookmark Button
Sometime we need to find out details of running process which is external to your current process, might be a third party one. If you are currently looking for some code to find out details of a process, this post will definitely help you. Here we will learn, how to get the process description using C#.   Continue reading to learn about it. Also, sample code has been shared for you to understand it better. If you have specific query, drop a line in the comment section.     If
you open the Task Manager in your Windows system and navigate to the details tab, as shown below, you will find out the various process names running in your system. This includes the name of the process, the process ID (aka. PID), status of the process and the description.   If you are a developer and looking for an way to retrieve using C#, the “Process” instance doesn’t return this information. To do this, we need to iterate thru the Win32_Process using the ManagementObjectSearcher.       Normal SQL like query “Select...(Read whole news on source site)

Heroic.AutoMapper Updated

AddThis Social Bookmark Button
I just shipped a new version of Heroic.AutoMapper.  Unfortunately, AutoMapper 4.2.0 introduces some breaking changes between 4.1.0 (semvar, anyone?), and Heroic.AutoMapper was impacted.  That means anything that uses Heroic.AutoMapper is also impacted. Fortunately, the change is mechanical, and a NuGet package update followed by some find-and-replace should have you back up and running. First, update to Heroic.AutoMapper 2.0.0.  Next, do a find-and-replace, replacing “CreateMappings(IConfiguration” with “CreateMappings(IMapperConfiguration”.   Any type that implements IHaveCustomMappings should have changed from this:public void CreateMappings(IConfiguration configuration) { configuration.CreateMap() .ForMember(x => x.Name, opt
=> opt.MapFrom(x => x.FullName)); } To this:public void CreateMappings(IMapperConfiguration configuration) { configuration.CreateMap() .ForMember(x => x.Name, opt => opt.MapFrom(x => x.FullName)); } Going forward, AutoMapper 5.0 is going to be a big change.  I’m still not sure how I feel about it.  On the one hand, I totally agree that having a non-static version of Mapper could be useful, and it will probably clean up a lot of things internally.  But, in every application I’ve ever created, I’ve only ever needed a single Mapper.  I can’t think of a single time I’ve needed a...(Read whole news on source site)