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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:01:13+00:00 2026-06-09T16:01:13+00:00

I want to write a static utility class which only has a set of

  • 0

I want to write a static utility class which only has a set of properties, which expose functionality to the user

For example I could call:

Utils.String.GetHexString("Hello World");

or

Utils.Stream.CopyBytes(instream, outstream);

The closest thing I could liken this to is System.Text.Encoding where there are properties like UTF8, ASCII etc, so yo can call things like:

Encoding.UTF8.GetBytes("Hello World");

or

Encoding.ASCII.GetBytes("Hello World");

The problem is that in Encoding, this calls the equivalent objects (UTF8Encoder, ASCIIEncoder) which are publicly available to the user. What I want is to expose the objects ONLY via Utils, without visibilty of the objects that relate to the properties, for example

I could call:

Utils.Stream.CopyStream(instream, outstream);

but I could not call:

StreamUtils.CopyStream(instr, outstr) //This class is only accessible via the Utils class!

Is this possible, and if it is, is it going to be good or bad practice to do so?

  • 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-06-09T16:01:14+00:00Added an answer on June 9, 2026 at 4:01 pm

    Ok, basically it’s no possible (in C# at least) to achieve exactly what I want. The class must be visible for the functionality to be visible through the Util class.

    My solution was to turn the classes (e.g. StreamUtils, StringUtils) into singletons. They cannot be constructed because their constructors are internal. their methods are public but can never be seen because the object cannot be instantiated outside of my assembly. The Utils class exposes the functionality to the user via the singleton instance.

    Consider the following:

    class StreamUtils
    {
        static StreamUtils instance;
    
        internal static StreamUtils Instance
        {
            get
            {
                if(instance == null)
                {
                    instance = new StreamUtils();
                }
                return instance;
            }
        }
    
        internal StreamUtils()
        {
        }
    
        public void CopyStream(Stream input, Stream output)
        {
        }
    }
    
    static class Utils
    {
        public StreamUtils Stream
        {
            get
            {
                 return StreamUtils.Instance;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write an user defined error collection class which should collect all
I want to write a static helper class in coffeescript. Is this possible? class:
I want to write a utility in my program which can convert a string
I want write a simple query which will fetch data from a table (which
I want write a little code analyzer which parses nested structures and translates into
I want to write a batch script statement where: FINDSTR has to check for
I want to write <a href=product.php?id=5> as product/5.I am not talking about user to
I want to write a class with three int values in them and manipulate
I want to write a Static Text with an upside down ^ How can
Here's the method i want to write: public static IEnumerable<String> GetTableNames(this IQueryable<T> query) {

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.