Apply some auto-formatting changes

This commit is contained in:
Johann Studanski
2025-01-24 14:16:46 +01:00
parent 462668f605
commit 12794730dc
2 changed files with 16 additions and 15 deletions

View File

@@ -150,7 +150,7 @@ namespace Claunia.PropertyList
/// <summary>Register preprocessing functions for for plist values.</summary> /// <summary>Register preprocessing functions for for plist values.</summary>
/// <param name="preprocessor">A function that preprocesses the passed string and returns the adjusted value.</param> /// <param name="preprocessor">A function that preprocesses the passed string and returns the adjusted value.</param>
/// <param name="type">The type of value preprocessor to use.</param> /// <param name="type">The type of value preprocessor to use.</param>
public static void RegisterValuePreprocessor<T>(Func<T, T> preprocessor, ValuePreprocessor.Type type) => public static void RegisterValuePreprocessor<T>(Func<T, T> preprocessor, ValuePreprocessor.Type type) =>
ValuePreprocessor.Register(preprocessor, type); ValuePreprocessor.Register(preprocessor, type);
/// <summary>Reads all bytes from an Stream and stores them in an array, up to a maximum count.</summary> /// <summary>Reads all bytes from an Stream and stores them in an array, up to a maximum count.</summary>

View File

@@ -15,14 +15,16 @@ namespace Claunia.PropertyList
/// </summary> /// </summary>
public enum Type public enum Type
{ {
BOOL, INTEGER, FLOATING_POINT, UNDEFINED_NUMBER, BOOL, INTEGER, FLOATING_POINT,
STRING, DATA, DATE UNDEFINED_NUMBER, STRING, DATA,
DATE
}; };
/// <summary> /// <summary>
/// A Null-Implementation of a preprocessor for registered, but passive, use cases. /// A null-implementation of a preprocessor for registered, but passive, use cases.
/// </summary> /// </summary>
private static T NullPreprocessor<T>(T value) => value; private static T NullPreprocessor<T>(T value) => value;
private record struct TypeIdentifier(Type ValueType, System.Type ProcessingType); private record struct TypeIdentifier(Type ValueType, System.Type ProcessingType);
/// <summary> /// <summary>
@@ -45,24 +47,22 @@ namespace Claunia.PropertyList
/// <summary> /// <summary>
/// Register a custom preprocessor. /// Register a custom preprocessor.
/// </summary> /// </summary>
public static void Register<T>(Func<T, T> preprocessor, Type type) => public static void Register<T>(Func<T, T> preprocessor, Type type) =>
_preprocessors[new(type, typeof(T))] = preprocessor; _preprocessors[new(type, typeof(T))] = preprocessor;
/// <summary> /// <summary>
/// Unregister a specific preprocessor--replaces it with a null implementation /// Unregister a specific preprocessor--replaces it with a null-implementation
/// to prevent argument errors. /// to prevent argument errors.
/// </summary> /// </summary>
public static void Unregister<T>(Type type) => public static void Unregister<T>(Type type) => _preprocessors[new(type, typeof(T))] = NullPreprocessor<T>;
_preprocessors[new(type, typeof(T))] = NullPreprocessor<T>;
/// <summary> /// <summary>
/// Preprocess the supplied data using the appropriate registered implementation. /// Preprocess the supplied data using the appropriate registered implementation.
/// </summary> /// </summary>
/// <exception cref="ArgumentException">If no appropriate preprocessor--not even a default null implementation--was registered.</exception> /// <exception cref="ArgumentException">If no appropriate preprocessor--not even a default null-implementation--was registered.</exception>
public static T Preprocess<T>(T value, Type type) => public static T Preprocess<T>(T value, Type type) => TryGetPreprocessor(type, out Func<T, T> preprocess)
TryGetPreprocessor(type, out Func<T, T> preprocess) ? preprocess(value)
? preprocess(value) : throw new ArgumentException($"Failed to find a preprocessor for value '{value}'.");
: throw new ArgumentException($"Failed to find a preprocessor for value '{value}'.");
/// <summary> /// <summary>
/// Gets the appropriate registered implementation--or null--and casts it back to the required type. /// 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)) if(_preprocessors.TryGetValue(new TypeIdentifier(type, typeof(T)), out Delegate preprocessor))
{ {
preprocess = (Func<T, T>) preprocessor; preprocess = (Func<T, T>)preprocessor;
return true; return true;
} }
preprocess = default; preprocess = default;
return false; return false;
} }
} }
} }