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

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

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

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
Random Solutions  
 
programming4us programming4us