Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4021182
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:19:12+00:00 2026-05-20T10:19:12+00:00

Is there a way to check if my element with elementtype class has a

  • 0

Is there a way to check if my element with elementtype class has a certain other class in his inheritance hierarchy?

My usecase is: I have to check if my Exceptions are prefixed with “Exception”. To do so, i have to somehow determine if a certain class is an exception. The only way i can be sure is if it is inherited by the Exception class itself.

Checking the baseclass type for being an exception is easy enough, but imagine the following scenario:

class GenericMathException : Exception{}
class SpecificMathException : GenericMathException{}

The only information i can get about the SpecificMathException is that it’s baseclass type is GenericMathException, but i can’t go any further up in it’s inheritance hierarchy.

The usual approach of reflection can’t be used too, afaik.

So, anyone ever had to deal with this problem and found a solution? Or has any alternative approach to identify Exceptions?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:19:13+00:00Added an answer on May 20, 2026 at 10:19 am

    By its nature, StyleCop indeed works only with the contents of the file and can not use information from the assembly itself.

    But, if you ask about “alternative approach to identify Exceptions”, there is a rule in StyleCop+ which performs a checking very close to yours. You specify a list of base classes (Attribute, Exception, EventArgs and Stream by default), and it ensures that all classes inherited from them have the name that ends with ...Attribute, ...Exception and so on.

    The checking works in the following way. If the name of the base class ends with a string from the list, it ensures that the name of the inherited class should also end with the same string. E.g., if it meets Class2 : InvalidOperationException or Class2 : SomeUnknownException, it will raise a violation in both cases.

    Assuming that you follow this rule, all your inherited classes will always be named well, even if they are multi-inherited. The only thing that can not be checked in this way, is the situation where you deal with some classes not from “yours” assembly, that already have broken this rule. E.g., if some assembly has Class2 : Exception, and you reference this assembly as a binary (and do not have a chance to check it with StyleCop) then you will not be able to check if your Class3 inherited from Class2 should be prefixed with ...Exception.

    But practice shows that the last issue is rather rare, so the method described above works really well for StyleCop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With: if(element.hasClass(class)) I can check for one class, but is there an easy way
Is there a way to check if a file has been opened by ReWrite
Is there a way to check if a ValidationSummary control has its IsValid property
Jquery newbie here. In a wrapped element set, is there a way to check
I have a div: <div class=test id=someElement style=position: absolute></div> Is there any way to
Is there any way to check if a array exists or has a value
Is there any way to check whether a file is locked without using a
Is there a way to check to see if a date/time is valid you
Is there any way to check if a given index of an array exists?
Is there a way to check how much a flash file is (down)loaded to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.