Exemple #1
0
        private static void FlattenTreeInternal(List <SKEMAObject> result, SKEMAObject skema, bool skipOptional)
        {
            result.Add(skema);

            switch (skema.Type)
            {
            case SKEMAType.REFERENCE:
                if (skema.ReferenceSKEMA != null)
                {
                    if (result.Contains(skema.ReferenceSKEMA) == false)
                    {
                        FlattenTreeInternal(result, skema.ReferenceSKEMA, skipOptional);
                    }
                }
                break;

            case SKEMAType.ANY:
            case SKEMAType.STRING:
            case SKEMAType.INTEGER:
            case SKEMAType.FLOAT:
            case SKEMAType.BOOLEAN:
            case SKEMAType.DATETIME:
                break;

            case SKEMAType.MAP:
                foreach (string key in skema.Keys)
                {
                    if (skipOptional && skema.IsOptional(key) == true)
                    {
                        //Console.WriteLine("Key " + key + " is optional. Skipping!");
                        continue;
                    }

                    if (result.Contains(skema[key]) == false)
                    {
                        FlattenTreeInternal(result, skema[key], skipOptional);
                    }
                }
                break;

            case SKEMAType.ARRAY:
                if (skema.ArrayElementSKEMA != null)
                {
                    if (result.Contains(skema.ArrayElementSKEMA) == false)
                    {
                        FlattenTreeInternal(result, skema.ArrayElementSKEMA, skipOptional);
                    }
                }
                break;

            default:
                break;
            }
        }
Exemple #2
0
        /// <summary>
        /// Writes a SKEMAObject value.
        /// </summary>
        /// <param name="obj">The object to write.</param>
        /// <param name="indent">The amount of indentation.</param>
        /// <returns>A string to write into a file.</returns>
        private static string WriteObject(SKEMAObject obj, int indent)
        {
            if (obj == null)
            {
                return(string.Empty);
            }

            string indentString = string.Empty;

            for (int i = 0; i < indent; i++)
            {
                indentString += SKON.IndentString;
            }

            switch (obj.Type)
            {
            case SKEMAType.REFERENCE:
                return("#" + obj.Reference);

            case SKEMAType.ANY:
                return("Any");

            case SKEMAType.STRING:
                return("String");

            case SKEMAType.INTEGER:
                return("Integer");

            case SKEMAType.FLOAT:
                return("Float");

            case SKEMAType.BOOLEAN:
                return("Boolean");

            case SKEMAType.DATETIME:
                return("DateTime");

            case SKEMAType.MAP:
                StringBuilder mapsb = new StringBuilder();

                if (obj.Keys.Count <= 0)
                {
                    mapsb.Append("{  }");
                    return(mapsb.ToString());
                }

                mapsb.Append("\n" + indentString + "{\n");

                foreach (string key in obj.Keys)
                {
                    mapsb.Append(indentString + SKON.IndentString + (obj.IsOptional(key) ? "optional " : "") + $"{key}: {WriteObject(obj[key], indent + 1)},\n");
                }

                mapsb.Append(indentString + "}");

                return(mapsb.ToString());

            case SKEMAType.ARRAY:
                if (obj.ArrayElementSKEMA == null)
                {
                    return("[  ]");
                }
                return("\n" +
                       indentString + "[" + ((obj.ArrayElementSKEMA.Type != SKEMAType.MAP && obj.ArrayElementSKEMA.Type != SKEMAType.ARRAY) ? "\n" : "") +
                       indentString + SKON.IndentString + WriteObject(obj.ArrayElementSKEMA, indent + 1) + "\n" +
                       indentString + "]");

            default:
                return(null);
            }
        }