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 6155899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:31:00+00:00 2026-05-23T20:31:00+00:00

What I want to do may seem like a weird scenario. Please keep in

  • 0

What I want to do may seem like a weird scenario. Please keep in mind that I need to do this for a Demo project, where I output c# code to the user to teach them how certain controls are coded.

I am given a .cs file and I need to output the contents. There is at least one class in the file, and at most…a lot. I need to output the whole file, EXCEPT one type of class. The specific type of class that I want to prevent being outputted all inherit a certain base class, so they should be easy to distinguish.

Here is an example:

    public abstract class A{}

    public class B{]

    public class C{}

Assume these are the base-types that some of my classes may inherit. I want to prevent outputting all classes that inherit from A. A is probably going to be the only abstract base class so if that can help in anyway, that would be awesome.

Let’s say I’m given a file, example.cs:

    using System;
    using OtherStuff;

    namespace blah.blahagain.someotherblah
    {
      [AttributeOne]
      [AttributeTwo]
      [AttributeThree]
      public class AA: A
      {
        //stuff
      }

      public class BB: B
      {
        //stuff
      }

      public class CC: C
      {
        //stuff
      }

      public class D
      {
        //stuff
      }

    }

And the output should be

    using System;
    using OtherStuff;

    namespace blah.blahagain.someotherblah
    {
      public class BB: B
      {
        //stuff
      }

      public class CC: C
      {
        //stuff
      }

      public class D
      {
        //stuff
      }

    }

The only way I have thought of is brute-force string manipulation. I can’t, however, use whitespace as a separator between classes because there is no guarantee if there will even be white space between classes. I will need to keep track of open and closed curly brackets to discover where one class begins and another end. I also need to test for the base class of each class by testing the string tokens before the first {} pair.

Also I need to prevent the attributes of AA from outputted too.

Since there are many brighter minds out there, I am here to ask if there is another simpler/cleaner method for doing what I need.

Thanks for reading!

Edit after YetAnotherUser’s answer: The output should be exactly the same as the file, which includes all comments.

Another edit: Instead of answering with certain software or libraries that could do this, I would more prefer algorithms. Maybe regular expressions? I am not good with them so I do not know the extend that they can be used for.

  • 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-23T20:31:01+00:00Added an answer on May 23, 2026 at 8:31 pm

    Could you wrap everything you need to exclude with:

    #region ExcludeRegion
      [AttributeOne]
      [AttributeTwo]
      [AttributeThree]
      public class AA: A
      {
        //stuff
      }
    #endregion
    

    See the #region documentation

    This should be relatively easy to scan for and exclude. It also gives you the added benefit of showing what you’re hiding in the IDE.

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

Sidebar

Related Questions

Now, this requirement may seem weird. But i would like to know how to
this may seem like a very simple question, but I want to dump some
This may seem like an odd one, but I want to be able to
This may seem like a basic/stupid/obviously-answered question, but I wanted to check: why use
This may seem a little upside down faced, but what I want to be
This may seem a bit odd, but I really need to create a workaround
This may seem obvious to most people, but I'm just trying to confirm that
This may seem like an obvious thing, but I can't find it. When using
This may seem like a dumb idea, but is there anyway to serve a
This may seem like a silly question, but what are the functional differences, if

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.