-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
smarthome
committed
Aug 6, 2023
1 parent
5ef5900
commit 87f5959
Showing
3 changed files
with
33 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System.Xml.Linq; | ||
|
||
namespace FamilyTree | ||
{ | ||
public static class PersonDeserializer | ||
{ | ||
public static Person Deserialize(XElement root) | ||
{ | ||
if (root == null) | ||
return null; | ||
|
||
var name = root.Attribute("Name").Value; | ||
var familiyName = root.Attribute("FamilyName").Value; | ||
int.TryParse(root.Attribute("Birth")?.Value, out var birthYear); | ||
int.TryParse(root.Attribute("Death")?.Value, out var deathYear); | ||
bool.TryParse(root.Attribute("IsAlive")?.Value, out var isAlive); | ||
var father = Deserialize(root.Element("Father")); | ||
var mother = Deserialize(root.Element("Mother")); | ||
return new Person(name, familiyName, birthYear, deathYear, isAlive, father, mother); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters