Syndication

News

     

Archives

Miscelaneous

Programming

June 2011 - Posts

Someone asked me how to mock a dynamic object with Moq, which might be non-obvious.

Given the following interface definition:

public interface IProject
{
  string Name { get; }
  dynamic Data { get; }
}

When you try to setup the mock for the dynamic property values, you get:

image001

 

What’s important to realize is that a dynamic object is just a plain object, whose properties happen to be resolved at runtime. Kinda like reflection, if you will: all public properties of whatever object happens to be the instance, will be resolved just fine at runtime.

Therefore, one way to mock this dynamic is to just create an anonymous type with the properties we want, and set the dynamic property to return that:...

Read full article

Posted by Daniel Cazzulino
Filed under:

I’m spiking ideas on how to make my regular expressions easier to read and maintain for the dev who comes after me (that could be myself in 3 months, meaning I will surely have forgotten everything about how that crazy regex worked).

I’m aware and wary of fluent API alternatives to building regular expressions which IMO hinder readability more than anything. They are just too verbose.

So here’s a progression of options that I’m thinking of. I’d like to get your feedback on what makes for a readable pattern and how much you care about extension method pollution (since patterns are all strings, extension methods would need to “hang” there):...

Read full article

Posted by Daniel Cazzulino
Filed under:

Is it just me or the X220 is just plain better in almost all relevant fronts?

  X1 X220
Chipset/CPU Intel®   Core™ i7-2620M Processor (2.7GHz, 4MB L3 Cache) USB 3.0
    Core™ i5-2540M Processor (2.5GHz, 3MB L3 Cache)
  Core™ i5-2520M Processor (2.5GHz, 3MB Cache) Core™ i5-2520M Processor (2.5GHz, 3MB Cache)
    Core™ i5-2410M Processor (2.3GHz, 3MB L3 Cache)
  Core™ i3-2310M Processor (2.1GHz, 3MB L3 Cache) Core™ i3-2310M Processor (2.1GHz, 3MB L3 Cache)
     
Display 13.3” HD (1366x768) Super Bright (350 NITS) (non IPS, *glossy*!) Display 12.5" HD (1366x768) LED Backlit Display ...

Read full article

Posted by Daniel Cazzulino
More Posts