Esempio n. 1
0
        /// <summary>
        /// Extension method for getting interfaces
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="component"></param>
        /// <returns></returns>
        public static T[] GetInterfaces <T>(this Component component) where T : class
        {
            //DOES NOT WORK !!!!  Component[] components = component.GetComponents(typeof(T)) as T[];
            Component[] components = component.GetComponents(typeof(T));// as T[];
            if (components != null)
            {
                T[] result = new T[components.Length];
                for (int i = 0; i < components.Length; ++i)
                {
                    result[i] = components[i] as T;
                }

                return(result);
            }
            else
            {
                return(null);
            }
        }
 public static object[] GetInterfaces(this Component component, Type interfaceType)
 {
     return(GetInterfaces(component.GetComponents(typeof(Component)), interfaceType));
 }
 public static InterfaceType[] GetInterfaces <InterfaceType>(this Component component) where InterfaceType : class
 {
     return(GetInterfaces <InterfaceType>(component.GetComponents <Component>()));
 }