private void FillCore(PageViewModel model, IHostService host) { if (model.References == null || model.References.Count == 0) { return; } foreach (var r in model.References) { var m = host.LookupByUid(r.Uid).Find(x => x.Type == DocumentType.Article); if (m == null) { continue; } var page = (PageViewModel)m.Content; var item = page.Items.Find(x => x.Uid == r.Uid); if (item == null) { continue; } r.Summary = item.Summary; r.Type = item.Type; r.Syntax = item.Syntax; r.Platform = item.Platform; } }
private static void AddChildren(MetadataItem model, PageViewModel result) { if (model.Items != null && model.Items.Count > 0) { foreach (var item in model.Items) { result.Items.Add(ItemViewModel.FromModel(item)); AddChildren(item, result); } } }
public static IEnumerable<ReferenceViewModel> ToExternalReferenceViewModel(PageViewModel page, Uri baseUri) { foreach (var item in page.Items) { yield return new ReferenceViewModel { Uid = item.Uid, Name = item.Name, NameForCSharp = item.NameForCSharp, NameForVB = item.NameForVB, FullName = item.FullName, FullNameForCSharp = item.FullNameForCSharp, FullNameForVB = item.FullNameForVB, Href = baseUri + "/" + item.Href }; } }
public static PageViewModel FromModel(MetadataItem model) { if (model == null) { return null; } var result = new PageViewModel(); result.Items.Add(ItemViewModel.FromModel(model)); if (model.Type.AllowMultipleItems()) { AddChildren(model, result); } foreach (var item in model.References) { result.References.Add(ReferenceViewModel.FromModel(item)); } return result; }
private IEnumerable<string> GetViewModelXRef(PageViewModel vm) { foreach (var reference in vm.References) { if (reference.Uid.StartsWith("{") && reference.Uid.EndsWith("}")) { // ignore generic type parameter. continue; } if (reference.SpecForCSharp == null && reference.SpecForVB == null) { yield return reference.Uid; } else { // for spec type, only return the real type: // e.g.: // - List<string> --> List`1, string // - object[] --> object if (reference.SpecForCSharp != null) { foreach (var specItem in reference.SpecForCSharp) { if (specItem.Uid != null) { yield return specItem.Uid; } } } if (reference.SpecForVB != null) { foreach (var specItem in reference.SpecForVB) { if (specItem.Uid != null) { yield return specItem.Uid; } } } } } }
private static MergeItem CreateMergeItemCore(ItemViewModel majorItem, PageViewModel page) { return new MergeItem { MajorItem = majorItem, Children = new SortedSet<string>(majorItem.Children ?? Enumerable.Empty<string>()), Platform = new SortedSet<string>(majorItem.Platform ?? Enumerable.Empty<string>()), MinorItems = page?.Items.Where(x => x.Uid != majorItem.Uid).ToDictionary(item => item.Uid, item => CreateMergeItemCore(item, null)), References = page?.References.ToDictionary(item => item.Uid), Metadata = page?.Metadata, }; }
private void ConvertToVMCore(PageViewModel vm, MergeItem mergeItem) { if (mergeItem.Children.Count > 0) { mergeItem.MajorItem.Children = mergeItem.Children.ToList(); } if (mergeItem.Platform.Count > 0) { mergeItem.MajorItem.Platform = mergeItem.Platform.ToList(); } vm.Items.Add(mergeItem.MajorItem); if (mergeItem.MinorItems != null) { foreach (var item in mergeItem.MinorItems.Values) { ConvertToVMCore(vm, item); } } }
private PageViewModel ConvertToVM(MergeItem mergeItem) { var vm = new PageViewModel { Items = new List<ItemViewModel>(), References = mergeItem.References?.Values.ToList(), Metadata = mergeItem.Metadata, }; ConvertToVMCore(vm, mergeItem); return vm; }