private void BuildContent(MarkdownBuilder mb, TypeScriptAccessor accessor)
        {
            mb.Header(3, accessor.Name);

            if (accessor.GetSignature != null)
            {
                mb.AppendLine("⇄ " + accessor.GetSignature.Format(_lib));

                mb.AppendLine();

                BuildParameters(mb, accessor.GetSignature.Parameters);

                mb.AppendLine();

                mb.Append($"**Returns** " + accessor.GetSignature.Type.Format(_lib));
                if (!string.IsNullOrEmpty(accessor.GetSignature.Comment?.Returns))
                {
                    mb.Append(" - " + accessor.GetSignature.Comment.Returns);
                }

                mb.AppendLine();
                mb.AppendLine();

                mb.AppendSeparateLine();
            }

            if (accessor.SetSignature != null)
            {
                mb.AppendLine("⇄ " + accessor.SetSignature.Format(_lib));

                mb.AppendLine();

                BuildParameters(mb, accessor.SetSignature.Parameters);

                mb.AppendLine();

                mb.Append($"**Returns** " + accessor.SetSignature.Type.Format(_lib));
                if (!string.IsNullOrEmpty(accessor.SetSignature.Comment?.Returns))
                {
                    mb.Append(" - " + accessor.SetSignature.Comment.Returns);
                }

                mb.AppendLine();
                mb.AppendLine();

                mb.AppendSeparateLine();
            }
        }
Beispiel #2
0
        private void LoadFromJObject(TypeScriptAccessor accessor, JObject jobject)
        {
            if (jobject.TryGetValue("comment", out var commentToken))
            {
                accessor.Comment = new TypeScriptComment();
                LoadFromJObject(accessor.Comment, commentToken.ToObject <JObject>());
            }

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

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

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

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

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

            if (jobject.TryGetValue("getSignature", out var signatureToken))
            {
                accessor.GetSignature = new TypeScriptSignature();
                LoadFromJObject(accessor.GetSignature, signatureToken.ToObject <List <JObject> >().First());
                accessor.GetSignature.Name = $"get {accessor.Name}";
            }

            if (jobject.TryGetValue("setSignature", out signatureToken))
            {
                accessor.SetSignature = new TypeScriptSignature();
                LoadFromJObject(accessor.SetSignature, signatureToken.ToObject <List <JObject> >().First());
                accessor.SetSignature.Name = $"set {accessor.Name}";
            }
        }
Beispiel #3
0
        private void LoadFromJObject(TypeScriptClass @class, JObject jobject)
        {
            if (jobject.TryGetValue("id", out var idToken))
            {
                @class.Id = idToken.ToObject <int>();
            }

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

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

                if (flagsObj.TryGetValue("isExported", out var isExportedToken))
                {
                    @class.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);
                        @class.Properties.Add(property);
                    }
                    else if (childKind == TypeScriptTokenKind.Method)
                    {
                        var method = new TypeScriptMethod();
                        LoadFromJObject(method, child);
                        @class.Methods.Add(method);
                    }
                    else if (childKind == TypeScriptTokenKind.Constructor)
                    {
                        @class.Constructor = new TypeScriptMethod();
                        LoadFromJObject(@class.Constructor, child);
                    }
                    else if (childKind == TypeScriptTokenKind.Accessor)
                    {
                        var accessor = new TypeScriptAccessor();
                        LoadFromJObject(accessor, child);
                        @class.Accessors.Add(accessor);
                    }
                }
            }

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

            if (jobject.TryGetValue("implementedTypes", out var impTypesToken))
            {
                var typeObjs = impTypesToken.ToObject <List <JObject> >();
                foreach (var typeObj in typeObjs)
                {
                    @class.ImplementedTypes.Add(LoadTypeFromJObject(typeObj));
                }
            }

            if (jobject.TryGetValue("extendedTypes", out var exToken))
            {
                var typeObjs = exToken.ToObject <List <JObject> >();
                foreach (var typeObj in typeObjs)
                {
                    @class.ExtendedTypes.Add(LoadTypeFromJObject(typeObj));
                }
            }
        }