Beispiel #1
0
        public static object FromStreamContext(Type componentType,
                                               StreamContext streamContext,
                                               Encoding encoding = null)
        {
            if (componentType == null)
            {
                throw new ArgumentNullException("componentType");
            }
            if (streamContext == null)
            {
                throw new ArgumentNullException("streamContext");
            }

            StreamingSource ss = StreamingSource.Create(
                componentType,
                streamContext.ContentType,
                streamContext.Extension
                );

            if (ss == null)
            {
                throw RuntimeFailure.NoAcceptableStreamingSource(componentType);
            }
            if (ss is TextSource text)
            {
                text.Encoding = encoding;
            }

            return(ss.Load(streamContext, componentType));
        }