main
1using System;
2using System.Collections;
3
4namespace jive
5{
6 public static class ConversionExtensions
7 {
8 public static T downcast_to<T>(this object object_to_cast)
9 {
10 return (T) object_to_cast;
11 }
12
13 public static T converted_to<T>(this object item_to_convert)
14 {
15 if (item_to_convert.is_an_implementation_of<IConvertible>())
16 return (T) Convert.ChangeType(item_to_convert, typeof (T));
17 return item_to_convert.downcast_to<T>();
18 }
19
20 public static bool is_an_implementation_of<T>(this object item)
21 {
22 return item is T;
23 }
24
25 public static void call_on<T>(this object target, Action<T> action) where T : class
26 {
27 if (target as T != null) action(target as T);
28 }
29
30 public static void call_on_each<T>(this IEnumerable items, Action<T> action) where T : class
31 {
32 foreach (var item in items) item.call_on(action);
33 }
34 }
35}