background preloader

.NET

Facebook Twitter

Async for .NET Framework 4, Silverlight 4 and 5, and Windows Phone 7.5 and 8 1.0.16. This package enables Visual Studio 2012 projects to use the new 'async' and 'await' keywords. This package also includes Task-based extension methods that allow using some of the existing asynchronous APIs with the new language keywords. Windows Phone Silverlight 8 projects can use this package to get access to async extension methods for the networking types.

This package is not supported in Visual Studio 2010, and is only required for projects targeting .NET Framework 4.5, Windows 8, Windows Phone Silverlight 8, or Windows Phone 8.1 when consuming a library that uses this package. For known issues, please see: For more information on the async programming model, visit MSDN: Supported Platforms: - .NET Framework 4 (with KB2468871) - Windows 8 - Windows Phone 8.1 - Windows Phone Silverlight 7.5 - Silverlight 4 - Portable Class Libraries Requires NuGet 2.8.1 or higher. Owners. Beginner's Guide to Reactive Extensions for .NET. This page contains resources to help developers get up to speed with the Reactive Extensions. For additional resources see the Learning Resources page. Introductory Videos These videos give you an introduction to the basic use of the Reactive Extensions. More Videos ... Rx Workshop The following is a series of workshop videos introducing you to the key concepts in Rx.

Tutorials & Articles Curing the asynchronous blues with the Reactive Extensions for .NETThis Hands-on Lab familiarizes the reader with the Reactive Extensions for .NET (Rx). Curing the asynchronous blues with the Reactive Extensions for JavaScriptThis Hands-on Lab familiarizes the reader with the Reactive Extensions for JavaScript (RxJS). Enumeration classes. A question came up on the ALT.NET message board asking whether Value Objects should be used across service boundaries. Of course, the conversation took several detours, eventually coming to the question, “what do you do about enumerations crossing service boundaries.” I’m still ignoring that question, but I’ve found different ways to represent enums in my model.

Now, enums are just fine in lots of scenarios, but quite poor in others. There are other options I like to use when enumerations break down, and many times in the domain model, I go straight to the other option. For example, I’ve seen quite a few models like this: public class Employee { public EmployeeType Type { get; set; } } public enum EmployeeType { Manager, Servant, AssistantToTheRegionalManager } The problem with a model like this is it tends to create lots of switch statements: There are a few problems with enumerations like this: Instead of an enumeration, I like to use an enumeration class. Creating the enumeration class. SqlBulkCopy for Generic List<T> (useful for Entity Framework & NHibernate) A common complaint of the Entity Framework is slow insert times for larger datasets. Last night I was trying to insert a catalog of 15k products and it was taking a very long time (I gave up after 5 minutes). I recalled this post a while back from Mikael Eliasson demonstrating SqlBulkCopy using .NET.

I had used BCP in SQL server, but not from .NET. I took Mikael’s example and roughed out a reusable generic version below, which produced 15k inserts in 2.4s or +- 6200 rows per second. I upped it to 4 catalogs, 224392 rows in 39s, for +- 5750 rps (changing between 4 files). These are pretty decent records too, 41 columns and a few of the fields have a meaty char count. Good enough I say. This works off just a basic list of items which property names match the table column names.

To use I just build up a list of objects, pick the connection string off the DbContext and then call BulkInsert to save to the DB. Jarod Ferguson. VerifyArgs. Introducing the Expected Objects Library | Aspiring Craftsman. Introduced in the Effective Test Series, the Expected Object pattern is a technique involving the encapsulation of test-specific logic within a specialized type designed to compare its configured state against that of another object.

Use of the Expected Object pattern eliminates the need to encumber system objects with test-specific equality behavior, helps to reduce test code duplication and can aid in expressing the logical intent of automated tests. While the Expected Object pattern is a great strategy for helping adhere to good testing practices, the process of actually implementing the required types can be less than motivating. To alleviate the burden of hand-rolling Expected Object types, I created the Expected Objects library. This library provides the ability to compare the state of one object against another without relying upon the provided type’s equality members. The following examples demonstrate the capabilities of the library: Comparing Flat Objects Results: Extensibility. Normal Stuff - DebuggerDisplay attribute best practices - jaredpar's WebLog. The DebuggerDisplayAttribute is a powerful way to customize the way values are displayed at debug time.

