Table of Contents

Class CharDecoratorExtensions

Namespace
Cuemon
Assembly
Cuemon.Core.dll

Extension methods for the char struct hidden behind the IDecorator<T> interface.

public static class CharDecoratorExtensions
Inheritance
CharDecoratorExtensions

Examples

CharDecoratorExtensions provides extension methods on Decorator.Enclose for converting between IEnumerable<char> sequences and string collections. This example wraps the characters of "Hello" and calls ToEnumerable to split them into single-character strings, then ToStringEquivalent to rejoin them back into the original string. It also demonstrates the same round-trip with a char[] array of 'A', 'B', 'C'. Console output confirms the split produces "H, e, l, l, o" and the rejoined result matches "Hello" and "ABC".

using System;
using System.Collections.Generic;
using System.Linq;
using Cuemon;

namespace MyApp
{
    public class CharDecoratorExtensionsExample
    {
        public void Demonstrate()
        {
            // Convert a sequence of characters to a sequence of single-character strings
            IEnumerable<char> characters = "Hello".AsEnumerable();

            IEnumerable<string> strings = Decorator.Enclose(characters).ToEnumerable();
            Console.WriteLine(string.Join(", ", strings)); // "H, e, l, l, o"

            // Convert a sequence of characters back to a single string
            string result = Decorator.Enclose(characters).ToStringEquivalent();
            Console.WriteLine(result); // "Hello"

            // Works with any IEnumerable<char> including char arrays
            char[] charArray = { 'A', 'B', 'C' };
            string joined = Decorator.Enclose(charArray.AsEnumerable()).ToStringEquivalent();
            Console.WriteLine(joined); // "ABC"

}}
}

Methods

ToEnumerable(IDecorator<IEnumerable<char>>)

Converts the enclosed IEnumerable{char} of the decorator to its equivalent IEnumerable{string}.

public static IEnumerable<string> ToEnumerable(this IDecorator<IEnumerable<char>> decorator)

Parameters

decorator IDecorator<IEnumerable<char>>

The IDecorator<T> to extend.

Returns

IEnumerable<string>

An IEnumerable{string} equivalent to the enclosed IEnumerable{char} of the decorator.

Exceptions

ArgumentNullException

decorator cannot be null.

ToStringEquivalent(IDecorator<IEnumerable<char>>)

Converts the enclosed IEnumerable{char} of the decorator to its equivalent string representation.

public static string ToStringEquivalent(this IDecorator<IEnumerable<char>> decorator)

Parameters

decorator IDecorator<IEnumerable<char>>

The IDecorator<T> to extend.

Returns

string

A string equivalent to the enclosed IEnumerable{char} of the decorator.

Exceptions

ArgumentNullException

decorator cannot be null.

See Also