Month: November 2013

Dynamic objects part II

I decided to extend my DynamicObject class to enable me to do this: [Test] public void MyDynamicObject_SetWithSetter_CanGetByReference() { // Arrange dynamic obj = new MyDynamicObject(); obj[“property1”] = true; // Act bool value = obj.property1; // Assert Assert.That(value); } And this: [Test] public void MyDynamicObject_SetDelegateWithSetter_CanCallDelegate() { // Arrange dynamic obj = new MyDynamicObject(); Func<bool> d = () => true; obj[“property1”] =… Read more →

Dynamic Objects in a Generic World

I have a situation where I want a dynamic object that can used within generic classes and methods. I have a generic service that accepts any instance that implements a predefined interface: public interface IMyInterface { bool enabled { get; set; } } public class MyGenericService<T> where T : IMyInterface { public void Process(T obj) { obj.enabled = true; }… Read more →

Simple Injector – How to discover the underlying Implementation Type of a decorated instance when calling GetAllInstances

I asked the question “How to discover the underlying Implementation Type of a decorated instance when calling GetAllInstances?” on stackoverflow and got a perfectly valid answer – here’s a sample implementation to prove that it would work. Start with some test abstractions and implementations: public interface ICommandHandler<TCommand> { void Execute(); } public class A { } public class B {… Read more →

Runtime Csv Exporter using Dapper

Today I decided to create a run-time compiled Csv generator and compare it to a compile-time version of the same code. It works a treat with little noticeable difference in performance over 10000 runs (of a very small table) These are the compile time definitions: public class Client { public long id { get; set; } public string forenames {… Read more →

Convert Html to Tiff

using System; using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Linq; using System.Text; using System.Windows; using System.Windows.Forms; using System.Windows.Media.Imaging; class Program { private static WebBrowser InitialiseBrowser(string source) { // create a hidden web browser, which will navigate to the page WebBrowser browser = new WebBrowser(); browser.ScrollBarsEnabled = false; // we don’t want scrollbars on our image browser.ScriptErrorsSuppressed… Read more →