From 598d5622fd29ebbb1a0cced8b60b8af28c506830 Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Tue, 24 Mar 2020 17:51:20 -0500 Subject: [PATCH] Formatting --- IPA.Loader/Config/Stores/Attributes.cs | 22 ++-- IPA.Loader/Config/Stores/Converters.cs | 150 ++++++++++++------------- 2 files changed, 84 insertions(+), 88 deletions(-) diff --git a/IPA.Loader/Config/Stores/Attributes.cs b/IPA.Loader/Config/Stores/Attributes.cs index 43fab747..593d1b52 100644 --- a/IPA.Loader/Config/Stores/Attributes.cs +++ b/IPA.Loader/Config/Stores/Attributes.cs @@ -1,9 +1,6 @@ using System; -using System.Collections.Generic; using System.ComponentModel; using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace IPA.Config.Stores.Attributes { @@ -23,7 +20,7 @@ namespace IPA.Config.Stores.Attributes /// /// Indicates that a field or property in an object being wrapped by - /// that would otherwise be nullable (i.e. a reference type or a type) should never be null, and the + /// that would otherwise be nullable (i.e. a reference type or a type) should never be null, and the /// member will be ignored if the deserialized value is . /// [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)] @@ -31,7 +28,7 @@ namespace IPA.Config.Stores.Attributes /// /// Indicates that a given field or property in an object being wrapped by - /// should be serialized and deserialized using the provided converter instead of the default mechanism. + /// should be serialized and deserialized using the provided converter instead of the default mechanism. /// [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)] public sealed class UseConverterAttribute : Attribute @@ -40,6 +37,7 @@ namespace IPA.Config.Stores.Attributes /// Gets the type of the converter to use. /// public Type ConverterType { get; } + /// /// Gets the target type of the converter if it is avaliable at instantiation time, otherwise /// . @@ -60,7 +58,7 @@ namespace IPA.Config.Stores.Attributes ConverterType = converterType; var baseT = ConverterType.BaseType; - while (baseT != null && baseT != typeof(object) && + while (baseT != null && baseT != typeof(object) && (!baseT.IsGenericType || baseT.GetGenericTypeDefinition() != typeof(ValueConverter<>))) baseT = baseT.BaseType; if (baseT == typeof(object)) ConverterTargetType = null; @@ -73,14 +71,14 @@ namespace IPA.Config.Stores.Attributes } /// - /// Specifies a name for the serialized field or property in an object being wrapped by + /// Specifies a name for the serialized field or property in an object being wrapped by /// that is different from the member name itself. /// /// /// /// When serializing the following object, we might get the JSON that follows. /// - /// public class PluginConfig + /// public class PluginConfig /// { /// public virtual bool BooleanField { get; set; } = true; /// } @@ -94,7 +92,7 @@ namespace IPA.Config.Stores.Attributes /// /// However, if we were to add a to that field, we would get the following. /// - /// public class PluginConfig + /// public class PluginConfig /// { /// [SerializedName("bool")] /// public virtual bool BooleanField { get; set; } = true; @@ -108,7 +106,7 @@ namespace IPA.Config.Stores.Attributes /// /// [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)] - public sealed class SerializedNameAttribute : Attribute + public sealed class SerializedNameAttribute : Attribute { /// /// Gets the name to replace the member name with. @@ -124,6 +122,4 @@ namespace IPA.Config.Stores.Attributes Name = name; } } - - -} +} \ No newline at end of file diff --git a/IPA.Loader/Config/Stores/Converters.cs b/IPA.Loader/Config/Stores/Converters.cs index b78c95b4..dc1b372b 100644 --- a/IPA.Loader/Config/Stores/Converters.cs +++ b/IPA.Loader/Config/Stores/Converters.cs @@ -178,91 +178,91 @@ namespace IPA.Config.Stores.Converters public NullableConverter() : base(new TConverter()) { } } - /// - /// A converter for an enum of type , that converts the enum to its string representation and back. - /// + /// + /// A converter for an enum of type , that converts the enum to its string representation and back. + /// /// the enum type public sealed class EnumConverter : ValueConverter - where T : Enum - { - /// - /// Converts a that is a node to the corresponding enum value. - /// - /// the to convert - /// the object which will own the created object - /// the deserialized enum value - /// if is not a node - public override T FromValue(Value value, object parent) - => value is Text t - ? (T)Enum.Parse(typeof(T), t.Value) - : throw new ArgumentException("Value not a string", nameof(value)); - - /// - /// Converts an enum of type to a node corresponding to its value. - /// - /// the value to serialize - /// the object which owns - /// a node representing - public override Value ToValue(T obj, object parent) - => Value.Text(obj.ToString()); + where T : Enum + { + /// + /// Converts a that is a node to the corresponding enum value. + /// + /// the to convert + /// the object which will own the created object + /// the deserialized enum value + /// if is not a node + public override T FromValue(Value value, object parent) + => value is Text t + ? (T)Enum.Parse(typeof(T), t.Value) + : throw new ArgumentException("Value not a string", nameof(value)); + + /// + /// Converts an enum of type to a node corresponding to its value. + /// + /// the value to serialize + /// the object which owns + /// a node representing + public override Value ToValue(T obj, object parent) + => Value.Text(obj.ToString()); } - /// - /// A converter for an enum of type , that converts the enum to its string representation and back, - /// ignoring the case of the serialized value for deseiralization. - /// + /// + /// A converter for an enum of type , that converts the enum to its string representation and back, + /// ignoring the case of the serialized value for deseiralization. + /// /// the enum type public sealed class CaseInsensitiveEnumConverter : ValueConverter - where T : Enum - { - /// - /// Converts a that is a node to the corresponding enum value. - /// - /// the to convert - /// the object which will own the created object - /// the deserialized enum value - /// if is not a node - public override T FromValue(Value value, object parent) - => value is Text t - ? (T)Enum.Parse(typeof(T), t.Value, true) - : throw new ArgumentException("Value not a string", nameof(value)); - - /// - /// Converts an enum of type to a node corresponding to its value. - /// - /// the value to serialize - /// the object which owns - /// a node representing - public override Value ToValue(T obj, object parent) - => Value.Text(obj.ToString()); + where T : Enum + { + /// + /// Converts a that is a node to the corresponding enum value. + /// + /// the to convert + /// the object which will own the created object + /// the deserialized enum value + /// if is not a node + public override T FromValue(Value value, object parent) + => value is Text t + ? (T)Enum.Parse(typeof(T), t.Value, true) + : throw new ArgumentException("Value not a string", nameof(value)); + + /// + /// Converts an enum of type to a node corresponding to its value. + /// + /// the value to serialize + /// the object which owns + /// a node representing + public override Value ToValue(T obj, object parent) + => Value.Text(obj.ToString()); } - /// - /// A converter for an enum of type , that converts the enum to its underlying value for serialization. - /// + /// + /// A converter for an enum of type , that converts the enum to its underlying value for serialization. + /// /// the enum type public sealed class NumericEnumConverter : ValueConverter - where T : Enum - { - /// - /// Converts a that is a numeric node to the corresponding enum value. - /// - /// the to convert - /// the object which will own the created object - /// the deserialized enum value - /// if is not a numeric node - public override T FromValue(Value value, object parent) - => (T)Enum.ToObject(typeof(T), Converter.IntValue(value) - ?? throw new ArgumentException("Value not a numeric node", nameof(value))); - - /// - /// Converts an enum of type to a node corresponding to its value. - /// - /// the value to serialize - /// the object which owns - /// an node representing - public override Value ToValue(T obj, object parent) - => Value.Integer(Convert.ToInt64(obj)); + where T : Enum + { + /// + /// Converts a that is a numeric node to the corresponding enum value. + /// + /// the to convert + /// the object which will own the created object + /// the deserialized enum value + /// if is not a numeric node + public override T FromValue(Value value, object parent) + => (T)Enum.ToObject(typeof(T), Converter.IntValue(value) + ?? throw new ArgumentException("Value not a numeric node", nameof(value))); + + /// + /// Converts an enum of type to a node corresponding to its value. + /// + /// the value to serialize + /// the object which owns + /// an node representing + public override Value ToValue(T obj, object parent) + => Value.Integer(Convert.ToInt64(obj)); } internal class StringConverter : ValueConverter