Is there a way to do what classmethod
does in Python in C#?
That is, a static function that would get a Type object as an (implicit) parameter according to whichever subclass it's used from.
An example of what I want, approximately, is
class Base:
@classmethod
def get(cls, id):
print "Would instantiate a new %r with ID %d."%(cls, id)
class Puppy(Base):
pass
class Kitten(Base):
pass
p = Puppy.get(1)
k = Kitten.get(1)
the expected output being
Would instantiate a new <class __main__.Puppy at 0x403533ec> with ID 1.
Would instantiate a new <class __main__.Kitten at 0x4035341c> with ID 1.