I donβt know much about .NET 4.0 (now I use 3.5), but I think there is no way to achieve the effect of Pure.Krome.
But an approximation to such a comparison can be achieved using arrays and extension methods that LINQ provides.
Here is a small example.
string foo = @"very weird"; if (new[] { @"don't do it", @"very weird" }.Contains(foo)) { Console.WriteLine(@"bingo string"); } int baa = 7; if (new []{5, 7}.Contains(baa)) { Console.WriteLine(@"bingo int"); }
It is output:
bingo string bingo int
Thus, more resources are consumed than a simple chain of companions and logical operators, but provides a syntax similar to the one Pure.Krome that it wants to receive.
If you do not want to define arrays with a new [] (this is really curious, but in logical conditions), you can define your extension method for this.
public static class Extensions { public static bool IsOneOf<T>(this T obj, params T[] args) { return args.Contains(obj); } }
So you can use this extension method:
if (baa.IsOneOf(5, 7, 9, 10)) { Console.WriteLine(@"bingo int"); }
The conclusion is really predictable, heh.
Eskat0n
source share