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

[Enhancement] Make TextCaseConverter support ANY type #1051

@dansiegel

Description

@dansiegel

Summary

Currently the TextCaseConverter is pretty explicit about requiring that the value passed in must be null, a string, or a char... This is pretty silly as you may be passing in an Enum or a custom type with an overridden ToString.

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
=> value == null || value is string || value is char
? Convert(value?.ToString(), parameter)
: throw new ArgumentException("Value is neither a string nor a char", nameof(value));

API Changes

Simply return the convert instead of type checking.

public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
 	=> Convert(value?.ToString(), parameter);

Intended Use Case

You may want to use this with an Enum or other custom type which overrides ToString. The only implication would be with ConvertBack and since that throws a NotImplementedException it's a non-issue.

Who Will Do The Work?

  • I am willing to take this on myself
  • Just putting this out there for someone to pick up

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions