private void CreateCoreObject(OPathSegment lastSegment, Block codeHeaderBlock, Dictionary <object, object> currentObject, MarkdownDocument propertyValue, string originalOPathString)
        {
            if (currentObject.TryGetValue(lastSegment.SegmentName, out object value))
            {
                if (value is MarkdownDocument)
                {
                    // Duplicate OPath in markdown section
                    Logger.LogWarning(
                        $"There are two duplicate OPaths `{originalOPathString}`, the previous one will be overwritten.",
                        line: codeHeaderBlock.Line.ToString(),
                        code: WarningCodes.Overwrite.InvalidMarkdownFragments);
                }
                else if (value is Dictionary <object, object> || value is List <object> )
                {
                    throw new MarkdownFragmentsException(
                              $"A({lastSegment.SegmentName}) is expected to be a dictionary like \"A/B\" or an array of dictionaries like \"A[c=d]/C\", however it is used as an array of Blocks in line {codeHeaderBlock.Line} like \"../A\" OPath syntax",
                              codeHeaderBlock.Line);
                }
                else
                {
                    // Duplicate OPath in yaml section and markdown section
                    Logger.LogWarning(
                        $"Two duplicate OPaths `{originalOPathString}` in yaml code block and contents block",
                        line: codeHeaderBlock.Line.ToString(),
                        code: WarningCodes.Overwrite.InvalidMarkdownFragments);
                }
            }

            currentObject[lastSegment.SegmentName] = propertyValue;
        }
        private static List <object> CreateDictionaryArrayObject(OPathSegment segment)
        {
            var newObject = new List <object>
            {
                new Dictionary <object, object>
                {
                    { segment.Key, segment.Value }
                }
            };

            return(newObject);
        }
Exemplo n.º 3
0
        private static void CreateCoreObject(OPathSegment lastSegment, Block codeHeaderBlock, Dictionary <string, object> currentObject, List <Block> propertyValue, string originalOPathString)
        {
            if (currentObject.TryGetValue(lastSegment.SegmentName, out object value))
            {
                if (value is MarkdownDocument)
                {
                    // Duplicate
                    Logger.LogWarning(
                        $"There are two duplicate OPaths {originalOPathString}, the previous one will be overwritten",
                        line: codeHeaderBlock.Line.ToString(),
                        code: WarningCodes.Overwrite.InvalidOPaths);
                }
                else
                {
                    throw new MarkdownFragmentsException(
                              $"A({lastSegment.SegmentName}) is expected to be an dictionary like \"A/B\" or an array of dictionaries like \"A[c=d]/C\", however it is used as an array of Blocks in line {codeHeaderBlock.Line} like \"../A\" OPath syntax",
                              codeHeaderBlock.Line);
                }
            }

            currentObject[lastSegment.SegmentName] = CreateDocument(propertyValue);
        }
Exemplo n.º 4
0
 private static Dictionary <string, object> CreateDictionaryObject(OPathSegment segment)
 {
     return(new Dictionary <string, object>());
 }