background preloader

C#

Facebook Twitter

Threading

Microsoft Type Design Guildelines. From the CLR perspective, there are only two categories of types—reference types and value types—but for the purpose of a discussion about framework design, we divide types into more logical groups, each with its own specific design rules.

Microsoft Type Design Guildelines

Classes are the general case of reference types. They make up the bulk of types in the majority of frameworks. Classes owe their popularity to the rich set of object-oriented features they support and to their general applicability. Base classes and abstract classes are special logical groups related to extensibility. Interfaces are types that can be implemented by both reference types and value types.

Structs are the general case of value types and should be reserved for small, simple types, similar to language primitives. Enums are a special case of value types used to define short sets of values, such as days of the week, console colors, and so on.

LINQ

Tree<T>: Implementing a Non-Binary Tree in C# « Critical Development. Download the Source [This is the first article in a series of intelligent data structures, which is continued here with KeyedList.]

Tree<T>: Implementing a Non-Binary Tree in C# « Critical Development

I’ve always thought it was odd that the .NET Framework never shipped with a Tree or Tree<T> class in its collection namespaces. Most of the other classic data structures are there: List, Dictionary, Stack, Queue, and so on. Asynchronous Programming - Easier Asynchronous Programming with the New Visual Studio Async CTP. Imagine what the world would be like if people worked the same way as computer programs: void ServeBreakfast(Customer diner){ var order = ObtainOrder(diner); var ingredients = ObtainIngredients(order); var recipe = ObtainRecipe(order); var meal = recipe.Prepare(ingredients); diner.Give(meal);} Each subroutine can, of course, be broken down further; preparing the meal might involve heating pans, cooking omelets and toasting bread. Were humans to perform these sorts of tasks like typical computer programs, we’d carefully write down everything as sequences of hierarchical tasks in a checklist and obsessively ensure that each job was complete before embarking on the next.

A subroutine-based approach seems reasonable—you can’t cook the eggs before you get the order—but in fact it both wastes time and makes the application appear unresponsive. It wastes time because you want the bread to be toasting while the eggs are frying, not after the eggs are done and getting cold. Reflection Overview. Reflection can also be used to create applications called type browsers, which enable users to select types and then view the information about those types.

Reflection Overview

Dynamic in C# 4.0: Introducing the ExpandoObject - C# Frequently Asked Questions. Well, where else can you use this new feature? What are the use cases? Where does dynamic dispatch work better than static typing? The quick answer is that whenever you see syntax like myobject.GetProperty("Address"), you have a use case for dynamic objects. First of all, the above syntax is difficult to read. Second, you don’t have any IntelliSense support for the property name, and if the “Address” property doesn’t exist you get a run-time exception. Here’s a code example that I took from MSDN. XElement contactXML = new XElement("Contact", new XElement("Name", "Patrick Hines"), new XElement("Phone", "206-555-0144"), new XElement("Address", new XElement("Street1", "123 Main St"), new XElement("City", "Mercer Island"), new XElement("State", "WA"), new XElement("Postal", "68042") ) );

Impromptu-interface - ImpromptuInterface: Static interface to dynamic implementation (duck casting). That and more using the DLR. This Project has been moved to GitHub: C# 4.0 (.net & silverlight) framework to allow you to wrap any object (static or dynamic) with a static interface even though it didn't inherit from it.

impromptu-interface - ImpromptuInterface: Static interface to dynamic implementation (duck casting). That and more using the DLR.

It does this by emitting cached dynamic binding code inside a proxy. By expanding on the DLR plumbing used to implement this library, it has grown to support more general dynamic implementations. Unusual uses of ExpandoObject in C# 4 : Reed Copsey, Jr. Posted by Reed on Friday, November 6, 2009 · 7 Comments Most of the examples for using ExpandoObject basically demonstrate a replacement for a Hashtable or Dictionary<string,object>, but with a “nicer” syntax.

Unusual uses of ExpandoObject in C# 4 : Reed Copsey, Jr.

For example, Alexandra Rusina blogged about using ExpandoObject, showing how you can use this to simplify access to XML documents. In general, this basically makes ExpandoObject a property bag – but the XML sample could have easily been written using a dictionary, if with a bit more verbose of a syntax. However, there are some use cases for ExpandoObject that go above and beyond what can easily be done with a dictionary.

First off, ExpandoObject implements INotifyPropertyChanged. URL Routing in ASP.NET 4. By Scott Mitchell Introduction In the .NET Framework 3.5 SP1, Microsoft introduced ASP.NET Routing, which decouples the URL of a resource from the physical file on the web server.

URL Routing in ASP.NET 4

Using ASP.NET Routing Without ASP.NET MVC. By Scott Mitchell Introduction ASP.NET MVC is a Microsoft-supported framework for creating ASP.NET applications using a Model-View-Controller pattern.

Using ASP.NET Routing Without ASP.NET MVC

Chapter 9. Delegates, Events, and Lambda Expressions. Problem You have multiple objects that need to observe modifications to objects that implement IDictionary<K,V>.

Chapter 9. Delegates, Events, and Lambda Expressions

When an item is added or modified in the dictionary-based collection, each of these observer objects should be able to vote to allow or disallow the action. In order for an action to be allowed to complete, all observer objects must state if they are vetoing the action. If even one observer object votes to disallow the action, the action is prevented. Solution. Lambda Expressions (C# Programming Guide) Enumerable Methods (System.Linq) LINQ TO XML. Getting Started Walking Through a Silverlight Application Take a tour of the XAML and Javascript generated by an application template that's installed with the Silverlight SDK. Organizing XAML Assets Learn how to organize XAML assets in Expression Design and Expression Blend to maximize developer efficiency. Hosting HTML Content This video demonstrates various ways you can use existing HTML content within your Silverlight application including full pages, fragments, or syndicated content.

Understanding Mouse Input Learn about Mouse input and how to use some of the mouse functionality available in Silverlight. What is that IGrouping result returned from group by LINQ queries? I dont know how much you people use LINQ but for me it was like a blessing. Since I figured out how helpful it is I never really looked back. But this post is not about obvious usefulness of LINQ, everyone should know that by now!!!

Dynamic in C# 4.0: Introducing the ExpandoObject - C# Frequently Asked Questions.

Blogs

Fabulous Adventures In Coding.