I am trying to implement a search routine for an application written in C#. The requirements are as follows:
The user can select one of the following options for search:
Property Search(Exact)
: the text entered in the search box has to match exactly with the results, e.g. searching forPL
should only show the results whose properties containPL
.Property Search(Contains)
: the text entered in the search box can be part of the results, e.g. searching forPL
should show all the results whose properties containPL
, e.g. PLApp, Planning, playing, etc.
I have implemented it in my code by passing a boolean
flag to my method, and using if..else
to perform the searches accordingly.
public override bool PropertySearch(string value, bool searchPartial = false)
{
if(searchPartial)
{
if (dataValue.IndexOf(value, StringComparison.OrdinalIgnoreCase) >= 0)
return true;
} else
{
if (dataValue.Equals(value, StringComparison.OrdinalIgnoreCase))
return true;
}
return false;
}
This was my first implementation, and I have a feeling there might be a better and concise way to achieve this. Any thoughts?
PL
- maybe we need a specificationreview.stackexchange.com. \$\endgroup\$Exact
should return all results containing exact search text,Partial
should return all results containing search text. SoPartial
is a super set ofExact
. Hope that helps. \$\endgroup\$Exact
(searchPartial = false
) should returntrue
where, ignoring case,dataValue
equalsvalue
. \$\endgroup\$searchPartial
flag. \$\endgroup\$