• Mark (unregistered)

    Wow, I'm not even sure what to say about this, except, "WHY?!?"

  • Mikael Söderström (unregistered)

    WTF is that!?

  • RedWolves2 (unregistered)

    Public String DailyWTF
    {
    get
    {
    return "WTF?";
    }
    }

  • Ryan (unregistered)

    Yeah, that guy is messed up. He should totally be using a switch statement.

  • Frans Bouma (unregistered)

    He should have used a switch statement indeed, but besides that, this concept is not that bad. You see, with this you can keep a consistent interface definition (so no recompilation necessary for clients using this code) and still add new 'properties' to the class.

    Also, you can define SetParam() in a base class (this looks like VB* code, but in .NET you can) or interface and use it in generic code, making your code work with different types of objects.

    People who write generic code and have to set / get param values often go this route. In .NET you have reflection but that's pretty slow compared to this solution.

  • David Crowell (unregistered)

    I think the idea with this code is for a common interface. All of the classes that did this did inherit from the same class. However, they were never used in the generic way (variable of type baseclass), they were always the correct type.

    I came in late on this project. Some Java guys came up with an object model, and two low-level C# developers implemented it. The implementation leaves a lot to be desired. I have other fun examples I'll send in later :)

  • Sven (unregistered)

    Another thing could be that this is a parser for a file. Though it is not the most academic solution it does work. (Correct me if I am wrong).

  • David Crowell (unregistered)

    No, it's not a parser. To use the thing you create an instance and call SetParam() for each property, which were always hardcoded in the calling code. Then call Execute(). Makes my head hurt.

  • Tim Smith (unregistered)

    sigh

    Other people are right, this could have been useful. However, from what David is saying, they missed that boat too.

  • Centaur (unregistered)

    Isn’t this, in essence, how COM Automation IDispatch works? You give in an array of parameters and a function ID, and Invoke() dispatches your call to an appropriate function. This way, you always know exactly the binary interface (it only has Invoke() and several other functions), but you can extend the logical interface (set of allowed dispids).

    Of course they should at least put in an “else Debug.Assert(False) // invalid parameter name” at the end to try to spot mistypes.

  • Frans Bouma (unregistered)

    "(this looks like VB* code, but in .NET you can)"
    ... said the C# MVP...

    I will crawl back into a corner and cry now ;)

  • qwerty (unregistered)

    "Isn’t this IDispatch works?"

    Well, yes. And IDispath makes me think WTF also. I pity anyone tring to implement or consume IDispatch without a thunking layer.

  • Sven (unregistered)

    Oki nowing this is not a parser I say: sigh

    Well back to reading then :P

  • Richard Tallent (unregistered)

    While such a thing can be abused, I have a set of libraries where I use a similar technique so my query and import engines can be completely ignorant of the actual object properties and instead work the the exposed "surrogate" properties. Works wonders as well with my dynamic properties (database-driven, added at run-time).

    I've used other methods in the past (pure reflection and reflection plus attributes to name two), but this is actually the fastest method I've found. In fact, ObjectSpaces, the O/R mapper in .NET 2.0 uses something like this for property value look-up (can't remember if that library will make the cut or not).

  • V (unregistered)

    ... why not use reflection (for public properties/fields is fast...)

  • Roger (unregistered)

    it might be the he is deserializing an object from an xml document or whatever source.
    maybe looping through nodes and building the objects state this way..


    //Roger

  • beddless (unregistered)

    I think you could simplify this further....

    public string DoStuff(string Method, string Name, object Value) {...

    That way you could encompass get and set. You could introduce new methods like 'Screw Up' or 'Memory Leak' without even re-compiling your client. Great stuff!

    :)

  • xavier (unregistered)

    no no no no no no no
    why use a switch!?!?!?!
    its better to use String.Equals!!!!!
    lol

  • Haha (unregistered)

    Haha

Leave a comment on “Properties?”

Log In or post as a guest

Replying to comment #:

« Return to Article