main
 1using System;
 2using System.Collections;
 3
 4namespace gorilla.commons.utility
 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            {
17                return (T) Convert.ChangeType(item_to_convert, typeof (T));
18            }
19            return item_to_convert.downcast_to<T>();
20        }
21
22        public static bool is_an_implementation_of<T>(this object item)
23        {
24            return item is T;
25        }
26
27        public static void call_on<T>(this object target, Action<T> action) where T : class
28        {
29            if (target as T != null) action(target as T);
30        }
31
32        public static void call_on_each<T>(this IEnumerable items, Action<T> action) where T : class
33        {
34            foreach (var item in items) item.call_on(action);
35        }
36    }
37}