Results 1 to 6 of 6

Thread: [RESOLVED] how to find derived class name

  1. #1

    Thread Starter
    Fanatic Member ZeBula8's Avatar
    Join Date
    Oct 2002
    Posts
    548

    Resolved [RESOLVED] how to find derived class name

    say i have a class 'MainClass'

    now i have another class, 'Class1' and I inherit from 'MainClass' in this class.

    for example:
    public class Class1
    inherits MainClass
    end class


    Is there a way that i can get the name of this class 'MainClass' that I've inherited from in 'Class1' ? i want to know if it is 'MainClass' that this class is inheriting from.

    Basically, i want to be able to find out what the base classes are that my class inherits from.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: how to find derived class name

    You should be able to adapt this to do what you need:
    vb.net Code:
    1. Private Sub ListInheritenceChain(ByVal obj As Object)
    2.     Dim t As Type = obj.GetType()
    3.  
    4.     Do
    5.         MessageBox.Show(t.Name)
    6.  
    7.         If t Is GetType(Object) Then
    8.             Exit Do
    9.         Else
    10.             t = t.BaseType
    11.         End If
    12.     Loop
    13. End Sub
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Addicted Member iehjsucker's Avatar
    Join Date
    Sep 2005
    Posts
    150

    Re: how to find derived class name

    thanks. but what i am doing is getting class names from an external application. E.g, when I click the first button, all windows in my desktop will be listed. And if I select 1 from the list, say for example, I selected NOTEPAD and clicked the next button, then all the class names from notepad should be listed from the next listbox. I think the one you gave me will only work for the application alone





    =============
    ..code masters..

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: how to find derived class name

    Quote Originally Posted by iehjsucker
    thanks. but what i am doing is getting class names from an external application. E.g, when I click the first button, all windows in my desktop will be listed. And if I select 1 from the list, say for example, I selected NOTEPAD and clicked the next button, then all the class names from notepad should be listed from the next listbox. I think the one you gave me will only work for the application alone
    Are you the same person with two accounts?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    Addicted Member iehjsucker's Avatar
    Join Date
    Sep 2005
    Posts
    150

    Re: how to find derived class name

    nope I am not. why?

    oh my.. i posted at the wrong place





    =============
    ..code masters..

  6. #6

    Thread Starter
    Fanatic Member ZeBula8's Avatar
    Join Date
    Oct 2002
    Posts
    548

    Re: [RESOLVED] how to find derived class name

    thanks very much, jmcilhinney,

    that works for me.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width