Custom Formatter Support
Issue #45
resolved
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)
-
reporter -
reporter - changed status to open
-
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
orGenericQcSeraializer
is sufficiente.g.
public class UnityObjectSerialiazer : PolymorphicQcSerializer<Object> { public override string SerializeFormatted(Object value, QuantumTheme theme) { return value.name; } }
-
reporter - changed status to resolved
- Log in to comment
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