コード例 #1
0
        public static CodeBlock ResourceDocument(
            CompilerContext compilerContext,
            CodeGenerationContext codeGenContext)
        {
            var contextUri = StringMethods.Concat(codeGenContext.BaseUri, New.Const(CompilerContext.ContextUri));

            var rootNode = WriteNode(
                compilerContext,
                codeGenContext,
                new[]
            {
                WriteContext(codeGenContext.JsonWriter, contextUri)
            });

            return(new CodeBlock(
                       codeGenContext.JsonWriter.WriteBeginObject(),
                       rootNode,
                       codeGenContext.JsonWriter.WriteEndObject()
                       ));
        }
コード例 #2
0
        public static CodeBlock ResourceDocument(
            Variable <JsonWriter> jsonWriter,
            ResourceModel model,
            Expression resource,
            Variable <SerializationContext> options,
            IMetaModelRepository models)
        {
            var uriGenerator  = options.get_UriGenerator();
            var typeGenerator = options.get_TypeGenerator();
            var baseUri       = options.get_BaseUri().ObjectToString();
            var contextUri    = StringMethods.Concat(baseUri, New.Const(".hydra/context.jsonld"));

            var jsonFormatterResolver = New.Var <HydraJsonFormatterResolver>("resolver");
            var assignResolver        = jsonFormatterResolver.Assign(New.Instance <HydraJsonFormatterResolver>());

            var rootNode = WriteNode(
                jsonWriter,
                baseUri,
                model,
                resource,
                uriGenerator,
                typeGenerator,
                models,
                jsonFormatterResolver,
                new[]
            {
                WriteContext(jsonWriter, contextUri)
            });

            return(new CodeBlock(
                       jsonFormatterResolver,
                       assignResolver,
                       jsonWriter.WriteBeginObject(),
                       rootNode,
                       jsonWriter.WriteEndObject()
                       ));
        }