diff --git a/Tomlet/TomlCompositeDeserializer.cs b/Tomlet/TomlCompositeDeserializer.cs index f705fa4..6a42204 100644 --- a/Tomlet/TomlCompositeDeserializer.cs +++ b/Tomlet/TomlCompositeDeserializer.cs @@ -34,6 +34,9 @@ public static TomlSerializationMethods.Deserialize For(Type type, TomlSe } catch (Exception) { + if(options.IgnoreInvalidEnumValues) + return Enum.GetValues(type).GetValue(0)!; + throw new TomlEnumParseException(enumName, type); } }; diff --git a/Tomlet/TomlSerializerOptions.cs b/Tomlet/TomlSerializerOptions.cs index 54b79be..37daa9a 100644 --- a/Tomlet/TomlSerializerOptions.cs +++ b/Tomlet/TomlSerializerOptions.cs @@ -3,6 +3,19 @@ public class TomlSerializerOptions { public static TomlSerializerOptions Default = new(); + + /// + /// When set to false (default) the deserializer will skip assigning fields that have constructor params of the same name. + /// public bool OverrideConstructorValues { get; set; } = false; + + /// + /// When set to true, the deserializer will ignore non-public members. When set to false, only members marked [NonSerialized] will be ignored. + /// public bool IgnoreNonPublicMembers { get; set; } = false; + + /// + /// When set to true, the deserializer will ignore invalid enum values (and they will be implicitly left at their default value). When set to false, an exception will be thrown if the enum value is not found. + /// + public bool IgnoreInvalidEnumValues { get; set; } = false; } \ No newline at end of file