3.17.2010

Dynamic + Extension Methods = Fail

I am playing around with dynamics right now working on a solution for a completely different problem.

I discovered a issue I didn’t foresee (and maybe I am doing something wrong).

I use AssertExtensions to make my tests more readable so I created my first extension.

public static class AssertExtensions
{
    public static void ShouldBe<T>(this T actual, T expected)
    {
        Assert.AreEqual(expected, actual);
    }
}

I created a test to ‘get’ a property from a dynamic object.

[TestMethod]
public void should_be_able_to_get_property()
{
    var book = new Book {Title = "Icarus Hunt", Author = "Timothy Zahn"};

    var d = book as dynamic;

    d.Author.ShouldBe("Timothy Zahn");
}

Should work right?

Wrong.

image

Oh noes!

Apparently the RuntimeBinder can’t figure out the extension to string. My solution was to do this:

[TestMethod]
public void should_be_able_to_get_property()
{
    var book = new Book {Title = "Icarus Hunt", Author = "Timothy Zahn"};

    var d = book as dynamic;

    var author = d.Author as string;

    author.ShouldBe("Timothy Zahn");
}

I just found it interesting that it didn’t behave the way I would have expected.

3.09.2010

100 Books Every Man Must Read

So over lunch I decided to mark down which of the 100 books every man must read I have actually read.

 

Read

  1. The Great Gatsby
  2. 1984 <- multiple times... pure genius
  3. The Catcher in the Rye
  4. The Picture of Dorian Gray
  5. How to Win Friends and Influence People
  6. Call of the Wild
  7. Swiss Family Robinson
  8. Catch-22 <- love it! I need to reread.
  9. Lord of the Flies
  10. Don Quixote ... yes I've read it. It was long and I don't remember any of it.
  11. The Hobbit
  12. Huckleberry Finn
  13. Animal Farm <- again.. genius.
  14. Frankenstein <- Fire.... bad
  15. Hamlet
  16. The Stranger
  17. The Island of Dr Moreau
  18. All Quiet on the Western Front <- literally changed my mind about going into the army :)
  19. To Kill a Mockingbird

 

Read Excerpts

  1. The Prince
  2. The Republic
  3. Brave New World (still need to finish it)
  4. The Iliad and Odyssey
  5. Walden
  6. The Metamorphosis
  7. The Art of Warfare
  8. The Divine Comedy <- I read Inferno
  9. The Politics
  10. The Federalist Papers <- genius
  11. Moby Dick <- started but never finished
  12. Paradise Lost
  13. The Red badge of Courage
  14. The Bible
  15. Zen and the Art of Motorcycle Maintenance

3.07.2010

Adv WPF Videos

The videos are up from the Adv WPF Workshop we had here at EPS.

Videos (the links are kind of slow and funky atm. I will look into it on Monday. I had more luck downloading the file as opposed to streaming it)

I had a great time talking through some of the things we are doing here with WPF. I think it took awhile to get started but towards the end I think we picked up speed.

I don’t exactly recall the topics right now but I believe we did cover these items from the original agenda:

  • INotifyPropertyChange
    • Normal
    • Type Safe
    • Dynamic Proxy
    • AOP
  • View + ViewModel
    • Typical methods
    • IView extensions
    • IView<VM>
    • ViewRegistry
    • Also will be covering StructureMap conventions (TypeScanners) and Type Interceptors
  • Event Aggregator
    • using Events
    • Publish extension method
    • ISubscribe
    • Putting it all together with a Region Controller

I guess one big note would be that PostSharp is no longer open source therefore you need a license for their 2.0 product. At EPS we picked up licenses for our current solution. The benefit we get out of PostSharp and AOP far surpasses the license price even when you have to buy the license for every developer.

Check PostSharp out at http://www.sharpcrafters.com/

I think we are going to work on a PostSharp CodeCast or some other informative session on the tool.

Considering we have the Houston Open Spaces coming up, I will probably delay another workshop for a bit. But I had a good time and will probably do another one around May or June.

I want to thank everyone who came online and on site. It was a lot of fun! Please provide feedback so we can make the next workshop even better.