... Home Contact

Krzysztof Koźmic's blog

Designed in Poland, assembled in Australia.


Show appreciation: My Amazon.com Wish List


Me@Twitter

    Currently reading

    Article Categories

    Archives

    Post Categories

    MyPersonal

    Syndication:

    November 2008 Entries

    Castle DynamicProxy IInterceptorSelector implementation

    I just got this test pass: [Test] public void BasicCase() { ProxyGenerationOptions options = new ProxyGenerationOptions(); options.Selector = new AllInterceptorSelector(); var target = this.generator.CreateInterfaceProxyWithTarget( typeof(ISimpleInterface), new SimpleClass(), options, new NoopInterceptor() ) as ISimpleInterface; Assert.IsNotNull( target ); target.Do(); } And here’s how Do proxy method looks like in...

    Expressions aren’t made equal

    I got surprised by Expressions last week while trying to create a caching mechanism for them. To be precise, this piece of code static void Main() { Expression<Action<string>> first = s => Console.WriteLine(s); Expression<Action<string>> second = n => Console.WriteLine(n); Expression<Action<string>> third = n => Console.WriteLine(n); Check(first, second); Check(second, third);   }   private static void Check(Expression<Action<string>> a, Expression<Action<string>> b) { ...

    Microoptimizations: foreach vs for in C#

    Patrick Smacchia wrote a post where he compares execution time while using different patterns to iterate over a collection, namely List<int> and int[]. Since he provided the code, I decided to give it a go as well. Only thing I did, was I added [MethodImpl(MethodImplOptions.NoInlining)] for each method, since they all were very simple, and could easily be inlined. That said, here are my results (release build ran without debugger, outside of Visual Studio): If you compare those to Patrick’s results, you may notice few things: Patrick has a faster PC...

    Five books I wish existed

    I read a lot of blogs. I love them. However, I believe they are not the best medium if you want to learn something from A to Z. That said, here’s my wishlist of books that I wish existed. “Creating maintainable software architecture” – Oren Eini “Maintainable software development” – Oren Eini “Advanced Windows Communication Foundation from the inside” – Nicholas Allen “Building service oriented software” – Udi Dahan “Presentation patterns with WPF” – Glenn Block (There is more broad book “Presentation Patterns” to...

    You don’t get the C# 4.0, do you?

    Sorry for the daring topic, but that’s really what comes to my mind when I read or hear people whining about C# loosing purity/object-orientation/strongly-typedness/goal/insert your favorite here, with the advent of version 4.0. To sum it up, there are four major new areas of improvement coming up with the forthcoming version of the language, as outlined by Charlie Calvert in "New Features in C# 4.0". dynamic keyword (type) along with all its implications. Optional and named parameters. Co/Contra-variance of generics Few additional features geared towards easing...

    Creating tree of dependencies with MEF

    As a follow up to my previous post, here’s the simplified – Console based version of the code. Disclaimer. This is a solution. Not the best one, not recommended by anyone, just the one that happened to solve my problem. So take it with a (big) grain of salt, and if you know a better one, use the Leave your comment function below. using System; using System.ComponentModel.Composition; using System.Reflection;   [assembly:AllowNonPublicComposition] namespace ConsoleApplication1 { class Program ...

    MEF is not a dependency injection framework

    Part of a project I’m working on, has strong extensibility requirements, so for last two days I’ve been working on a proof of concept prototype for it, using MEF. Not only do we need plug-ins, but also there will be at least two client applications using them (one in WPF, and the other one in Silverlight), so we decided to decouple the view of the plug-in from the logic behind it using something along the lines of MVP (Presenter First would be the closest). That is where I hit the wall. I decorated my classes and interfaces with...

    Delegate.CreateDelegate exception with proxies

    While playing with dynamic invocation of WCF proxies I found a strange behavior with Delegate.CreateDelegate method. It throws exception when trying to create delegate for WCF proxy method. The following sample code causes the ArgumentException with message “Error binding to target method.”   private static void Main() { ...