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

15Dec/120

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
12Dec/120

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!

30Nov/120

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
22Nov/121

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
15Sep/120

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...

25Jul/120

SharePoint 2010: Simple Backup/Restore via PowerShell

Hello dear readers!

In this article I will show you the main simple samples of backing up and restoring SharePoint SPFarm and SPSite in Windows PowerShell.

Backup-SPFarm
Creates a backup of an individual database, Web application, or the entire farm.

Required params:
Read the full article...

25May/121

Entity Framework: Insert, Update, Delete records

Every .NET developer sometime will start using ADO.NET Entity Framework.
And first question will be such as how to insert, update and delete records.
Performing basic Inser, Update and Delete operations via the Entity Framework is very straight forward.

Before you make any of thase operations you need to declare entyty

Read the full article...

13Mar/120

How To: Using System.IO.Path in C#

There is different effective ways of dealing with filenames and paths that the .NET Framework provides. It introduces the Path type in the System.IO namespace. There are complications when dealing with paths. They involve invalid paths and virtual and physical paths on servers. The Path type makes handling these easier.

This article uses the C# Path type. Path handles file locations in a consistent way. It resolves common problems.

Read the full article...

Filed under: .NET, C# Continue reading
4Feb/120

Validation Controls in SharePoint

Recently I had to compare 2 E-mail fields in the form with SharePoint field controls. And this article will describe the usage of SharePoint validation controls.

Introduction

The Microsoft.SharePoint.WebControls namespace of the Microsoft.SharePoint.dll contains a number of controls such as validation controls that can be used on any application pages to validate user entry in the SharePoint controls.
To use SharePoint control all your classes in project namespace require that a page directive like the following be included in the ASPX page containing the control:

You can obtain the PublicKeyToken value for the current Windows SharePoint Services deployment from the default.aspx file in the %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\SiteTemplates\STS folder, or from information provided for the Microsoft.SharePoint assembly atLocal_Drive:\%WINDOWS%\assembly in Windows Explorer.
Read the full article...

22Jan/121

NSLog – from beginning to advanced.

Hello friends!
First of all thanks to my friends were asking me about NSLog features, so, I decided to write about it.
So, let's get start with introduction where I will describe what is NSLog and basic usage of it.
Read the full article...