Where are C#'s meta-classes?

In Delphi you can define a meta class and pass classes into methods.

TFoo = class(TObject);

TFooClass = class of TFoo;

function MakeFoo( aFooClass : TFooClass ) : TFoo;
begin
    result := aFooClass.Create();
end;

This allows very generic code where you can get away with just passing in a class name.
I use this heavily in Delphi as part of a test framework (the meta class represents test data).

I think that this can be done in C# using reflection but there should be a cleaner method.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s