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

  • SEARCH
  • Home
  • 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 7012517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:15:58+00:00 2026-05-27T22:15:58+00:00

I know there are tools to count the number of classes i use in

  • 0

I know there are tools to count the number of classes i use in my code base, and this is a reasonable software engineering metric (e.g. average lines of code per class).

However i was idly wondering whether there are any tools to count the number of anonymous classes in the code base?

If so would this make an interesting software quality metric? e.g. i would probably be worried if i had more anonymous classes than normal classes though I’m not sure if i should be.

  • 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-27T22:15:58+00:00Added an answer on May 27, 2026 at 10:15 pm

    I don’t think the number of anonymous types is a useful metric, whether by itself or when compared with the number of named types. I also don’t know about any tools that measure this (that doesn’t mean they don’t exist, though).

    To find out the number of anonymous types in a compiled assembly, you could use these facts about compiled anonymous types:

    1. They have the [CompilerGenerated] attribute
    2. Their name starts with <>f__AnonymousType (an unspeakable name in C#)
    3. They have the [DebuggerDisplay] attribute with Type="<Anonymous Type>"

    #1 by itself is not enough to identify an anonymous type. And I think you can’t rely on #2 or #3, since MS can decide to change them at any time and other compilers, like Mono C#, can use another style. But I think it’s the best you can do. Using #1 and #2, you could write a method that does what you want like this:

    private static int ComputeNumberOfAnonymousTypes(Assembly assembly)
    {
        return (from type in assembly.GetTypes()
                where Attribute.IsDefined(type, typeof(CompilerGeneratedAttribute))
                        && type.Name.StartsWith("<>f__AnonymousType")
                select type)
            .Count();
    }
    

    If you wanted to find out the number of anonymous files in a bunch of source code files, you would need C# parser. If you are willing to use pre-release software, I think this would be a good job for Roslyn, except it doesn’t support anonymous types yet.

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

Sidebar

Related Questions

I know that there are a number of tools for analysing .NET code and
I know there are quite a few line count tools around. Is there something
I know there are tools available to rectify this, but somehow i cannot make
There are plenty of script/tools for counting line of code, and some to count
I know there are tools out there that will let you see the content
I know there are lots of tools on the net that can make our
I would like to know if there are any tools to automatically generate EJB3
I'd like to know if there are effective and open source tools to develop
I know that in GWT the java reflection tools isn't emulated, but is there
I know there are tools to migrate VS 2008 application to VS 2010. But

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.