tags:

views:

42

answers:

2

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

        }
A: 
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();
}
Arseny
Malcolm
@Malcolm fixed. instead of anonimous method you can use lambda or difine static function whatever.
Arseny
A: 

You should use reflection to call the property whose name gets passed.

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