简体   繁体   中英

Find the items matching any condition from the generic list

I have collection of patient in a lists named lst_Patient.

And this is method where i get the info from user:

 public  Patient[] GetPatientsBySearchParams(DataPair[] dataPair)
        {
    //return the array patients that match any of the criteria
//Right Now I ma doing this didn't get any success :

 List<Patient> P = new List<Patient>();

            P = lst_Patient.FindAll(p => { p.FirstName = dataPair[0].OutputValue.ToString();
                                         p.LastName = dataPair[1].OutputValue.ToString();
                                         return true;
return P.ToArray();

        }

On a button click i take the info entered in the textbox by the user:

 private DataPair[] dpair;
 private void Button_Click(object sender, RoutedEventArgs e)
        {
            InvalidSearch.Visibility = Visibility.Collapsed;
            SearchResults.Visibility = Visibility.Visible;

            dpair = new DataPair[]{
                            new DataPair { Name = "FirstName", OutputValue = fst_Name.Text },
                            new DataPair { Name = "LastName", OutputValue = lst_Name.Text },
                            new DataPair { Name = "DateOfBirth", OutputValue = dob.Text },
                            new DataPair { Name = "SSN", OutputValue = ssn.Text },
                            new DataPair { Name = "PracticeNumber", OutputValue = pract_nbr.Text },
                            new DataPair { Name = "ReferenceNumber", OutputValue = ref_nbr.Text },
                            new DataPair { Name = "PlaceOfService", OutputValue = pos.Text },
                            new DataPair { Name = "DateOfService",  OutputValue = dos.Text},
                            new DataPair { Name = "RenderingProvider",  OutputValue = rndrng_prov.Text },
                            new DataPair { Name = "AdmissionDate",  OutputValue = admsn_date.Text }
                       };

            this.FetchData();
        }


        private void FetchData()
        {

            Patient[] p =    client.GetPatientsBySearchParams(dpair);

        }
public  Patient[] GetPatientsBySearchParams(DataPair[] dataPair)
{      
  P = lst_Patient.FindAll(
 delegate(Patient tmp){ 
  if(tmp.FirstName = dataPair[0].OutputValue || tmp.LastName = dataPair[1].OutputValue) 
   return true;
  else 
   return false;
 }
);

return P.ToArray();
}

您应该使用反射来调用传递名称的属性。

p.GetType().GetProperty(dataPair[i].Name).GetValue(p) == dataPair[i].OutputValue;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM