Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8313853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:37:50+00:00 2026-06-08T20:37:50+00:00

I am using an external DLL which has an abstract baseclass Packet and subclasses

  • 0

I am using an external DLL which has an abstract baseclass Packet and subclasses to Packet.

The subclasses are named after the number they represent, one name could be P132_RandomString. I am parsing a file containing these numbers and for each number I want to create a corresponding object. There are hundreds of different subclasses and the DLL have no factory method (at least not for my input).

The problem is I don’t know the “RandomString” part, if I did I could have used Reflection but I assume there is no way to use Reflection since I only know the beginning of the classname?

The only solution I could think of is implementing my own factory method with hundreds of case statements but this feels a bit cumbersome…

My question is: is there a nice way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T20:37:52+00:00Added an answer on June 8, 2026 at 8:37 pm

    You can use a LINQ Where clause to grab the type you want.
    Consider the following program:
    (This assumes you know the base class and the prefix)

    class Program {
        static void Main( string[] args ) {
    
            string prefix = "p22";
            IEnumerable<Type> types = Assembly.LoadFrom("c:\\Sample.Assembly.dll").GetTypes();    
            Type baseClass = typeof(foo);
            Type foundType = types.Where(
                t => t.Name.StartsWith( prefix ) &&
                    t.IsSubclassOf( baseClass )
                    ).SingleOrDefault();
            foo myClass = (foo)Activator.CreateInstance( foundType );
                    //Do Stuff with myClass 
        }
    }
    abstract class foo { }
    class p22_notMyClass { }
    class p22_myclass : foo { }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using an external swf containing a number of font classes to load and
Instead of using an external web-based Mercurial host, I want to set one up
One of the side-effects of using an external Subversion repository was getting automatic offsite
I'm using a number of C# custom controls (forms, buttons, etc) which use a
I have a DLL which has certain functionality which requires UAC elevated privileges in
I have a C# project which references a DLL (call it external DLL) which
I am using an external dll in my project. When i try to run
I am trying to clear images using external jquery file but it's not showing
I'm using an external API to receive xml and serializing this to an object
I am using the external library IMAPClient. When the login fails, i see this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.