none
Get the class and methods name of an abstract sealed class

    Question

  • How do I get the class and methods name of an abstract sealed class? Any help will be greatly appreciated.
    Monday, September 17, 2012 2:21 PM

Answers

  • I disagree. It is possible to make an abstract sealed class in the c++ cli. Example: 

    public ref class MyClass abstract sealed

    {

    ________

    __________

    };

    In most languages, this is what is typically called a "static class".  (For example, in C#, you can't declare "abstract sealed" - the compiler enforces this, but if you declare a class static, you get this in IL.  Same with a VB "Module". )  C++/CLI is the only language where you can declare it like this, and you weren't saying you were using it - hence my comment.  

    It's a class you can't create instances of - and will only contain static members.  

    If you're working in C++/CLI, an "abstract sealed" class will only have static method declarations, and no instance method declarations.  You can still use Type.GetMethods, but you'll want to use BindingFlags.Static to retrieve them.

    You'd get this, in C++/CLI, via:

    // Get the Type handle for your class
    Type^ myType = YourClass::typeid;
    
    // Get the public (static) methods. 
    array<MethodInfo^>^methods = myType->GetMethods( static_cast<BindingFlags>(BindingFlags::Public | BindingFlags::Static) );
    
    for each (MethodInfo^ mi in methods)
        Console::WriteLine(mi->Name);


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Proposed as answer by Mike FengModerator Wednesday, September 19, 2012 10:15 AM
    • Marked as answer by OrionWalli Saturday, September 22, 2012 1:35 PM
    Tuesday, September 18, 2012 3:30 PM
    Moderator

All replies

  • It is impossible to make an "abstract sealed" class.

    Abstract means it must be subclassed, but sealed means it cannot be subclassed.

    You can get the method names of any (valid) type, however, by using Type.GetMethods.  The returned MethodInfo objects each have a Name property, which is the method name.


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Proposed as answer by RohitArora Monday, September 17, 2012 4:30 PM
    Monday, September 17, 2012 4:06 PM
    Moderator
  • I disagree. It is possible to make an abstract sealed class in the c++ cli. Example: 

    public ref class MyClass abstract sealed

    {

    ________

    __________

    };

    Tuesday, September 18, 2012 6:57 AM
  • I disagree. It is possible to make an abstract sealed class in the c++ cli. Example: 

    public ref class MyClass abstract sealed

    {

    ________

    __________

    };

    In most languages, this is what is typically called a "static class".  (For example, in C#, you can't declare "abstract sealed" - the compiler enforces this, but if you declare a class static, you get this in IL.  Same with a VB "Module". )  C++/CLI is the only language where you can declare it like this, and you weren't saying you were using it - hence my comment.  

    It's a class you can't create instances of - and will only contain static members.  

    If you're working in C++/CLI, an "abstract sealed" class will only have static method declarations, and no instance method declarations.  You can still use Type.GetMethods, but you'll want to use BindingFlags.Static to retrieve them.

    You'd get this, in C++/CLI, via:

    // Get the Type handle for your class
    Type^ myType = YourClass::typeid;
    
    // Get the public (static) methods. 
    array<MethodInfo^>^methods = myType->GetMethods( static_cast<BindingFlags>(BindingFlags::Public | BindingFlags::Static) );
    
    for each (MethodInfo^ mi in methods)
        Console::WriteLine(mi->Name);


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Proposed as answer by Mike FengModerator Wednesday, September 19, 2012 10:15 AM
    • Marked as answer by OrionWalli Saturday, September 22, 2012 1:35 PM
    Tuesday, September 18, 2012 3:30 PM
    Moderator