public IEnumerable <IHtmlElement> Serialize(object x, int lvl, IHtmlSerializer fac) { // IDictionary dict; // dict = (IDictionary) x; // dict = (IDictionary<string, object>) x; var d = (IDictionary)x; var itemtype = HtmlSupport.Itemtype(x); var subs = d.Keys.ToRawList().Cast <string>() .Select(name => new { Name = name, Val = d[name] }) // .Where(a => a.Val != null) .SelectMany(a => new IHtmlElement[] { new Dt(a.Name), new Dd { Subs = fac.Serialize(a.Val, lvl - 1, fac).ToArray() } }) .ToArray(); return(new Ul { Subs = subs, Itemscope = true, Itemtype = itemtype, }.ToArray()); }
public IEnumerable <IHtmlElement> Serialize(object o, int lvl, IHtmlSerializer fac) { // Type elementType = GetElementType(o); // Type elementType = GetItemType(o); if (o is IEnumerable) { o = (o as IEnumerable).ToRawList(); } var elementType = o.GetType().GetGenericArguments().Length == 1 ? o.GetType().GetGenericArguments()[0] : o.GetType().GetElementType(); if (elementType == null) { throw new ArgumentException($"Unable to find elementtype for {o.GetType()}"); } var itemType = HtmlSupport.GetItemType(elementType); return(new Ul { Clz = "result-list " + itemType, Itemscope = true, Itemtype = HtmlSupport.Itemtype(o), Subs = ((IEnumerable <object>)o) .SelectMany(item => fac.Serialize(item, lvl - 1, fac)) .Select(elem => new Li(elem)) .OfType <IHtmlElement>() .ToArray(), }.ToArray()); }
public static IEnumerable <IHtmlElement> SerializeProps(object x, int lvl, IHtmlSerializer fac, IEnumerable <MemberInfo> props, bool includeType) { var itemType = HtmlSupport.Itemtype(x); var subs = new List <IHtmlElement>(); if (includeType) { subs.AddRange(new IHtmlElement[] { new Dt("Type"), new Dd { Title = itemType, Text = x.GetType().Name, }, }); } props .Select(mi => new { mi.Name, Val = HtmlSupport.TryGetVal(mi, x) }) .Where(a => a.Val != null) .SelectMany(a => new IHtmlElement[] { new Dt(a.Name), new Dd { Itemprop = PropName(a.Name), Subs = fac.Serialize(a.Val, lvl - 1, fac).ToArray() } }) .ToList().ForEach(e => subs.Add(e)); return(new Dl { Subs = subs.ToArray(), Itemscope = true, Itemtype = itemType, }.ToArray()); }
public void Convert(string path) { List <ReleaseNote> releaseNotes = _xmlDeserializer.Deserialize(path); _htmlSerializer.Serialize(releaseNotes, path); }