예제 #1
0
        private void LoadFromJObject(TypeScriptInterface @interface, JObject jobject)
        {
            if (jobject.TryGetValue("id", out var idTokent))
            {
                @interface.Id = idTokent.ToObject <int>();
            }

            if (jobject.TryGetValue("name", out var nameTokent))
            {
                @interface.Name = nameTokent.ToString();
            }

            if (jobject.TryGetValue("flags", out var flagsToken))
            {
                var flagsObj = flagsToken.ToObject <JObject>();

                if (flagsObj.TryGetValue("isExported", out var isExportedToken))
                {
                    @interface.IsExported = isExportedToken.ToObject <bool>();
                }
            }

            if (jobject.TryGetValue("children", out var childrenToken))
            {
                var children = childrenToken.ToObject <List <JObject> >();

                foreach (var child in children)
                {
                    var childKind = child["kind"].ToObject <TypeScriptTokenKind>();
                    if (childKind == TypeScriptTokenKind.Property)
                    {
                        var property = new TypeScriptProperty();
                        LoadFromJObject(property, child);
                        @interface.Properties.Add(property);
                    }
                    else if (childKind == TypeScriptTokenKind.Method)
                    {
                        var method = new TypeScriptMethod();
                        LoadFromJObject(method, child);
                        @interface.Methods.Add(method);
                    }
                }
            }

            if (jobject.TryGetValue("comment", out var commentToken))
            {
                @interface.Comment = new TypeScriptComment();
                LoadFromJObject(@interface.Comment, commentToken.ToObject <JObject>());
            }

            if (jobject.TryGetValue("extendedTypes", out var extendedTypesToken))
            {
                var typeObjs = extendedTypesToken.ToObject <List <JObject> >();
                foreach (var typeObj in typeObjs)
                {
                    @interface.ExtendedTypes.Add(LoadTypeFromJObject(typeObj));
                }
            }
        }
예제 #2
0
        private void LoadFromJObject(TypeScriptProperty property, JObject jobject)
        {
            if (jobject.TryGetValue("name", out var nameTokent))
            {
                property.Name = nameTokent.ToString();
            }

            if (jobject.TryGetValue("flags", out var flagsToken))
            {
                var flagsObj = flagsToken.ToObject <JObject>();

                if (flagsObj.TryGetValue("isPublic", out var isPublicToken))
                {
                    property.IsPublic = isPublicToken.ToObject <bool>();
                }

                if (flagsObj.TryGetValue("isProtected", out var isProtectedToken))
                {
                    property.IsProtected = isProtectedToken.ToObject <bool>();
                }

                if (flagsObj.TryGetValue("isOptional", out var isOptionalToken))
                {
                    property.IsOptional = isOptionalToken.ToObject <bool>();
                }

                if (flagsObj.TryGetValue("isStatic", out var isStaticToken))
                {
                    property.IsStatic = isStaticToken.ToObject <bool>();
                }

                if (flagsObj.TryGetValue("isPrivate", out var isPrivateToken))
                {
                    property.IsPrivate = isPrivateToken.ToObject <bool>();
                }

                if (jobject.TryGetValue("type", out var typeToken))
                {
                    property.Type = LoadTypeFromJObject(typeToken.ToObject <JObject>());
                }
            }

            if (jobject.TryGetValue("defaultValue", out var defValToken))
            {
                property.DefaultValue = defValToken.ToString();
            }

            if (jobject.TryGetValue("comment", out var commentToken))
            {
                property.Comment = new TypeScriptComment();
                LoadFromJObject(property.Comment, commentToken.ToObject <JObject>());
            }
        }
예제 #3
0
        private void BuildContent(MarkdownBuilder mb, TypeScriptProperty property)
        {
            mb.Header(3, property.Name);

            mb.AppendLine();
            if (!string.IsNullOrEmpty(property.Comment?.ShortText))
            {
                mb.AppendLine(property.Comment.ShortText);
                mb.AppendLine();
            }

            mb.AppendLine(property.Format(_lib));

            BuildExample(mb, property.Comment);

            mb.AppendSeparateLine();
        }