Example #1
0
        private string SerializeProperty(ODataProperty odataProperty)
        {
            MemoryStream           outputStream      = new MemoryStream();
            ODataAtomOutputContext atomOutputContext = this.CreateAtomOutputContext(this.model, outputStream);
            var serializer = new ODataAtomPropertyAndValueSerializer(atomOutputContext);

            serializer.WriteTopLevelProperty(odataProperty);
            atomOutputContext.Flush();
            outputStream.Position = 0;
            string result = new StreamReader(outputStream).ReadToEnd();

            return(result);
        }
        private string SerializePropertyWithOwningType(EdmModel model, IEdmStructuredType owningType, ODataProperty odataProperty)
        {
            MemoryStream           outputStream      = new MemoryStream();
            ODataAtomOutputContext atomOutputContext = this.CreateAtomOutputContext(model, outputStream);
            var serializer = new ODataAtomPropertyAndValueSerializer(atomOutputContext);

            serializer.WritePayloadStart();
            serializer.WriteProperties(
                owningType,
                new[] { odataProperty },
                /*isWritingCollection*/ false,
                null,
                null,
                new DuplicatePropertyNamesChecker(allowDuplicateProperties: true, isResponse: true),
                ProjectedPropertiesAnnotation.AllProjectedPropertiesInstance
                );
            serializer.WritePayloadEnd();

            atomOutputContext.Flush();
            outputStream.Position = 0;
            string result = new StreamReader(outputStream).ReadToEnd();

            return(result);
        }