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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:11:37+00:00 2026-05-16T06:11:37+00:00

I have a function which is processing rows from an excel file.In this function,I

  • 0

I have a function which is processing rows from an excel file.In this function,I have a for loop.Now,once a row is extracted,we check for various conditions.If any condition is false,we continue with next row.Can this code be made more structured using a pattern?

 foreach (System.Data.DataRow dr in ds.Tables[0].Rows)
                {

                    Product prod = GetProduct(dr);
                    if (prod == null)
                    {
                        IndicateNotInserted(dr, "InvalidProduct");
                        continue; 
                    }



                    if (IsProductExpired())
                    {
                        IndicateNotInserted(dr, "Expired");
                        continue; 
                    }
                    ProcessRow(dr);
  • 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-05-16T06:11:38+00:00Added an answer on May 16, 2026 at 6:11 am

    You could use a chain of responsibility style pattern where a there are a series of classes each one responsible for checking one aspect of validity and reporting the type of error.

    you would pass your Prod to the first class which would check the validity, if it was invalid it would report and return false. if it was valid it would return the validity check of the successor of the current instance (if it had one).

    then your code could just get the Prod and pass it to the root validity checker and continue if it reported false.

    This would also allow you to easily add new validators in the future, potentially being able to do it without having to recompile, depending on how you implemented the construction of the chain of validators.

    something like this: (pseudo code, not tested/compiled)

    public interface IValidator
    {
    bool IsValid(Product product);
    IValidator Successor{get;set;};
    }
    
    public class AbstractValidator : IValidator
    {    
        IValidator m_successor=null;
        public abstract bool IsValid(Product product);
    
        IValidator Successor
        {
        get 
          {
          if(m_sucessor==null)
              return new AlwaysValidSuccessor();
          else
              return m_successor;
          }
        set
           {
           m_successor=value;
           }
        }
    }
    
    public class NullValidator : AbstractValidator
    {
     public bool IsValid(Product product)
     {
        if (product!=null)
            {
            return Successor.IsValid(product);
            }
        return false;
        }
    }
    
    public class ExpiredValidator : AbstractValidator
    {
     public bool IsValid(Product product)
     {
        if (product.Expired==false) //whatever you need to do here
            {
            return Successor.IsValid(product);
            }
        return false;
        }
    }
    

    then you use it:

    IValidator validatorRoot = new NullValidator();
    validatorRoot.Successor = new ExpiredValidator();
    // construct the chain with as many as you need
    //then use it
    if (validatorRoot.IsValid(Prod)==false)
    {
         continue;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 529k
  • Answers 529k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You'll want to look at Data::Lazy and Scalar::Defer. Update: There's… May 16, 2026 at 11:09 pm
  • Editorial Team
    Editorial Team added an answer To get employee names starting with A or B listed… May 16, 2026 at 11:09 pm
  • Editorial Team
    Editorial Team added an answer Unfortunately, it is not specified which function actually calls the… May 16, 2026 at 11:09 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a function in which the processing is given over to a new
I have a query which returns a series of cells of data from a
I have craeted code which reads the acc no, rtn, name and amt from
I have a function which returns a referenced value by default – however, the
I have a pretty standard contact form that uses a cfc for processing now.
I have a python webapp which accepts some data via POST. The method which
I have a page which currently refreshes itself every 10 seconds. The page runs
Often, I will have an array holding a set of values each of which
I have a mysql database table filled with 1000+ records, lets say 5000 records.
I need to write an aggregate extension function (implemented in C) for mySQL 5.x.

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.