Humanizer.Core Transform Method

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Humanizer.Core provides a Transform() string extension method that transforms a string using the provided transformers. Transformations are applied in the provided order.

Let's consider the following simple example that transforms a string to the various casing using IStringTransformer for letter casing.

public static void Example1()
{
    string str = "My Test String";

    Console.WriteLine(str.Transform(To.TitleCase));
    Console.WriteLine(str.Transform(To.UpperCase));
    Console.WriteLine(str.Transform(To.LowerCase));
    Console.WriteLine(str.Transform(To.SentenceCase));
}

Let's execute the above example and you will see the following output.

My test string
My Test String
my test string

The property passed as a parameter like To.TitleCase returns an instance of a private class that implements IStringTransformer and knows how to turn a string into a specified case.

The advantage of using the Transform method is that IStringTransformer is an interface you can implement in your codebase once and use it with the Transform method allowing for easy extension.



Got any Humanizer.Core Question?