示例#1
0
        public static ApiReferenceBuildOutput FromModel(ReferenceViewModel vm, string[] supportedLanguages)
        {
            if (vm == null)
            {
                return(null);
            }

            // TODO: may lead to potential problems with have vm.Additional["syntax"] as SyntaxDetailViewModel
            // It is now working as syntax is set only in FillReferenceInformation and not from YAML deserialization
            var result = new ApiReferenceBuildOutput
            {
                Uid          = vm.Uid,
                Id           = Utility.GetHtmlId(vm.Uid),
                Parent       = vm.Parent,
                Definition   = vm.Definition,
                IsExternal   = vm.IsExternal,
                Href         = vm.Href,
                Name         = ApiBuildOutputUtility.TransformToLanguagePairList(vm.Name, vm.NameInDevLangs, supportedLanguages),
                NameWithType = ApiBuildOutputUtility.TransformToLanguagePairList(vm.NameWithType, vm.NameWithTypeInDevLangs, supportedLanguages),
                FullName     = ApiBuildOutputUtility.TransformToLanguagePairList(vm.FullName, vm.FullNameInDevLangs, supportedLanguages),
                Spec         = GetSpecNames(ApiBuildOutputUtility.GetXref(vm.Uid, vm.FullName, vm.Name), supportedLanguages, vm.Specs),
                Metadata     = vm.Additional,
            };
            object syntax;

            if (result.Metadata.TryGetValue("syntax", out syntax))
            {
                result.Syntax = ApiSyntaxBuildOutput.FromModel(syntax as SyntaxDetailViewModel, supportedLanguages);
                result.Metadata.Remove("syntax");
            }
            return(result);
        }
示例#2
0
        public static ApiBuildOutput FromModel(PageViewModel model)
        {
            if (model == null || model.Items == null || model.Items.Count == 0)
            {
                return(null);
            }

            var metadata   = model.Metadata;
            var references = new Dictionary <string, ApiReferenceBuildOutput>();

            foreach (var item in model.References)
            {
                if (!string.IsNullOrEmpty(item.Uid))
                {
                    references[item.Uid] = ApiReferenceBuildOutput.FromModel(item, model.Items[0].SupportedLanguages);
                }
            }

            // Add other items to reference, override the one in reference with same uid
            foreach (var item in model.Items.Skip(1))
            {
                if (!string.IsNullOrEmpty(item.Uid))
                {
                    references[item.Uid] = ApiReferenceBuildOutput.FromModel(item);
                }
            }

            return(FromModel(model.Items[0], references, metadata));
        }
示例#3
0
        public static ApiCrefInfoBuildOutput FromModel(CrefInfo model)
        {
            if (model == null)
            {
                return(null);
            }

            return(new ApiCrefInfoBuildOutput
            {
                Type = ApiReferenceBuildOutput.FromUid(model.Type),
                Description = model.Description,
            });
        }
        public static ApiParameterBuildOutput FromModel(ApiParameter model)
        {
            if (model == null)
            {
                return(null);
            }

            return(new ApiParameterBuildOutput
            {
                Name = model.Name,
                Type = ApiReferenceBuildOutput.FromUid(model.Type),
                Description = model.Description,
            });
        }
示例#5
0
 public static List <ApiLanguageValuePair> GetSpec(string key, Dictionary <string, ApiReferenceBuildOutput> references, string[] supportedLanguages)
 {
     if (string.IsNullOrEmpty(key))
     {
         return(null);
     }
     if (!references.TryGetValue(key, out ApiReferenceBuildOutput reference))
     {
         return(ApiReferenceBuildOutput.GetSpecNames(GetXref(key), supportedLanguages));
     }
     else
     {
         return(reference.Spec);
     }
 }
示例#6
0
        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.FullName, vm.Name), 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(s => ApiLinkInfoBuildOutput.FromModel(s)).ToList(),
                Sees             = vm.Sees?.Select(s => ApiLinkInfoBuildOutput.FromModel(s)).ToList(),
                Inheritance      = vm.Inheritance?.Select(i => FromUid(i)).ToList(),
                Implements       = vm.Implements?.Select(i => ApiNames.FromUid(i)).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(s => ApiExceptionInfoBuildOutput.FromModel(s)).ToList(),
            };

            output.Metadata["type"]     = vm.Type;
            output.Metadata["summary"]  = vm.Summary;
            output.Metadata["platform"] = vm.Platform;
            return(output);
        }
