I have this code:
if (((Classes.ProductGroup)o).ToString().Contains(comboBox.Text))
return true;
else
return false;
Now I want not to specify the part Classes.ProductGroup. I want to make it universal.
How can I replace the part Classes.ProductGroup with a Type object?
Type type = typeof(Classes.ProductGroup);
Something similar to this:
if (((type)o).ToString().Contains(comboBox.Text))
Is this possible?
Here is the complete method code:
private void FilterPGsinComboBox(object obj)
{
if (!Dispatcher.CheckAccess())
{
Dispatcher.Invoke(new FilterPGsinComboBoxDelegate(this.FilterPGsinComboBox),obj);
return;
}
Type type = ((Dictionary<ComboBox, Type>)obj).First().Value;
ComboBox comboBox = ((Dictionary<ComboBox, Type>)obj).First().Key;
comboBox.IsDropDownOpen = true;
CollectionView itemsViewOriginal = (CollectionView)CollectionViewSource.GetDefaultView(comboBox.ItemsSource);
itemsViewOriginal.Filter = ((o) =>
{
if (String.IsNullOrEmpty(comboBox.Text))
return true;
else
{
if (((Classes.ProductGroup)o).ToString().Contains(comboBox.Text))
return true;
else
return false;
}
});
itemsViewOriginal.Refresh();
}
ToString(). cast is redundantoand please provide what function you want to achieve