Exemplo n.º 1
0
        private static JObject MakeFrameObject(JsonLdEmbed embed, bool explicitFlag, bool requireAll)
        {
            var ret = new JObject(
                new JProperty("@embed", JsonLdEmbedAsString(embed)),
                new JProperty("@explicit", explicitFlag),
                new JProperty("@requireAll", requireAll));

            return(ret);
        }
Exemplo n.º 2
0
        private static JsonLdEmbed GetEmbedOption(JObject frame, JsonLdEmbed defaultValue, JsonLdProcessingMode processingMode)
        {
            if (frame["@embed"] != null)
            {
                var embedString = frame["@embed"] is JObject
                    ? frame["@embed"]["@value"].Value <string>()
                    : frame["@embed"].Value <string>();
                switch (embedString.ToLowerInvariant())
                {
                case "@always":
                    return(JsonLdEmbed.Always);

                case "true":
                case "@once":
                    return(JsonLdEmbed.Once);

                case "@first" when processingMode == JsonLdProcessingMode.JsonLd10:
                    return(JsonLdEmbed.First);

                case "@last" when processingMode == JsonLdProcessingMode.JsonLd10:
                    return(JsonLdEmbed.Last);

                case "@link" when processingMode == JsonLdProcessingMode.JsonLd10:
                    return(JsonLdEmbed.Link);

                case "@first":
                case "@last":
                case "@link":
                    throw new JsonLdProcessorException(JsonLdErrorCode.InvalidEmbedValue,
                                                       $"Invalid @embed value {embedString}. This value is only valid if the processing mode is JSON-LD 1.0.");

                case "false":
                case "@never":
                    return(JsonLdEmbed.Never);

                default:
                    throw new JsonLdProcessorException(JsonLdErrorCode.InvalidEmbedValue,
                                                       $"Invalid @embed value {embedString}");
                }
            }
            return(defaultValue);
        }
Exemplo n.º 3
0
        private static string JsonLdEmbedAsString(JsonLdEmbed embed)
        {
            switch (embed)
            {
            case JsonLdEmbed.Always:
                return("@always");

            case JsonLdEmbed.Once:
                return("@once");

            case JsonLdEmbed.Last:
                return("@last");

            case JsonLdEmbed.Link:
                return("@link");

            case JsonLdEmbed.Never:
                return("@never");

            default:
                return(null);
            }
        }