public string Name { get; }
public MyObject(string name) => Name = name;
public class MyFormatter : IFormatProvider, ICustomFormatter {
public object GetFormat(Type formatType)
public string Format(string fmt, object obj, IFormatProvider formatProvider)
if(obj is MyObject myObj)
public static void Main()
Console.WriteLine(obj?.ToString() ?? "");
Console.WriteLine(Convert.ToString(obj, new MyFormatter()));
Console.WriteLine(string.Format(new MyFormatter(), "{0}", obj));