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 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

Related Questions

I have a Processing code which displays words from a text file. I have
I have a function which looks something like this, it returns a noncopyable class
I have a function which I have to loop it a few times but
I have a delete button which I use to delete table rows: //Dialog function
I have a big pixel processing function which I am currently trying to optimize
I have a function which sends specified form data to a php processing page.
i have a function which retrieves values from a webservice , then loops through
I have a function in which the processing is given over to a new
I have a jQuery XML file parser that I got from somewhere which reads
I have a function which is merging certain files from a directory def merge(path):

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.