Instead of getting a simple type name display, interesting fields, properties or even custom strings can be surfaced to the user in useful combinations [DebuggerDisplay("Student: {FirstName} {LastName}")] public sealed class Student { public string FirstName { get; set; } public string LastName { get; set; } } The DebuggerDisplay attribute can customize the name, value and type columns in the debugger window. Each one can be customized using a string which can contain constant text or expressions to be be evaluated by the expression evaluator. The latter is designated by putting the expression inside {}’s (this greatly resembles String.Format) This feature while very powerful and useful can also easily contribute negatively to the debugging experience when used improperly (mostly in the area of performance).

Don’t use multiple functions or properties in the display string. Retryable actions in C# Download the Code 2012-10-18 18:00 Edit: I was just informed via Twitter that the source code for this article is no longer available. I had the source on my SkyDrive. I will attempt to find it in the next couple of days. I will post an update with a new link to the source code. I will most likely post the code to GitHub. 2012-10-18 22:30 Edit: I have uploaded a variation of my retry source code to GitHub. In inevitably there will be times during the execution of your application where you will encounter an exception. Your database access code may start of with something like the following, 1: try 3: ReadDatabase(); 5: catch (SqlException) 7: // return error to user? Your first thought may be to catch the known exception type and try the action again, such as, 7: try 9: ReadDatabase(); 11: catch (SqlException) 13: // failed again, return error to user?

If there is only one place in your code you have to do this, then this approach may be acceptable. Introducing Retryable The first is side effects. How Duck Typing Benefits C# Developers. David Meyer recently published a .NET class library that enables duck typing (also sometimes incorrectly described as Latent Typing as Ian Griffiths explains in his campaign to disabuse that notion) for .NET languages. The term duck typing is popularly explained by the phrase If it walks like a duck and quacks like a duck, it must be a duck. For most dynamic languages, this phrase is slightly inaccurate in describing duck typing. To understand why, let’s take a quick look at what duck typing is about.

Duck Typing Explained Duck typing allows an object to be passed in to a method that expects a certain type even if it doesn’t inherit from that type. I emphasize that last phrase for a reason. In many (if not most) dynamic languages, my object does not have to support all methods and properties of duck to be passed into a method that expects a duck. The Static Typed Backlash Give me static types or give me death! Well, actually I do understand...kinda. C# has used duck typing for a long time. Json.NET. C# 4.0/3.0 in a Nutshell - PredicateBuilder. Dynamically Composing Expression Predicates Suppose you want to write a LINQ to SQL or Entity Framework query that implements a keyword-style search.

In other words, a query that returns rows whose description contains some or all of a given set of keywords. We can proceed as follows: IQueryable<Product> SearchProducts (params string[] keywords) { IQueryable<Product> query = dataContext.Products; foreach (string keyword in keywords) { string temp = keyword; query = query.Where (p => p.Description.Contains (temp)); } return query; } The temporary variable in the loop is required to avoid the outer variable trap, where the same variable is captured for each iteration of the foreach loop.

So far, so good. Of all the things that will drive you to manually constructing expression trees, the need for dynamic predicates is the most common in a typical business application. Using PredicateBuilder Here's how to solve the preceding example with PredicateBuilder: PredicateBuilder Source Code How it Works. Screenshots. JustDecompile - Free .NET Decompiling Tool.

Testing

