private static IEnumerable<XRefSpec> GetXRefInfo(ItemViewModel item, string key, List<DataContracts.Common.ReferenceViewModel> references) { var result = new XRefSpec { Uid = item.Uid, Name = item.Name, Href = key, CommentId = item.CommentId, }; if (!string.IsNullOrEmpty(item.NameForCSharp)) { result["name.csharp"] = item.NameForCSharp; } if (!string.IsNullOrEmpty(item.NameForVB)) { result["name.vb"] = item.NameForVB; } if (!string.IsNullOrEmpty(item.FullName)) { result["fullName"] = item.FullName; } if (!string.IsNullOrEmpty(item.FullNameForCSharp)) { result["fullName.csharp"] = item.FullNameForCSharp; } if (!string.IsNullOrEmpty(item.FullNameForVB)) { result["fullName.vb"] = item.FullNameForVB; } if (!string.IsNullOrEmpty(item.NameWithType)) { result["nameWithType"] = item.NameWithType; } if (!string.IsNullOrEmpty(item.NameWithTypeForCSharp)) { result["nameWithType.csharp"] = item.NameWithTypeForCSharp; } if (!string.IsNullOrEmpty(item.NameWithTypeForVB)) { result["nameWithType.vb"] = item.NameWithTypeForVB; } yield return result; // generate overload xref spec. if (item.Overload != null) { var reference = references.Find(r => r.Uid == item.Overload); if (reference != null) { yield return GetXRefInfo(reference, key); } } }
private static ApiBuildOutput FromModel(ItemViewModel model, Dictionary<string, ApiReferenceBuildOutput> references, Dictionary<string, object> metadata) { if (model == null) return null; var output = new ApiBuildOutput { Uid = model.Uid, Id = Utility.GetHtmlId(model.Uid), IsExplicitInterfaceImplementation = model.IsExplicitInterfaceImplementation, IsExtensionMethod = model.IsExtensionMethod, Parent = ApiBuildOutputUtility.GetReferenceViewModel(model.Parent, references, model.SupportedLanguages), Children = GetReferenceList(model.Children, references, model.SupportedLanguages), Href = model.Href, SupportedLanguages = model.SupportedLanguages, Name = ApiBuildOutputUtility.TransformToLanguagePairList(model.Name, model.Names, model.SupportedLanguages), NameWithType = ApiBuildOutputUtility.TransformToLanguagePairList(model.NameWithType, model.NamesWithType, model.SupportedLanguages), FullName = ApiBuildOutputUtility.TransformToLanguagePairList(model.FullName, model.FullNames, model.SupportedLanguages), Type = model.Type, Source = model.Source, Documentation = model.Documentation, AssemblyNameList = model.AssemblyNameList, NamespaceName = ApiBuildOutputUtility.GetReferenceViewModel(model.NamespaceName, references, model.SupportedLanguages), Summary = model.Summary, Remarks = model.Remarks, Examples = model.Examples, Syntax = ApiSyntaxBuildOutput.FromModel(model.Syntax, references, model.SupportedLanguages), Overridden = ApiBuildOutputUtility.GetApiNames(model.Overridden, references, model.SupportedLanguages), Overload = ApiBuildOutputUtility.GetApiNames(model.Overload, references, model.SupportedLanguages), Exceptions = GetCrefInfoList(model.Exceptions, references, model.SupportedLanguages), SeeAlsos = GetLinkInfoList(model.SeeAlsos, references, model.SupportedLanguages), Sees = GetLinkInfoList(model.Sees, references, model.SupportedLanguages), Inheritance = GetReferenceList(model.Inheritance, references, model.SupportedLanguages, true), Implements = model.Implements?.Select(u => ApiBuildOutputUtility.GetApiNames(u, references, model.SupportedLanguages)).ToList(), InheritedMembers = GetReferenceList(model.InheritedMembers, references, model.SupportedLanguages), ExtensionMethods = GetReferenceList(model.ExtensionMethods, references, model.SupportedLanguages), Conceptual = model.Conceptual, Platform = model.Platform, Attributes = model.Attributes, Metadata = metadata.Concat(model.Metadata.Where(p => !metadata.Keys.Contains(p.Key))).ToDictionary(p => p.Key, p => p.Value), }; output.DerivedClasses = GetReferenceList(model.DerivedClasses, references, model.SupportedLanguages, true, output.Level + 1); return output; }
public static ApiReferenceBuildOutput FromModel(ItemViewModel vm) { if (vm == null) return null; var output = new ApiReferenceBuildOutput { Uid = vm.Uid, Id = Utility.GetHtmlId(vm.Uid), IsExplicitInterfaceImplementation = vm.IsExplicitInterfaceImplementation, IsExtensionMethod = vm.IsExtensionMethod, Parent = vm.Parent, IsExternal = false, Href = vm.Href, Name = ApiBuildOutputUtility.TransformToLanguagePairList(vm.Name, vm.Names, vm.SupportedLanguages), NameWithType = ApiBuildOutputUtility.TransformToLanguagePairList(vm.NameWithType, vm.NamesWithType, vm.SupportedLanguages), FullName = ApiBuildOutputUtility.TransformToLanguagePairList(vm.FullName, vm.FullNames, vm.SupportedLanguages), Spec = GetSpecNames(ApiBuildOutputUtility.GetXref(vm.Uid, vm.Name, vm.FullName), vm.SupportedLanguages), Source = vm.Source, Documentation = vm.Documentation, AssemblyNameList = vm.AssemblyNameList, NamespaceName = vm.NamespaceName, Remarks = vm.Remarks, Examples = vm.Examples, Overridden = ApiNames.FromUid(vm.Overridden), Overload = ApiNames.FromUid(vm.Overload), SeeAlsos = vm.SeeAlsos?.Select(ApiLinkInfoBuildOutput.FromModel).ToList(), Sees = vm.Sees?.Select(ApiLinkInfoBuildOutput.FromModel).ToList(), Inheritance = vm.Inheritance?.Select(FromUid).ToList(), Implements = vm.Implements?.Select(ApiNames.FromUid).ToList(), InheritedMembers = vm.InheritedMembers, ExtensionMethods = vm.ExtensionMethods, Modifiers = vm.Modifiers, Conceptual = vm.Conceptual, Metadata = vm.Metadata, Attributes = vm.Attributes, Syntax = ApiSyntaxBuildOutput.FromModel(vm.Syntax, vm.SupportedLanguages), Exceptions = vm.Exceptions?.Select(ApiExceptionInfoBuildOutput.FromModel).ToList(), }; output.Metadata["type"] = vm.Type; output.Metadata["summary"] = vm.Summary; output.Metadata["platform"] = vm.Platform; return output; }
private static MergeItem CreateMergeItemCore(ItemViewModel majorItem, PageViewModel page) { return new MergeItem { MajorItem = majorItem, AssemblyNameList = new SortedSet<string>(majorItem.AssemblyNameList ?? Enumerable.Empty<string>()), 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, }; }
public static ItemViewModel BuildItem(IHostService host, ItemViewModel item, FileModel model, Func<string, bool> filter = null) { var linkToUids = new HashSet<string>(); var pageViewModel = model.Content as PageViewModel; var skip = pageViewModel?.ShouldSkipMarkup; if (skip != true) { item.Summary = Markup(host, item.Summary, model, filter); item.Remarks = Markup(host, item.Remarks, model, filter); if (model.Type != DocumentType.Overwrite) { item.Conceptual = Markup(host, item.Conceptual, model, filter); } } linkToUids.UnionWith(item.Inheritance ?? EmptyEnumerable); linkToUids.UnionWith(item.DerivedClasses ?? EmptyEnumerable); linkToUids.UnionWith(item.InheritedMembers ?? EmptyEnumerable); linkToUids.UnionWith(item.Implements ?? EmptyEnumerable); linkToUids.UnionWith(item.SeeAlsos?.Where(s => s.LinkType == LinkType.CRef)?.Select(s => s.LinkId) ?? EmptyEnumerable); linkToUids.UnionWith(item.Sees?.Where(s => s.LinkType == LinkType.CRef)?.Select(s => s.LinkId) ?? EmptyEnumerable); if (item.Overridden != null) { linkToUids.Add(item.Overridden); } if (item.Syntax?.Return != null) { if (item.Syntax.Return.Description != null && skip != true) { item.Syntax.Return.Description = Markup(host, item.Syntax?.Return?.Description, model, filter); } linkToUids.Add(item.Syntax.Return.Type); } var parameters = item.Syntax?.Parameters; if (parameters != null) { foreach (var parameter in parameters) { if (skip != true) { parameter.Description = Markup(host, parameter.Description, model, filter); } linkToUids.Add(parameter.Type); } } if (item.Exceptions != null) { foreach (var exception in item.Exceptions) { if (skip != true) { exception.Description = Markup(host, exception.Description, model, filter); } linkToUids.Add(exception.Type); } } model.LinkToUids = model.LinkToUids.Union(linkToUids); return item; }
private void PatchViewModel(ItemViewModel item, string comment) { var commentModel = TripleSlashCommentModel.CreateModel(comment, SyntaxLanguage.CSharp, TripleSlashCommentParserContext.Instance); var summary = commentModel.Summary; if (!string.IsNullOrEmpty(summary)) { item.Summary = summary; } var remarks = commentModel.Remarks; if (!string.IsNullOrEmpty(remarks)) { item.Remarks = remarks; } var exceptions = commentModel.Exceptions; if (exceptions != null && exceptions.Count > 0) { item.Exceptions = exceptions; } var sees = commentModel.Sees; if (sees != null && sees.Count > 0) { item.Sees = sees; } var seeAlsos = commentModel.SeeAlsos; if (seeAlsos != null && seeAlsos.Count > 0) { item.SeeAlsos = seeAlsos; } var examples = commentModel.Examples; if (examples != null && examples.Count > 0) { item.Examples = examples; } if (item.Syntax != null) { if (item.Syntax.Parameters != null) { foreach (var p in item.Syntax.Parameters) { var description = commentModel.GetParameter(p.Name); if (!string.IsNullOrEmpty(description)) { p.Description = description; } } } if (item.Syntax.TypeParameters != null) { foreach (var p in item.Syntax.TypeParameters) { var description = commentModel.GetTypeParameter(p.Name); if (!string.IsNullOrEmpty(description)) { p.Description = description; } } } if (item.Syntax.Return != null) { var returns = commentModel.Returns; if (!string.IsNullOrEmpty(returns)) { item.Syntax.Return.Description = returns; } } } // todo more. }