Article View: borland.public.csharpbuilder.language.csharp
Article #110Replacement for "class of" in C#?
From: Shawn Oster
Date: Fri, 22 Dec 2006 22:42
Date: Fri, 22 Dec 2006 22:42
28 lines
1903 bytes
1903 bytes
I'm trying to port a factory I use in Delphi to C# and have hit a snag. In Delphi I usually make light-weight factories like this: TGizmo = class(TObject) // stuff here end; TGizmoClass = class of TGizmo; TGizmoFactory = class(TObject) private FHashedListOfGizmoClasses: TClassHashList; public procedure RegisterClass(const ClassKey: string; ClassType: TGizmoClass); function CreateObject(const ClassKey: string): TGizmo; end; As you can see I pass in a key and a class type, then in CreateObject I simply look up the key in the hash, call TGizmoClass.Create and *bam* there is my new object. My question is: How can I create a type-safe class type to pass into my factory? All the examples I see require creating a concrete factory for every concrete class but that seems like a waste. I'm sure I'm just overlooking something super simple. Thanks, Shawn
Technical Details
Message-ID:
<458c5f4b@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!out04b.usenetserver.com!news.usenetserver.com!in01.usenetserver.com!news.usenetserver.com!newsfeed.media.kyoto-u.ac.jp!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 1efe35,454cd7256a34fa43,start X-Google-Attributes: gid1efe35,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Shawn Oster" <soster@colorflex.com> Newsgroups: borland.public.csharpbuilder.language.csharp Subject: Replacement for "class of" in C#? Date: Fri, 22 Dec 2006 15:42:34 -0700 Lines: 30 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3028 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028 X-RFC2646: Format=Flowed; Original NNTP-Posting-Host: 216.150.210.34 Message-ID: <458c5f4b@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1166827339 216.150.210.34 (22 Dec 2006 14:42:19 -0800) Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!out04b.usenetserver.com!news.usenetserver.com!in01.usenetserver.com!news.usenetserver.com!newsfeed.media.kyoto-u.ac.jp!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail