public static void Serialize <TDoc, TCursor>(TagElementStream <TDoc, TCursor, string> s, ref Values.GroupTag32Collection collection, string groupsElementName = "Groups") where TDoc : class where TCursor : class { Contract.Requires(!string.IsNullOrEmpty(groupsElementName)); bool reading = s.IsReading; var guid = reading ? Values.KGuid.Empty : collection.Uuid; var tags = reading ? null // HACK: GroupTags is exposed as a IReadOnlyList, but at the time of this writing is implemented // with a GroupTagData32[] as its backing field : (Values.GroupTagData32[])collection.GroupTags; s.StreamAttributeOpt("guid", ref guid, Predicates.IsNotEmpty); using (var bm = s.EnterCursorBookmarkOpt(groupsElementName, tags, Predicates.HasItems)) if (bm.IsNotNull) { StreamElements(s, ref tags); } if (reading) { bool sort = false; s.ReadAttributeOpt("sort", ref sort); collection = new Values.GroupTag32Collection(guid, sort, tags); } }
public static void Serialize <TDoc, TCursor>(TagElementStream <TDoc, TCursor, string> s, ref Values.GroupTagData32 value) where TDoc : class where TCursor : class { bool reading = s.IsReading; var group_tag = reading ? null : value.TagString; var name = reading ? null : value.Name; var guid = reading ? Values.KGuid.Empty : value.Uuid; s.StreamAttribute("tag", ref group_tag); s.StreamAttributeOpt("guid", ref guid, Predicates.IsNotEmpty); s.StreamAttribute("name", ref name); if (reading) { value = new Values.GroupTagData32(group_tag, name, guid); } }