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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:53:24+00:00 2026-06-03T07:53:24+00:00

I have two simiiliar methods for parsing lines. first method public IList<LasLine> GetLasLines(string section)

  • 0

I have two simiiliar methods for parsing lines.
first method

 public IList<LasLine> GetLasLines(string section)
        {
            var lasLines = new List<LasLine>();
            bool startParse = false; // Секція знайдена і почати парсити її
            foreach(var line in _lines)
            {
                if(GetSectionName(line).Equals(section) && !startParse)
                {
                    startParse = true;
                }
                else
                {
                    if(IsCommentLine(line)) continue; 
                    if(IsBeginSection(line)) break; 
                    LasLine lasLine;
                    if(!TryParseLasLine(line, out lasLine)) continue; 
                    lasLines.Add(lasLine); 
                }
            }
            return lasLines;
        }

And second

public IList<AsciiLogDataLine> GetAsciiLogData()
{
var asciiLogData = new List<AsciiLogDataLine>();
bool startParse = false; 
foreach(var line in _lines)
{
if(GetSectionName(line).Equals(LasSectionName.ASCIISection) && !startParse)
{
startParse = true;
}
else
{
    if(IsCommentLine(line)) continue; 
    AsciiLogDataLine asciiLogDataLine;
    if(!TryParseAsciiLogDataLine(line, out asciiLogDataLine)) continue;                         asciiLogData.Add(asciiLogDataLine);          
              }
    }
    return asciiLogData;
    }

Is it possible to implement this pattern?

  • 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-03T07:53:25+00:00Added an answer on June 3, 2026 at 7:53 am

    As i think, you can create common Contract (Interface) for this Line Classes, and use for example Generic Method.

    IEnumerable<IDataLine> GetLines<T>(Func<object> parseFunction)
    {
       ...
       var dataLine = parseFunction(line);
       if (dataLine == null)
       {
           continue;
       }
       ...
    }
    

    Or you can create IParser and inject it into the method

    IEnumerable<IDataLine> GetLines<T>(IParser parser)
    {
       ...
       if (!parser.CanParse(line))
       {
            continue;
       }
       var dataLine = parser.Parse(line);
       ...
    }
    

    Last sample more similar to the Strategy Pattern.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two very similar methods: public IQueryable<User> Find(Func<User, bool> exp) { return db.Users.Where(exp);
I have the following two methods that (as you can see) are similar in
I have two similar codes. The first one works as expected. urlpatterns = patterns('',
I have two extension methods that are very similar. I'd like to remove the
I have two similar methods that take a criteria object (dumb object with a
If I have two yield return methods with the same signature, the compiler does
I have two very similar methods in Grails, something like calculate statistics by os
First, a little background (greatly simplified): I have two classes, one called Entity and
In apache.commons.collections there is a class called MapUtils which have these two methods to
assume that i have two sequential methods, methodA and methodB ( methodB is called

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.