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

September 2008 Entries

This is a follow-up post on an article from a few months back and hopefully expands on how to overcome the error "failed to lazily initialize a collection, no session or session was closed" which I get very often in WinForms development.


Seeing as duck-typing is a buzz topic and quite the rage at the moment, I thought I'd try and introduce my own spin on this, namely duck-copying. As the title suggests, it's more like a copy constructor and an extension method for copying objects of different types, but have properties that are named the same and have the same type.


I feel that one of the short-comings in C# is the lack of default copy constructors for classes and, to add to my frustration, the help provided in MSDN about this topic just doesn't cut it. I decided to implement my own "generic" copy constructor, which is by no means feature-complete, but certainly delivers what I need now. Here is an example that'll hopefully help...


I came across a problem when a virtual directoy I had created inherited the setting from my web config file in the parent directory. I was always aware of this, and had used it to great effect, however, in this case, the parent site had all sorts of http modules/handlers and page directives included, and I really didn't want to (a) copy all of the bin files across just to make it work, or (b) add a whole bunch of <remove /> tags to the various sections just to take them out. After a bit of trial-and-error typing, I came across...