NuGet Package of the Week #6 - Dynamic, Malleable, Enjoyable Expando Objects with Clay. C# in Depth: The Beauty of Closures. Note: this article has been translated into Serbo-Croatian by Anja Skrba from webhostinggeeks.com. Some time soon, I want to write about the various Java 7 closures proposals on my blog. However, when I started writing that post I found it was difficult to start off without an introduction to closures. As time went by, the introduction became so long that I feared I'd lose most of my readers before I got to the Java 7 bit. As chapter 5 in the book is largely about anonymous methods and how they provide closures to C#, it seemed appropriate to write this article here. Most articles about closures are written in terms of functional languages, as they tend to support them best. However, that's also precisely why it's useful to have an article written about how they appear more traditional OO languages. Chances are if you're writing in a functional language, you know about them already.

What are closures? Example situation: filtering a list public delegate bool Predicate<T>(T obj) Conclusion.

Asynchronous Programming

ORM Related. Documentation. The Repository Pattern with Linq to Fluent NHibernate and MySQL | Random Sparks. I have heard a lot of good things about NHibernate, but have never had the opportunity to use it. In this post I will describe how to get started using Fluent NHibernate with Linq to NHibernate using MySQL for a database.

Code The Back Story To add a bit of concreteness to the design / code, let’s imagine that we need to build out the back-end for a delivery truck management system. Each truck can have only one driver (one-to-one relationship), but each truck will have many locations (one-to-many relationship). Installing MySQL MySQL is a popular open source relational database management system (RDBMS). I will be developing for a Windows-based server. MySQL Community Server – This is the database manager system. The site also provides a thorough guide to installing MySQL on Windows. Create the Tables and Columns Once the MySQL components are installed, start the MySQL Workbench to begin creating the database table.

To add a table double-click the ‘Add Table’ button. The Repository Pattern.

MVC

Algorithm - C# rounding DateTime objects. Studio Styles: Son of Obsidian. Secret Project. Well I said I would reveal the secret project I've been working on. 99% of people won't be interested, but if you're a .NET developer you probably will be very interested. Especially if you do a lot of UI work. I actually came up with this idea 6 years ago and wrote a fairly successful codeproject article on it, but then I abandoned it. I've since started a new job, and wished I had this tool, so built it. Enter Event Spy - Event spy is a development/debugging tool that subscribes to all events a .NET object can raise, it then records when events are raised on the object, and allows you to explore the value of any event arguments.

Event spy works on any event of any object, no matter what the event handler type is. Usage is pretty simple, just add Event Spy as a reference, then call: var spy = new EventSpy(); spy.Register(o); where o is any object. A build and the source (VS 2010 project) are below, please give it a whirl and give any feedback. Prism 4.0 For Visual Studio 2010, .NET Framework 4.0, WPF & Silverlight 4 « Karl On WPF – .Net.

The Microsoft patterns & practices team is excited to announce the release of: Prism 4 For Visual Studio 2010, .NET Framework 4.0, WPF & Silverlight 4 Prism provides guidance designed to help you more easily design and build rich, flexible, and easy to maintain Windows Presentation Foundation (WPF) desktop applications, Silverlight Rich Internet Applications (RIAs) and Windows Phone 7 applications. Using design patterns that embody important architectural design principles, such as separation of concerns and loose coupling, Prism helps you to design and build applications using loosely coupled components that can evolve independently but which can be easily and seamlessly integrated into the overall application.

Links Audience Prism is intended for software developers building WPF or Silverlight applications that typically feature multiple screens, rich user interaction and data visualization, and that embody significant presentation and business logic. Key Benefits In this Release. Weak Events in C# Download source code - 16.42 KB Table of contents Introduction When using normal C# events, registering an event handler creates a strong reference from the event source to the listening object. If the source object has a longer lifetime than the listener, and the listener doesn't need the events anymore when there are no other references to it, using normal .NET events causes a memory leak: the source object holds listener objects in memory that should be garbage collected. There are lots of different approaches to this problem. This article will explain some of them and discuss their advantages and disadvantages.

I have sorted the approaches in two categories: first, we will assume that the event source is an existing class with a normal C# event; after that, we will allow modifying the event source to allow different approaches. What Exactly are Events? Many programmers think events are a list of delegates - that's simply wrong. EventHandler eh = Method1; eh += Method2; This expands to:

WPF - Silverlight