Category: code

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 →

markdown in BlogEngine.NET

BlogEngine.NET has half baked support for markdown. You can install MarkdownFormatterExtension but this doesn’t do anything unless you enter raw text into the HTML editor view. There is an additional problem that the posts are saved as Xml and as such all the white space is removed during the save process. You can get around this by tweaking the Post… Read more →

Migrate from wordpress to blogengine.net

http://weblogs.asp.net/aghausman/archive/2009/07/20/migrate-from-wordpress-to-blogengine-net.aspx http://www.machinadei.com/cms/dev/importing-your-old-wordpress-posts-into-orchard-cms#.Uk7Kt9K-qfY http://wpblogml.codeplex.com/ use google prettify insert option from comments with defer in the header https://code.google.com/p/google-code-prettify/wiki/GettingStarted Read more →

NOT using repository pattern, use the ORM as is (EF)

This was originally posted as an answer to a question on stackoverflow here IMO both the Repository abstraction and the UnitOfWork abstraction have a very valuable place in any meaningful development. People will argue about implementation details, but just as there are many ways to skin a cat, there are many ways to implement an abstraction. Your question is specifically… Read more →