Currently Browsing: .NET

Netvibes App for Windows Phone 8

This is just a quick post to announce a Windows Phone 8 app I’ve been working on, Netvibes Reader. It pulls in your RSS feeds aggregated on into native, WP8 app. You can download Netvibes Reader from the Windows Phone store. Phil
read more

OrderBy a string in Entity Framework

I’ve just started using Entity Framework, and I’ve found that it really helps speed up development time when dealing with queries where performance isn’t a huge issue. I added to an existing project which needed to keep the EF classes isolated in the data layer. This made it difficult to pass in a sort order without having a massive switch statement to deal with each of the options. I solved this by building an OrderBy extension method that takes a string, and builds the sort expression using reflection. This means you can sort without having to know the actual type of what...
read more

Detecting Encoding in C#

On a project that I’ve been working on recently, I was having some trouble combining SQL scripts that where in a couple of different formats. While there’s no easy way to detect all of the possible encodings, by checking the byte order mark (BOM) there is a pretty straight forward way to detect the following encodings: UTF-16 UTF-16BE UTF-32 UTF-32BE UTF-8 public static Encoding GetFileEncoding(string path) { if (path == null) throw new ArgumentNullException("path"); var encodings = Encoding.GetEncodings() .Select(e => e.GetEncoding()) .Select(e => new { Encoding =
read more

Async Entity Framework Queries

I’ve been writing a lot of Node.js recently, and I’ve really love how the asynchronous database access works, and thought to myself “I wonder if I can do that with Entity Framework?” While I couldn’t find anywhere in EF the inherently support any form of async calls, I did find that you can with the underlying SqlConnection (assuming you’re using MSSQL.) So with a little bit of Async CTP magic mixed in, I created an extension method to read the data asynchronously. Unfortunately I couldn’t find an obvious way to open the connection or write data...
read more

Alternating Row Styles in Silverlight

Update: There was an issue when using ItemsControl because of the way I was determining if one control was in another (I was using the DataContext.) This example code and attached ZIP have been updated. Because the ItemsControl in Silverlight 4 doesn’t support alternating styles on the child items, I’ve made this set of attached properties to allow you to switch the style on any item contained within an ItemsControl or anything that inherits from it (e.g. ListBox.) I’ve uploaded a sample project, but here’s the entirety of the code for those who don’t want to download...
read more

« Previous Entries