Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Add ToTitleCaseAttribute #17

@roydukkey

Description

@roydukkey

Sure. Here an example that follows the same pattern for the existing ToLowerAttribute and ToUpperAttribute.

using System;
using System.Globalization;

namespace Dado.ComponentModel.DataMutations
{
	[AttributeUsage(AttributeTargets.Property)]
	public class ToTitleCaseAttribute : MutationAttribute
	{
		public CultureInfo CultureInfo { get; set; } = CultureInfo.CurrentCulture;
		public override int Priority { get; set; } = 40;

		protected override object MutateValue(object value, IMutationContext context)
		{
			if (value is string valueAsString && !String.IsNullOrWhiteSpace(valueAsString)) {
				return CultureInfo.TextInfo.ToTitleCase(valueAsString);
			}

			if (value is char valueAsChar) {
				return CultureInfo.TextInfo.ToTitleCase();
			}

			return value;
		}
	}
}

This should probably be including in this package.

Originally posted by @roydukkey in #16 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions