Table of Contents

Tweaker Class

Definition

Namespace
Cuemon
Assemblies
Cuemon.Core.dll
Source
src/Cuemon.Core/Tweaker.cs

Provides a way to change any instance of the same generic type.

public static class Tweaker
Inheritance
object
Tweaker

Examples

The following example demonstrates how to use Tweaker to apply inline transformations on values and objects: adjusting with a converter, altering in-place, and changing between types.

using System;
using System.Collections.Generic;

namespace Cuemon;

public class TweakerExample
{
    public void Demonstrate()
    {
        // Adjust: transform a value using a converter function
        int doubled = Tweaker.Adjust(21, x => x * 2);
        Console.WriteLine(doubled); // 42

        // Alter: modify an object in-place via an action delegate
        var list = new List<string> { "a", "b", "c" };
        Tweaker.Alter(list, lst => lst.Add("d"));
        Console.WriteLine(string.Join(", ", list)); // a, b, c, d

        // Change: convert a value to a different type
        string asString = Tweaker.Change(42, x => x.ToString());
        Console.WriteLine(asString); // 42

        // Adjust with null converter returns the original value unchanged
        int same = Tweaker.Adjust(10, null as Func<int, int>);
        Console.WriteLine(same); // 10
    }
}

Methods

Name Description
Adjust<T>(T, Func<T, T>)

Adjust the specified value with the function delegate converter.

Alter<T>(T, Action<T>)

Adjust the specified value with the modifier delegate.

Change<T, TResult>(T, Func<T, TResult>)

Converts the specified value to a value of TResult.