Ejemplo n.º 1
0
        ///Return an object drawer instance of target inspected type
        public static IObjectDrawer GetObjectDrawer(Type objectType)
        {
            IObjectDrawer result = null;

            if (objectDrawers.TryGetValue(objectType, out result))
            {
                return(result);
            }

            // look for specific drawer first
            Type fallbackDrawerType = null;

            foreach (var drawerType in ReflectionTools.GetImplementationsOf(typeof(IObjectDrawer)))
            {
                if (drawerType != typeof(DefaultObjectDrawer))
                {
                    var args = drawerType.BaseType.RTGetGenericArguments();
                    if (args.Length == 1)
                    {
                        if (args[0].IsEquivalentTo(objectType))
                        {
                            return(objectDrawers[objectType] = Activator.CreateInstance(drawerType) as IObjectDrawer);
                        }
                        if (args[0].IsAssignableFrom(objectType))
                        {
                            fallbackDrawerType = drawerType;
                        }
                    }
                }
            }

            if (fallbackDrawerType != null)
            {
                return(objectDrawers[objectType] = Activator.CreateInstance(fallbackDrawerType) as IObjectDrawer);
            }


            // foreach ( var drawerType in ReflectionTools.GetImplementationsOf(typeof(IObjectDrawer)) ) {
            //     if ( drawerType != typeof(DefaultObjectDrawer) ) {
            //         var args = drawerType.BaseType.RTGetGenericArguments();
            //         if ( args.Length == 1 && args[0].IsAssignableFrom(objectType) ) {
            //             return objectDrawers[objectType] = Activator.CreateInstance(drawerType) as IObjectDrawer;
            //         }
            //     }
            // }

            return(objectDrawers[objectType] = new DefaultObjectDrawer(objectType));
        }
Ejemplo n.º 2
0
        ///Return an object drawer instance of target inspected type
        public static IObjectDrawer GetObjectDrawer(Type objectType)
        {
            IObjectDrawer result = null;

            if (objectDrawers.TryGetValue(objectType, out result))
            {
                return(result);
            }

            foreach (var drawerType in ReflectionTools.GetImplementationsOf(typeof(IObjectDrawer)))
            {
                if (drawerType != typeof(DefaultObjectDrawer))
                {
                    var args = drawerType.BaseType.GetGenericArguments();
                    if (args.Length == 1 && args[0].IsAssignableFrom(objectType))
                    {
                        return(objectDrawers[objectType] = Activator.CreateInstance(drawerType) as IObjectDrawer);
                    }
                }
            }

            return(objectDrawers[objectType] = new DefaultObjectDrawer(objectType));
        }