You can write an extension. I wrote one time ago, for making code like
if(someObject.stringPropertyX.Equals("abc") || someObject.stringPropertyX.Equals("def") || ....){
//do something
...
}else{
//do something other...
....
}
more readable with an extention s.t. one was able to write
if(someObject.stringPropertyX.In("abc", "def",...,"xyz"){
//do something
...
}else{
//do something other...
....
}
Here's the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Some.Namespace.Extenders
{
public static class StringExtender
{
/// <summary>
/// Evaluates whether the String is contained in AT LEAST one of the passed values (i.e. similar to the "in" SQL clause)
/// </summary>
/// <param name="thisString"></param>
/// <param name="values">list of strings used for comparison</param>
/// <returns><c>true</c> if the string is contained in AT LEAST one of the passed values</returns>
public static bool In(this String thisString, params string[] values)
{
foreach (string val in values)
{
if (thisString.Equals(val, StringComparison.InvariantCultureIgnoreCase))
return true;
}
return false; //no occurence found
}
}
}
This is the one specific to my needs at that time, but you may adapt and modify it to match more different types.