complete account page

This commit is contained in:
2022-03-02 17:31:49 +08:00
parent aa38e186c7
commit 51f8e4f2e8
26 changed files with 547 additions and 76 deletions

View File

@ -1,4 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Linq;
using Billing.Models;
using Xamarin.Forms;
namespace Billing.UI
@ -75,6 +79,51 @@ namespace Billing.UI
}
}
public static class ModelExtensionHelper
{
public static List<T> FromStream<T>(Stream stream) where T : IModel, new()
{
XDocument doc = XDocument.Load(stream);
var root = doc.Root;
var list = new List<T>();
foreach (XElement ele in root.Elements("item"))
{
if (ele.Attribute("null")?.Value == "1")
{
list.Add(default);
}
else
{
T value = new();
value.OnXmlDeserialize(ele);
list.Add(value);
}
}
return list;
}
public static void ToStream<T>(this IEnumerable<T> list, Stream stream) where T : IModel
{
XElement root = new("root");
foreach (var t in list)
{
XElement item = new("item");
if (t == null)
{
item.Add(new XAttribute("null", 1));
}
else
{
t.OnXmlSerialize(item);
}
root.Add(item);
}
XDocument doc = new(new XDeclaration("1.0", "utf-8", "yes"), root);
doc.Save(stream, SaveOptions.DisableFormatting);
}
}
public class Tap : IDisposable
{
private readonly static object sync = new();