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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:49:04+00:00 2026-05-11T18:49:04+00:00

Imagine an application based on options. I want to add an exclamation mark to

  • 0

Imagine an application based on options.

I want to add an exclamation mark to the end of every string (itself, an extremely easy task). However, I have an option in web.config or an XML file, so if the option is true, the exclamation is appended, otherwise it isn’t.

I know how to check web.config or an xml file for the setting’s value, however, what is the best way to do this? In the case of a string, it will be heavily used in any program.

I could write:

if (ExclamationIsSet)
{
// Append here
}

// Otherwise it isn't set, so don't.

However, this isn’t practical for a large (or even small) codebase. Is there a way to get rid of this manual checking? I’ve heard AOP or attributes may be able to solve this, but I haven’t seen an example.

What methods could solve this problem?

  • 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-11T18:49:04+00:00Added an answer on May 11, 2026 at 6:49 pm

    The operation can be described as:

    public interface ITextDecorator
    {
        string GetString(string input);
    }
    

    This encapsulates the how (Web.config, XML, etc.) and emphasizes the what (decorating a string).

    Then, any class which might need to decorate text can take an instance of that interface:

    public class Foo
    {
        private ITextDecorator _textDecorator;
    
        public Foo(ITextDecorator textDecorator)
        {
            _textDecorator = textDecorator;
        }
    
        public void Bar(string text)
        {
            text = _textDecorator.GetString(text);
    
            // ...
        }
    }
    

    Example implementations of ITextDecorator might be:

    public sealed class ExclamationPointTextDecorator : ITextDecorator
    {
        public string GetString(string input)
        {
            return input + "!";
        }
    }
    
    public sealed class ConditionalTextDecorator : ITextDecorator
    {
        private Func<bool> _condition;
        private ITextDecorator _innerTextDecorator;
    
        public ConditionalTextDecorator(Func<bool> condition, ITextDecorator innerTextDecorator)
        {
            _condition = condition;
            _innerTextDecorator = innerTextDecorator;
        }
    
        public string GetString(string input)
        {
            return _condition() ? _innerTextDecorator.GetString(input) : input;
        }
    }
    

    An example usage of these classes might be:

    var textDecorator = new ConditionalTextDecorator(
        () => true,  // Check Web.config, an XML file, or any other condition
        new ExclamationPointTextDecorator());
    
    var foo = new Foo(textDecorator);
    
    foo.Bar("Test");
    

    Notice the decoupling of the exclamation point appending from its conditional invocation. Both classes can now be reused independent of the other. This design style of fine-grained objects works best with an Inversion of Control (IoC) container. However, it is not required.

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

Sidebar

Related Questions

Imagine a web-application storing some data-resource with some id which stores three attachment (e.g.
Imagine an in-house application aimed at the very technical user. The app maintains data.
Imagine a pure .NET application which do not uses COM components nor PInvoke. Does
Imagine the typical type of application where you have a list of items with
Imagine that your web application maintains a hit counter for one or multiple pages
Imagine a more complex CRUD application which has a three-tier-architecture and communicates over webservices.
Imagine 2 modules for an application. One is called core and acts like an
imagine a situation where you have an application that needs to import data from
imagine the following environment: an XBAP application running in partial trust mode (default behaviour;
Imagine some kind of a banking application, with a screen to create accounts. Each

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.