{%Pragmatic Coding%} Tips and tricks for software developers.


How to: Using TPL Dataflow for multithreaded file compression

In this small tutorial I will show you how to use TPL Dataflow  library with a quite trivial task - multithreaded file compression.


We need to implement efficient compression of files using GZipStream  class in the System.IO.Compression namespace. It is assumed that we will compress large files that can not fit entirely in memory. Read the full article...


C# ASP.NET friendly “slug” url creating

Hello friends!

I had to develop asp.net mvc controller which could accept a parameter as a slug string for friendly URL's which look like the following:

First what should be done is adding new MapRote with modified url template and parameters:

Great, we now have formatted our route for blog record url. Now we need to wtite extension method which will generate clear formatted URL. Read the full article...


Visual Studio: Import and Export Breakpoints

Visual Studio saves breakpoints in a XML file. To save the breakpoints, you just need to click on the “Export” button in breakpoint window as shown in the following figure. Read the full article...


How to: Using async and await in C # – Best Practices

Async and await keywords, introduced in C # 5.0, greatly simplify asynchronous programming. They also hide some difficulties, if you lose a focus. It can add some problems to your code. The following practices will serve you well if you create asynchronous code for. NET applications. Read the full article...


What’s new in reflection for .NET 4.5

.NET 4.5 has some changes to the System.Reflection. The most significant is that the Type is now separated into two classes: Type and TypeInfo. TypeInfo object keeps a complete definition, and the Type now keeps only general information. If you use the reflection from your desktop or web applications for NET 4.5, then the old API is still available too, along with new reflections. Today I will focus on how to use some of the main features of the new API.  Read the full article...


Dynamic Linq OrderBy Extension

Few days ago as usualy I working on my project and I made a function where I'm passing field name for sorting  table using Linq stuff. I was in need of an OrderBy extension method that could take a string field parameter in OrderBy and sort a IQueryable<> or IEnumerable<> collection. I was playing around implementation that could work, but I just wasn't satisfied with its internals (quite a bit of reflection to get the correct type to construct a LambdaExpression, etc) Read the full article...

Tagged as: .NET, C#, LINQ Continue reading

How To: Get property value from string using reflection in C#

Few days ago I had to implement selection of a list of items with filtering and fields I had to filter by has been passed as a string value.
Will give you sample function where I have implemented filtering.

As you can see I'm using GetPropValue function that uses Reflection to get object property value.
Here is GetPropValue function implementation:

I hope this post was helpful for you!
Post a coment if you have any questions!


Working with GPS in WinCE using C#

In this article I want to share with You, my dear reader, the implementation of the GPS data access in devices based on WindowsCE.When I had to create a product Shturman Navigator, it was necessary to develop an application that runs in WinSE 5.0, and in WinCE 6.0, which is able to receive data from the NMEA navigation receiver, and record them to log.

To work with GPS in a WinCE 5.0, and 6.0 is easier to use to work with COM port. So, first of all you need to find on your device, which COM-port provides GPS data. For determining that you can use DeviceManager.

Often manufacturers of a firmware already made sure that COM port of GPS was two. This allows you to separate software that requires a GPS and navigation, so that they were not fighting for access to the COM-port. Suppose that the COM port will be used in exclusive access.
To get NMEA data (http://ru.wikipedia.org/wiki/NMEA_0183), we need just to open the COM port, read data from it, and then close the COM port.
Read the full article...

Tagged as: .NET, C#, GPS, WinCE Continue reading

Cloning objects in C#

Few days ago I needed to clone object and than modify some data in it.

For example, get object from db and make clone this object with same data to be able to modify some specific properties. Something like

So, I decided to review abilities of cloning objects. Read the full article...

Tagged as: .NET, C# Continue reading

How To: Format Decimal.ToString() in C#

Today I have spent some time to find out how correctly convert and format decimal number to string representation with 2 decimal digits. And here is what I found and learned I want to share it with you my friend.
I'll give you several C# examples that shows how to format float numbers to string in C#. You can use static method String.Format or instance methods double.ToString and float.ToString.

Digits after decimal point

This example formats double to string with fixed number of decimal places. For two decimal places use pattern „0.00“. If a float number has less decimal places, the rest digits on the right will be zeroes. If it has more decimal places, the number will be rounded.

Read the full article...