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 8418341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:17:53+00:00 2026-06-10T02:17:53+00:00

My Problem I have a Problem which i can not solve my self. I

  • 0

My Problem

I have a Problem which i can not solve my self. I dont want to use so much code, because i have multiple Classes which extend another class (in my case its called “Data”).

I have a log file, where each Data Group is beginning with a specific Group Name, for example “MitarbeiterSet”. The abstract Data-Class is used to prefent to much code, where I implemented variables like “String[] data” (for the data beeing parsed from the log file e.g. < 101 4 3 6 3 30 80 2 0 0 1 300 >) or “static String parseInduction”, which is used to determin, if this Class is the right one to create Objects from.

I have another Class, called ParseMonitor, which creates the StreamReader to parse the log-file. So if the right Class is found, i induct the setDataArray(StreamReader sr) function from the right Class, to parse the Data Array. (At this point i have to tell you, that i need those different Classes, because i need to upload them to a sql server specificly.)

This static function creates an object of it self and uses the parseLine(String line) Function to fill the object with data from the given line.

WHAT I NEED.

I want to call the static function of any class, just by having the name of this class. So i dont have to use that much code and be able to add more classes.

Later on i want to call every class and use the uploadToServer() to Upload it to the server.

Is this possible?

  • 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-10T02:17:55+00:00Added an answer on June 10, 2026 at 2:17 am

    Since your static method is creating an instance of its class anyway, I suggest a different approach:

    Create an interface that all classes that contain ParseLine can implement. (Change out the return type for the correct one):

    public interface IParseLine
    {
        string ParseLine(string line);
    }
    

    Have all of the classes that contain ParseLine() implement IParseLine.

    Create an instance of the class, cast it to an IParseLine, and execute the method:

    IParseLine pl = Activator.CreateInstance(Type.GetType(className)) as IParseLine;
    if (pl != null)
    {
        string parsedString = pl.ParseLine(line);
        // ...
    }
    

    Edit From comments:

    I want to create a while loop, which can be stated as followed:
    while{!sr.EndofStream){ line = sr.ReadLine(); for(int i = 0; i <
    classNames.length; i++){ if(line.Contains(classNames[i].MYINDICATOR){
    CALL classNames[i] STATIC METHOD TO PARSE THE FOLLOWING LINES AND
    CREATE DATA Objects of its Class } }

    I didn’t test this, but you can change the code to something like this (caching the reflection required to get MYINDICATOR):

    IList<KeyValuePair<string, Type>> typeIndicators = classNames.Select(x => {
        Type t = Type.GetType(x);
        string indicator = (string)t.GetField("MYINDICATOR", BindingFlags.Public | BindingFlags.Static).GetValue(null);
        return new KeyValuePair(indicator, t);
    });
    
    while (!sr.EndOfStream)
    {
        line = sr.ReadLine();
        foreach (var types in typeIndicators)
        {
            if (line.Contains(types.Key))
            {
                 IParseLine pl = Activator.CreateInstance(types.Value) as IParseLine;
                 if (pl != null)
                 {
                     string parsedString = pl.ParseLine(line);
                 }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small problem which i can't seem to solve myself. Look at
I'm having a problem, which already searched the internet but can not solve. I
I have a problem which i can't seem to find the solution to. I
I have the following problem: I have a search box in which user can
Here is my problem : I have a list of messages which I can
I have some problem with my open new window popup which it can read
I have a small problem which i can't seem to figure out. I tried
I currently ran into a problem I can not really solve by myself: I
The general problem I want to solve is to have just one datatemplate for
I have two classes (let's call them Working and ReturnStatement) which I can't modify,

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.