Custom Formatter Support

Issue #45 resolved
Yusuf Ismail repo owner created an issue

The QuantumFormatter should be easily extensible with custom formatters An example format of how it could work goes as follows

[QuantumFormatter]
private static string CustomTypeFormatter(CustomType obj, QuantumTheme theme)
{
   ...
}

Where CustomTypeFormatter was a static method that returns a formatted string of the obj of type CustomType. This would automatically be loaded by the QuantumFormatter, allowing you to add custom formatting to classes and types that you do not have source access to

Comments (4)

  1. Yusuf Ismail reporter

    After more investigation, I believe an interface and injection solution will be better

    This interface, for example IQcFormatter would be able to format the incoming object, specify what types it can format and use the base formatter for recursive formatting

  2. Yusuf Ismail reporter

    This has now been finished for V2.3.0

    public interface IQcSerializer
    {
        int Priority { get; }
    
        bool CanSerialize(Type type);
        string SerializeFormatted(object value, QuantumTheme theme, Func<object, QuantumTheme, string> recursiveSerializer);
    }
    

    In 99% of use cases though, just inheriting from either BasicQcSerializer PolymorphicQcSerializer or GenericQcSeraializer is sufficient

    e.g.

    public class UnityObjectSerialiazer : PolymorphicQcSerializer<Object>
    {
        public override string SerializeFormatted(Object value, QuantumTheme theme)
        {
            return value.name;
        }
    }
    

  3. Log in to comment