This repository was archived by the owner on Sep 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Add ToTitleCaseAttribute #17
Copy link
Copy link
Open
Labels
up-for-grabsThank you!Thank you!
Description
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
Labels
up-for-grabsThank you!Thank you!