/// <summary>
        /// Get the payload value converter
        /// </summary>
        /// <param name="model">The instance to get the value payload converter from.</param>
        /// <returns>The payload value converter</returns>
        public static ODataPayloadValueConverter GetPayloadValueConverter(this IEdmModel model)
        {
            ExceptionUtils.CheckArgumentNotNull(model, "model");

            // Get payload value converter for the model.
            ODataPayloadValueConverter converter = model.GetAnnotationValue(
                model,
                Metadata.EdmConstants.InternalUri,
                Metadata.EdmConstants.PayloadValueConverterAnnotation)
                                                   as ODataPayloadValueConverter;

            return(converter ?? ODataPayloadValueConverter.Default);
        }
Exemple #2
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="format">The format for this input context.</param>
        /// <param name="messageReaderSettings">Configuration settings of the OData reader.</param>
        /// <param name="readingResponse">true if reading a response message; otherwise false.</param>
        /// <param name="synchronous">true if the input should be read synchronously; false if it should be read asynchronously.</param>
        /// <param name="model">The model to use.</param>
        /// <param name="urlResolver">The optional URL resolver to perform custom URL resolution for URLs read from the payload.</param>
        protected ODataInputContext(
            ODataFormat format,
            ODataMessageReaderSettings messageReaderSettings,
            bool readingResponse,
            bool synchronous,
            IEdmModel model,
            IODataUrlResolver urlResolver)
        {
            ExceptionUtils.CheckArgumentNotNull(format, "format");
            ExceptionUtils.CheckArgumentNotNull(messageReaderSettings, "messageReaderSettings");

            this.format = format;
            this.messageReaderSettings = messageReaderSettings;
            this.readingResponse       = readingResponse;
            this.synchronous           = synchronous;
            this.model                 = model ?? EdmCoreModel.Instance;
            this.urlResolver           = urlResolver;
            this.edmTypeResolver       = new EdmTypeReaderResolver(this.Model, this.MessageReaderSettings.ReaderBehavior);
            this.payloadValueConverter = this.model.GetPayloadValueConverter();
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="format">The format for this output context.</param>
        /// <param name="messageWriterSettings">Configuration settings of the OData writer.</param>
        /// <param name="writingResponse">true if writing a response message; otherwise false.</param>
        /// <param name="synchronous">true if the output should be written synchronously; false if it should be written asynchronously.</param>
        /// <param name="model">The model to use.</param>
        /// <param name="urlResolver">The optional URL resolver to perform custom URL resolution for URLs written to the payload.</param>
        protected ODataOutputContext(
            ODataFormat format,
            ODataMessageWriterSettings messageWriterSettings,
            bool writingResponse,
            bool synchronous,
            IEdmModel model,
            IODataUrlResolver urlResolver)
        {
            ExceptionUtils.CheckArgumentNotNull(format, "format");
            ExceptionUtils.CheckArgumentNotNull(messageWriterSettings, "messageWriterSettings");

            this.format = format;
            this.messageWriterSettings = messageWriterSettings;
            this.writingResponse = writingResponse;
            this.synchronous = synchronous;
            this.model = model ?? EdmCoreModel.Instance;
            this.urlResolver = urlResolver;
            this.edmTypeResolver = EdmTypeWriterResolver.Instance;
            this.payloadValueConverter = this.model.GetPayloadValueConverter();
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="format">The format for this output context.</param>
        /// <param name="messageWriterSettings">Configuration settings of the OData writer.</param>
        /// <param name="writingResponse">true if writing a response message; otherwise false.</param>
        /// <param name="synchronous">true if the output should be written synchronously; false if it should be written asynchronously.</param>
        /// <param name="model">The model to use.</param>
        /// <param name="urlResolver">The optional URL resolver to perform custom URL resolution for URLs written to the payload.</param>
        protected ODataOutputContext(
            ODataFormat format,
            ODataMessageWriterSettings messageWriterSettings,
            bool writingResponse,
            bool synchronous,
            IEdmModel model,
            IODataUrlResolver urlResolver)
        {
            ExceptionUtils.CheckArgumentNotNull(format, "format");
            ExceptionUtils.CheckArgumentNotNull(messageWriterSettings, "messageWriterSettings");

            this.format = format;
            this.messageWriterSettings = messageWriterSettings;
            this.writingResponse       = writingResponse;
            this.synchronous           = synchronous;
            this.model                 = model ?? EdmCoreModel.Instance;
            this.urlResolver           = urlResolver;
            this.edmTypeResolver       = EdmTypeWriterResolver.Instance;
            this.payloadValueConverter = this.model.GetPayloadValueConverter();
            this.writerValidator       = ValidatorFactory.CreateWriterValidator(messageWriterSettings.EnableFullValidation);
        }
        /// <summary>
        /// Set the payload value converter
        /// </summary>
        /// <param name="model">The instance to set the value payload converter.</param>
        /// <param name="converter">The payload value converter to set.</param>
        public static void SetPayloadValueConverter(this IEdmModel model, ODataPayloadValueConverter converter)
        {
            ExceptionUtils.CheckArgumentNotNull(model, "model");
            ExceptionUtils.CheckArgumentNotNull(converter, "converter");

            // Set payload value converter for the model.
            model.SetAnnotationValue(
                model,
                Metadata.EdmConstants.InternalUri,
                Metadata.EdmConstants.PayloadValueConverterAnnotation,
                converter);
        }