Skip to content

Commit

Permalink
Use a default value for null non optional types
Browse files Browse the repository at this point in the history
  • Loading branch information
KillzXGaming committed Nov 11, 2023
1 parent 41e1162 commit e5a67d5
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Fushigi.Byml/Serializer/BymlSerialize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,22 @@ static BymlHashTable SetHashTable(object section)
if (bymlIgnoreAttribute != null)
continue;

//Skip null optional values
var value = properties[i].GetValue(section);

if (byamlAttribute != null)
{
if (byamlAttribute.Optional && properties[i].GetValue(section) == null)
//Skip null optional values
if (byamlAttribute.Optional && value == null)
continue;

//If value is null, use a default value
if (value == null)
value = byamlAttribute.DefaultValue;
}

//Set custom keys as property name if used
string name = byamlAttribute != null && byamlAttribute.Key != null ? byamlAttribute.Key : properties[i].Name;

var value = properties[i].GetValue(section);
if (value == null)
continue;

Expand Down

0 comments on commit e5a67d5

Please sign in to comment.