How to get all child class or classes that implements an abstract class?

pradipkkoli
pradipkkoli used Ask the Experts™
on
Hi,
    I am using C# 2.0, and required to build the parent-child class Hierarchy diagram. So the visual part is almost done i required how to find all child class from parent class. I am using Visual Studio 2005 and dotnet framework 2.0.


Thanks and
Warm Regards
Pradip
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
I have a VB.Net sample that you could either convert to C# or use directly in a VB.NET 'project that documents your C# assembly.The approach uses reflection to examine the classes.

Include these routines in a project that references the assemblies that contain your parent and child classes.  

Replace <Your Parent Class Name> with the appropriate type name.  

Execute ListClassesInLoadedAssemblies to list the sub classes

You will need to Import System.Reflection

    Public Sub ListClassesInLoadedAssemblies

        For Each ass As Assembly In My.Application.Info.LoadedAssemblies
                ListClassesInAssembly

        Next

    End Sub

    Protected Sub AddProcessesFromAssembly(ByVal ass As Assembly)

        Try

            For Each t As System.Type In ass.GetTypes
                if t.IsSubClassOf (GetType (<your parent class name> ) Then
                    Debug.print t.FullName
                End if
            Next

    End Sub
Sorry,  some typos in the previous - use these instead

    Public Sub ListClassesInLoadedAssemblies
        For Each ass As System.Reflection.Assembly In My.Application.Info.LoadedAssemblies
                ListClassesInAssembly
        Next
    End Sub


    Public Sub ListClassesInAssembly(ByVal ass As System.Reflection.Assembly)
            For Each t As System.Type In ass.GetTypes
                if t.IsSubClassOf (GetType (<your parent class name> ) Then
                    Debug.print t.FullName
                End if
            Next
    End Sub

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial