-
Notifications
You must be signed in to change notification settings - Fork 0
Object extension methods
Alex Kamsteeg edited this page Aug 8, 2015
·
2 revisions
SwissArmyKnife adds the following extension methods to object:
The IsAnyOf() extension method makes comparing objects to multiple values a lot easier and readable. Without this you have to write a lot more code, for example:
var example = 1;
if (example == 1 || example == 2 || example == 3)
{
// do something
}With IsAnyOf() you can just do the following:
var example = 1;
if (example.IsAnyOf(1, 2, 3))
{
// do something
}It works for any object type:
var example = "lorem";
if (example.IsAnyOf("lorem", "ipsum", "dolor"))
{
// do something
}And also on enums:
public enum State
{
Open,
Closed,
Faulted
}
var example = State.Open;
if (example.IsAnyOf(State.Closed, State.Faulted))
{
// PANIC!
}