DataGrids void Main() { foreach (var context in new RuleContext[] { new Foo(), new Bar(), new Baz() }) { string call; if (context.TryCall(out call)) { Console.WriteLine(call); } } } static class RuleContextExtensions { public static bool TryCall(this RuleContext context, out string call) { var foo = context as Foo; if (foo != null) { call = foo.Call(); return true; } var baz = context as Baz; if (baz != null) { call = baz.Call(); return true; } call = null; return false; } } class RuleContext { } class Foo : RuleContext { public string Call() { return "Foo"; } } class Bar : RuleContext { } class Baz : RuleContext { public string Call() { return "Baz"; } }