Click here to Skip to main content
15,907,906 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: Wow, Just Wow Pin
Pete O'Hanlon7-Aug-14 7:21
mvePete O'Hanlon7-Aug-14 7:21 
GeneralRe: Wow, Just Wow Pin
Rob Grainger7-Aug-14 7:45
Rob Grainger7-Aug-14 7:45 
GeneralRe: Wow, Just Wow Pin
fixthebugg7-Aug-14 10:11
fixthebugg7-Aug-14 10:11 
GeneralRe: Wow, Just Wow Pin
Brisingr Aerowing7-Aug-14 14:18
professionalBrisingr Aerowing7-Aug-14 14:18 
GeneralRe: Wow, Just Wow Pin
Bernhard Hiller7-Aug-14 21:43
Bernhard Hiller7-Aug-14 21:43 
AnswerRe: Wow, Just Wow Pin
Ravi Bhavnani10-Aug-14 10:53
professionalRavi Bhavnani10-Aug-14 10:53 
GeneralRe: Wow, Just Wow Pin
Marc Koutzarov29-Aug-14 21:48
professionalMarc Koutzarov29-Aug-14 21:48 
GeneralMore great naming Pin
Rob Grainger7-Aug-14 5:37
Rob Grainger7-Aug-14 5:37 
RantHaving enough data Pin
loctrice7-Aug-14 4:42
professionalloctrice7-Aug-14 4:42 
GeneralRe: Having enough data PinPopular
PIEBALDconsult7-Aug-14 5:04
mvePIEBALDconsult7-Aug-14 5:04 
GeneralThe first time, and the first time 2. Pin
Rob Grainger7-Aug-14 0:27
Rob Grainger7-Aug-14 0:27 
GeneralRe: The first time, and the first time 2. Pin
OriginalGriff7-Aug-14 0:56
mveOriginalGriff7-Aug-14 0:56 
GeneralRe: The first time, and the first time 2. Pin
Rob Grainger7-Aug-14 1:04
Rob Grainger7-Aug-14 1:04 
GeneralRe: The first time, and the first time 2. Pin
Dave Kreskowiak7-Aug-14 3:01
mveDave Kreskowiak7-Aug-14 3:01 
RantRe: The first time, and the first time 2. Pin
Kornfeld Eliyahu Peter7-Aug-14 3:32
professionalKornfeld Eliyahu Peter7-Aug-14 3:32 
GeneralRe: The first time, and the first time 2. Pin
Dave Kreskowiak7-Aug-14 5:02
mveDave Kreskowiak7-Aug-14 5:02 
GeneralRe: The first time, and the first time 2. Pin
Rob Grainger7-Aug-14 5:34
Rob Grainger7-Aug-14 5:34 
GeneralRe: The first time, and the first time 2. Pin
Dave Kreskowiak7-Aug-14 6:42
mveDave Kreskowiak7-Aug-14 6:42 
GeneralRe: The first time, and the first time 2. Pin
Rob Grainger7-Aug-14 5:35
Rob Grainger7-Aug-14 5:35 
GeneralRe: The first time, and the first time 2. Pin
PIEBALDconsult8-Aug-14 9:29
mvePIEBALDconsult8-Aug-14 9:29 
GeneralRe: The first time, and the first time 2. Pin
  Forogar  7-Aug-14 4:00
professional  Forogar  7-Aug-14 4:00 
JokeRe: The first time, and the first time 2. Pin
Paul M Watt7-Aug-14 6:04
mentorPaul M Watt7-Aug-14 6:04 
GeneralRe: The first time, and the first time 2. Pin
Sander Rossel7-Aug-14 7:39
professionalSander Rossel7-Aug-14 7:39 
GeneralSetProperty!!! PinPopular
Super Lloyd5-Aug-14 21:03
Super Lloyd5-Aug-14 21:03 
C#
public static class Extensions
{
    public static void SetProperty(this object domainEntity, string propertyName, object value)
    {
        var t = domainEntity.GetType();
        var p = t.GetProperty(propertyName, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic);
        p.SetValue(domainEntity, value);
    }
    public static void SetProperty<T, TProp>(this T domainEntity, Expression<Func<T, TProp>> getP, TProp value)
    {
        var e = (MemberExpression)getP.Body;
        SetProperty(domainEntity, e.Member.Name, value);
    }
}

This piece of code has a fantastic history that is not obvious...
Why is that you might ask?

Well.. the single architect of our application decided that we were going to use Domain Driven Design (DDD). He also decided that all domain object property will have private setters. This being, as you can imagine, inconvenient, we got large use of this method (which he also wrote) to set private properties whenever needed!

Brilliant! Let's use private property for safety! And let's use this method to ignore private! Genius! Suspicious | :suss: Shucks | :-\ Big Grin | :-D
My programming get away... The Blog...
DirectX for WinRT/C# since 2013!
Taking over the world since 1371!

GeneralRe: SetProperty!!! Pin
Bernhard Hiller5-Aug-14 21:13
Bernhard Hiller5-Aug-14 21:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.