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

  • Home
  • SEARCH
  • 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 8286475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:46:58+00:00 2026-06-08T11:46:58+00:00

I am new to programming to kindly bear me. I using c sharp, .net

  • 0

I am new to programming to kindly bear me. I using c sharp, .net 4, VS 2010

I have a interface class called IHandler with method IsValidate().
I have a message like AMOUNT 50 22.4, where AMOUNT is identifier.
So format of messages can be like FLOW 12 33 23.1, again where FLOW is identifier.

Now, based on the identifier i have different classes like ( I have around 15 – 20 classes like this, as i have to validate different message formats and sequence)

  1. AmountValidator

  2. FlowValidator

In these classes i have implementation of IsValidate() method, as these implement IHandler class.

Now my question is, once i identify the identifier of my message like AMOUNT or FLOW i want to create instance of the class.

What is the best way to do this?( I don’t want to create 30 instances in, if else statement )

Appreciate any help.

  • 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-08T11:46:59+00:00Added an answer on June 8, 2026 at 11:46 am

    You can do it like so:

    IHandler handler = (IHandler)Activator.CreateInstance("assemblyname", "typename");
    handler.IsValidate();
    

    The assembly name can be found on the properties page on the project where the handlers are.

    Here: assembly name

    You also have to remember that everything is case-sensitive, so the typename argument can’t be AMOUNTValidator if the class is actually named AmountValidator.

    EDIT: Factory sample:

    public static class HandlerFactory {
        private static Object factoryLock = new Object();
        private static List<IHandler> handlers = null;
    
        public static IHandler Gethandler(String type) {
            if (handlers == null) {
                lock (factoryLock) {
                    if (handlers == null) {
                        IEnumerable<Type> types = typeof(HandlerFactory).Assembly.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IHandler)));
                        handlers = types.Select(t => (IHandler)Activator.CreateInstance(t));
                    }
                }
            }
            return handlers.Where(h => h.Type == type);
        }
    }
    
    public interface IHandler {
        String Type { get; }
        Boolean IsValid(String data);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Totally new to programming so kindly excuse the silly question. I have this URL
I'm a new bie to python programming and programming as well. so kindly excuse
I'm new programming with Objective-C (my strongest skills is .Net), on .Net there's a
I've created my 'new programming language' using the ANTLR framework. The language is defined
I want to learn a new programming language. I have in mind stuff like
Im new to programming, in our c++ course, we have to build a stack
I have an interesting idea for a new programming language. It's based on a
It seems that most new programming languages that have appeared in the last 20
Suppose I have designed a new programming language for one of the managed code
What features could be added to a new programming language to make it more

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.