From 12794730dcf954450ce615458172dfd82806353d Mon Sep 17 00:00:00 2001 From: Johann Studanski Date: Fri, 24 Jan 2025 14:16:46 +0100 Subject: [PATCH] Apply some auto-formatting changes --- plist-cil/PropertyListParser.cs | 2 +- plist-cil/ValuePreprocessor.cs | 29 +++++++++++++++-------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/plist-cil/PropertyListParser.cs b/plist-cil/PropertyListParser.cs index eea8073..6cfc071 100644 --- a/plist-cil/PropertyListParser.cs +++ b/plist-cil/PropertyListParser.cs @@ -150,7 +150,7 @@ namespace Claunia.PropertyList /// Register preprocessing functions for for plist values. /// A function that preprocesses the passed string and returns the adjusted value. /// The type of value preprocessor to use. - public static void RegisterValuePreprocessor(Func preprocessor, ValuePreprocessor.Type type) => + public static void RegisterValuePreprocessor(Func preprocessor, ValuePreprocessor.Type type) => ValuePreprocessor.Register(preprocessor, type); /// Reads all bytes from an Stream and stores them in an array, up to a maximum count. diff --git a/plist-cil/ValuePreprocessor.cs b/plist-cil/ValuePreprocessor.cs index df5295b..f6153de 100644 --- a/plist-cil/ValuePreprocessor.cs +++ b/plist-cil/ValuePreprocessor.cs @@ -15,14 +15,16 @@ namespace Claunia.PropertyList /// public enum Type { - BOOL, INTEGER, FLOATING_POINT, UNDEFINED_NUMBER, - STRING, DATA, DATE + BOOL, INTEGER, FLOATING_POINT, + UNDEFINED_NUMBER, STRING, DATA, + DATE }; /// - /// A Null-Implementation of a preprocessor for registered, but passive, use cases. + /// A null-implementation of a preprocessor for registered, but passive, use cases. /// private static T NullPreprocessor(T value) => value; + private record struct TypeIdentifier(Type ValueType, System.Type ProcessingType); /// @@ -45,24 +47,22 @@ namespace Claunia.PropertyList /// /// Register a custom preprocessor. /// - public static void Register(Func preprocessor, Type type) => + public static void Register(Func preprocessor, Type type) => _preprocessors[new(type, typeof(T))] = preprocessor; /// - /// Unregister a specific preprocessor--replaces it with a null implementation + /// Unregister a specific preprocessor--replaces it with a null-implementation /// to prevent argument errors. /// - public static void Unregister(Type type) => - _preprocessors[new(type, typeof(T))] = NullPreprocessor; + public static void Unregister(Type type) => _preprocessors[new(type, typeof(T))] = NullPreprocessor; /// /// Preprocess the supplied data using the appropriate registered implementation. /// - /// If no appropriate preprocessor--not even a default null implementation--was registered. - public static T Preprocess(T value, Type type) => - TryGetPreprocessor(type, out Func preprocess) - ? preprocess(value) - : throw new ArgumentException($"Failed to find a preprocessor for value '{value}'."); + /// If no appropriate preprocessor--not even a default null-implementation--was registered. + public static T Preprocess(T value, Type type) => TryGetPreprocessor(type, out Func preprocess) + ? preprocess(value) + : throw new ArgumentException($"Failed to find a preprocessor for value '{value}'."); /// /// Gets the appropriate registered implementation--or null--and casts it back to the required type. @@ -71,13 +71,14 @@ namespace Claunia.PropertyList { if(_preprocessors.TryGetValue(new TypeIdentifier(type, typeof(T)), out Delegate preprocessor)) { - preprocess = (Func) preprocessor; + preprocess = (Func)preprocessor; + return true; } preprocess = default; + return false; } } - } \ No newline at end of file