RSS Live C# RSS Feed...

  • Bad Metaphors
    The standard way to teach beginner OO programmers about classes is to make a metaphor to the real world. And indeed, I do this all the time in this blog, usually to the animal kingdom. A "class" in real life codifies a commonality amongst a certain set of objects: mammals, for example, have many things in common; they have backbones, can grow hair, can make their own heat, and so on. A class in a programming language does the same thing: codifies a commonality amongst a certain set of objects v

  • Fixing Floating Rectangles in ASP.NET StackedBar Chart
    In working on a client’s reporting system, I ran across some StackedBar charts that were using the System.Web.DataVisualization.Chart control that were having some problems.  The biggest one was that the rendered bars had gaps and floating rectangles in it.  This turned out to take about an hour to solve, using my best Google-fu, so I’m posting my solution and notes here, in case I run into it again and to save some other poor soul an hour’s time. The Problem Here’s what the chart look

  • Creating a dynamic, extensible C# Expando Object
    I love dynamic functionality in a strongly typed language because it offers us the best of both worlds. In C# (or any of the main .NET languages) we now have the dynamic type that provides a host of dynamic features for the static C# language. One place where I've found dynamic to be incredibly useful is in building extensible types or types that expose traditionally non-object data (like dictionaries) in easier to use and more readable syntax. I wrote about a couple of these for accessing old s

  • What is "binding" and what makes it late?
    "Late binding" is one of those computer-sciency terms that, like "strong typing", means different things to different people. I thought I might describe what the term means to me. First off, what is "binding"? We can't understand what it means to bind late if we don't know what it is to bind at all. A compiler is by definition a device which takes in a text written in one language and outputs code that "means the same thing" in another language. The compiler I work on, for example, takes in C#

  • Code Review Singleton Pattern Issues
    One of my applications relies on a singleton pattern to create a single instance of a server which processes requests from many different ASP.NET handlers.  It is created using pretty much standard Singleton code: public static Context CreateContext() { return CreateContext(new ConfigurationFileSettings()); } Recently, this server needed to be made aware of whether requests were coming into it via SSL or standard HTTP.  The solution that was checked in (and which worked and pa

  • Dynamic Types and DynamicObject References in C#
    I've been working a bit with C# custom dynamic types for several customers recently and I've seen some confusion in understanding how dynamic types are referenced. This discussion specifically centers around types that implement IDynamicMetaObjectProvider or subclass from DynamicObject as opposed to arbitrary type casts of standard .NET types. IDynamicMetaObjectProvider types  are treated special when they are cast to the dynamic type. Assume for a second that I've created my own implementa

  • Foreach, IEnumerable, IEnumerator, and Duck Typing
    During my Software Craftsmanship Precompiler session, I heard one of the students say, “all you need is an IEnumerable to use a foreach loop”. This sparked a bit of fun when I asked Steve Smith, my co-presenter, if that was correct. He confirmed that it was, and I disagreed. Being the scientists that we are, we decided to try it and see what happened. I of course knew that duck typing in C# should allow the Foreach loop to compile without anything having the method required by the IEnumerable in

  • Anonymous types unify within an assembly, Part One
    Back in my last post of 2010 I said that I would do an example of anonymous types unifying within an assembly "in the new year". I meant 2011, but here we are "in the new year" again, so, no time like the present. The C# specification guarantees you that when you use "the same" anonymous type in two places in one assembly (*) the types unify into one type. In order to be "the same", the two anonymous types have to have the exact same member names and the exact same member types, in the exact sa

  • Run Your Unit Tests in Parallel to Maximize Performance
    If you’re at all serious about testing, at some point you’re going to have a rather large suite of tests that need to run, and you’ll find that your builds are taking longer than you would like because of how long the tests run.  For example, consider this suite of 24 tests, each one of which looks like this one: If you run 24 of these, it’s going to take about 24 seconds, by default: Now of course it’s important to keep your unit tests and integration tests separate and to know which

  • Eduasync part 19: ordering by completion, ahead of time...
    Today's post involves the MagicOrdering project in source control (project 28). When I wrote part 16 of Eduasync, showing composition in the form of majority voting, one reader mailed me a really interesting suggestion. We don't really need to wait for any of the tasks to complete on each iteration of the loop - we only need to wait for the next task to complete. Now that sounds impossible - sure, it's great if we know the completion order of the tasks, but half the point of asynchr

  • Tags: AJAX Live Virtual Instructor-Led Training Microsoft Expression C# Visual Basic HTML JavaScript XML XSL SharePoint CSS XPath Microsoft .NET HTML5 & CSS3 ASP .NET WPF Web 2.0 Silverlight VBA MS Office Java ASP MVC jQuery Visual Studio Technical Training Solutions Onsite Instructor-Led Training