Link to home
Start Free TrialLog in
Avatar of kruegerste
kruegersteFlag for United States of America

asked on

C# Generic Method Parameter

Hello,

Is there a way to make the method below generic?  

CustomerData is a strongly-typed dataset.  I would like to be able to somehow pass a generic strongly-typed dataset in as a parameter or however this can be done so that we only use one method for all instances.  Otherwise we will need to duplicate this method about 10 times with different dataset types.

We would also pass in the table name as string for the dataset.

Thanks.
public string[] GetCustomerSuggestionList(string columnName, string prefix, int count)
        {
 		CustomerData customerData = new CustomerData();
                customerData = GetCustomersAll();

              	EnumerableRowCollection<DataRow> query = from customer in customerData.Tables["customer"].AsEnumerable()
                        where customer.Field<string>(columnName) != null && customer.Field<string>(columnName).ToLower().StartsWith(prefix.ToLower())
                        select customer;
                     
 		UtilityBF utilityBF = new UtilityBF();
                return utilityBF.GetDistinctQueryItems(query, columnName, count);
        }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Inferred usage:
public void SomeSub()
{
    CustomerData customerData = GetCustomersAll();

    string[] result = GetCustomerSuggestionList<CustomerData>(customerData, "customer", "address", "something", 4);
}

Open in new window

Avatar of kruegerste

ASKER

Thanks.  I was missing the where statement.
NP. Glad to help  :)