using System; using System.Collections; namespace jive { public static class ConversionExtensions { public static T downcast_to(this object object_to_cast) { return (T) object_to_cast; } public static T converted_to(this object item_to_convert) { if (item_to_convert.is_an_implementation_of()) return (T) Convert.ChangeType(item_to_convert, typeof (T)); return item_to_convert.downcast_to(); } public static bool is_an_implementation_of(this object item) { return item is T; } public static void call_on(this object target, Action action) where T : class { if (target as T != null) action(target as T); } public static void call_on_each(this IEnumerable items, Action action) where T : class { foreach (var item in items) item.call_on(action); } } }