示例#7
0
        public static ApiBuildOutput FromModel(PageViewModel model)
        {
            if (model == null || model.Items == null || model.Items.Count == 0)
            {
                return(null);
            }

            object displayLangs;

            if (model.Metadata.TryGetValue("_displayLangs", out displayLangs))
            {
                var langsObj = displayLangs as object[];
                if (langsObj != null)
                {
                    var langs = langsObj.Select(x => x?.ToString()).ToArray();
                    model.Items.ForEach(item => item.SupportedLanguages = IntersectLangs(item.SupportedLanguages, langs));
                }
                else
                {
                    Logger.LogWarning("Invalid displayLangs setting in docfx.json. Ignored.");
                }
            }

            var metadata   = model.Metadata;
            var references = new Dictionary <string, ApiReferenceBuildOutput>();

            foreach (var item in model.References)
            {
                if (!string.IsNullOrEmpty(item.Uid))
                {
                    references[item.Uid] = ApiReferenceBuildOutput.FromModel(item, model.Items[0].SupportedLanguages);
                }
            }

            // Add other items to reference, override the one in reference with same uid
            foreach (var item in model.Items.Skip(1))
            {
                if (!string.IsNullOrEmpty(item.Uid))
                {
                    references[item.Uid] = ApiReferenceBuildOutput.FromModel(item);
                }
            }

            return(FromModel(model.Items[0], references, metadata));
        }
示例#8
0
        public static ApiReferenceBuildOutput GetReferenceViewModel(string key, Dictionary<string, ApiReferenceBuildOutput> references, string[] supportedLanguages)
        {
            if (string.IsNullOrEmpty(key)) return null;

            ApiReferenceBuildOutput arbo;
            if (!references.TryGetValue(key, out arbo))
            {
                arbo = new ApiReferenceBuildOutput
                {
                    Spec = ApiReferenceBuildOutput.GetSpecNames(GetXref(key), supportedLanguages),
                };
            }
            else
            {
                arbo.Expand(references, supportedLanguages);
            }

            return arbo;
        }
示例#9
0
        public static ApiReferenceBuildOutput GetReferenceViewModel(string key, Dictionary <string, ApiReferenceBuildOutput> references, string[] supportedLanguages)
        {
            if (string.IsNullOrEmpty(key))
            {
                return(null);
            }
            if (!references.TryGetValue(key, out ApiReferenceBuildOutput arbo))
            {
                arbo = new ApiReferenceBuildOutput
                {
                    Spec = ApiReferenceBuildOutput.GetSpecNames(GetXref(key), supportedLanguages),
                };
            }
            else
            {
                arbo.Expand(references, supportedLanguages);
            }

            return(arbo);
        }
示例#10
0
        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;
        }
示例#11
0
        public static ApiReferenceBuildOutput FromModel(ReferenceViewModel vm, string[] supportedLanguages)
        {
            if (vm == null) return null;

            // TODO: may lead to potential problems with have vm.Additional["syntax"] as SyntaxDetailViewModel
            // It is now working as syntax is set only in FillReferenceInformation and not from YAML deserialization
            var result = new ApiReferenceBuildOutput
            {
                Uid = vm.Uid,
                Id = Utility.GetHtmlId(vm.Uid),
                Parent = vm.Parent,
                Definition = vm.Definition,
                IsExternal = vm.IsExternal,
                Href = vm.Href,
                Name = ApiBuildOutputUtility.TransformToLanguagePairList(vm.Name, vm.NameInDevLangs, supportedLanguages),
                NameWithType = ApiBuildOutputUtility.TransformToLanguagePairList(vm.NameWithType, vm.NameWithTypeInDevLangs, supportedLanguages),
                FullName = ApiBuildOutputUtility.TransformToLanguagePairList(vm.FullName, vm.FullNameInDevLangs, supportedLanguages),
                Spec = GetSpecNames(ApiBuildOutputUtility.GetXref(vm.Uid, vm.Name, vm.FullName), supportedLanguages, vm.Specs),
                Metadata = vm.Additional,
            };
            object syntax;
            if (result.Metadata.TryGetValue("syntax", out syntax))
            {
                result.Syntax = ApiSyntaxBuildOutput.FromModel(syntax as SyntaxDetailViewModel, supportedLanguages);
                result.Metadata.Remove("syntax");
            }
            return result;
        }