示例#1
0
        static void Main(string[] args)
        {
            Type     rootType     = typeof(DependencyObject);
            TypeInfo rootTypeInfo = rootType.GetTypeInfo();

            foreach (Type type in rootType.Assembly.ExportedTypes)
            {
                TypeInfo typeInfo = type.GetTypeInfo();

                if (typeInfo.IsPublic && rootTypeInfo.IsAssignableFrom(typeInfo))
                {
                    descendants.Add(type);
                }
            }

            descendants.Sort((t1, t2) =>
            {
                return(String.Compare(t1.GetTypeInfo().Name, t2.GetTypeInfo().Name));
            });

            ClassDerivatives toplevel = new ClassDerivatives(rootType);

            AddDerivatives(toplevel);

            PrintDerivaties(toplevel);

            Console.WriteLine("Press a key to continue: ");
            Console.ReadLine();
        }
示例#2
0
        static void PrintDerivaties(ClassDerivatives level, int indent = 0)
        {
            TypeInfo typeInfo = level.Type.GetTypeInfo();

            Console.Write(new String(' ', indent * 2));
            Console.WriteLine(typeInfo.Name);

            foreach (ClassDerivatives sublevel in level.Derivatives)
            {
                PrintDerivaties(sublevel, indent + 1);
            }
        }
示例#3
0
        static void AddDerivatives(ClassDerivatives level)
        {
            foreach (Type type in descendants)
            {
                Type baseType = type.GetTypeInfo().BaseType;

                if (baseType == level.Type)
                {
                    ClassDerivatives sublevel = new ClassDerivatives(type);
                    level.Derivatives.Add(sublevel);
                    AddDerivatives(sublevel);
                }
            }
        }