For example, if you want to call the static method "Foo" on the class
"Bar", in .NET, you have two choices:

1. Foo.Bar()
2. typeof(Foo).GetMethod("Bar", ...).Invoke()

What if you wanted to treat "Foo" in a way that you only cared about
having "a class which has the static method Bar() on it" without
knowing the class? In .NET, you only choice is reflection (#2), and I
think we can all admit that's not a very OO route.

You can do it in a very typesafe way using the Dynamic library[1] with fun like:

public class BarBell<T>
{
  static readonly StaticFunc<T, int, DateTime> _bar =
Dynamic<T>.Static.Function<int>.Explicit<DateTime>.CreateDelegate("Bar");

  static int Bar(DateTime when)
  {
     return _bar(when);
  }
}

Not that this has anything to do with your _correct_ point that
classes aren't objects in .Net

[0] http://www.codeplex.com/Dynamic

--
"I am Dyslexic of Borg. Resistors are fertile. Prepare to have your
ass laminated." -- Dan Nitschke

Marc C. Brooks
http://musingmarc.blogspot.com

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to