The Darkside

Shedding light on things and stuff

 
  Home :: Contact :: Syndication  :: Login
  75 Posts :: 0 Stories :: 49 Comments :: 2 Trackbacks

Ads

Archives

Post Categories

Open Source Projects

Other Blogs

August 2009 Entries

Seeing as I have to search for this code snippet on most occasions that I use it, I’ve decided to put it here as a post. I often find that I have to repeat the same code over and over when converting between two similar types (e.g. Person domain object and PersonDto object). If you see something like this crop up too often: var personDto =  new PersonDto {     Id = person.Id,     FirstName = person.FirstName,     LastName = person.LastName,     Age = person.Age }; You have two options: 1)...


This is (another) look at implementing a dynamic proxy using Reflection Emit. Why would you need a dynamic proxy? Well, there are times when functionality needs to be injected into existing code that can not be modified. My dynamic proxy generator allow you to supply two Action parameters the will be executed as pre- and post-call methods. The tests that I have provided with my sample application show an example of injecting timing code into existing methods. It could also be used to insert log


After doing some random surfing this morning (I think I started off with binging “operator precedence C#”, I landed on this page about one line variable swaps, which then got me thinking about how to do this in C#. My only solution I could come up with was using arithmetic to solve the problem:   int x = 11; int y = 42;   y = (y + x) - (x = (y + x) - x);   Debug.Assert(x == 42); Debug.Assert(y == 11);   Please don't use this code, unless you're on some type of job security mission :)  UPDATE: 12 Aug 2009 – Ok, so I wasted more...