Exemple #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));
        }
Exemple #2
0
        public override object Load(StreamContext inputSource,
                                    Type instanceType)
        {
            if (instanceType == null)
            {
                throw new ArgumentNullException("instanceType");
            }

            return(Activation.FromStreamContext(instanceType, inputSource));
        }
        public override StreamContext ChangePath(string relativePath)
        {
            if (relativePath == null)
            {
                throw new ArgumentNullException(nameof(relativePath));
            }

            UriBuilder baseUri = new UriBuilder(new Uri(_uri, relativePath));

            return(StreamContext.FromSource(baseUri.Uri));
        }
Exemple #4
0
        public void Load(StreamContext streamContext, Encoding encoding)
        {
            if (streamContext == null)
            {
                throw new ArgumentNullException("streamContext");
            }

            using (PropertiesReader pr = new PropertiesReader(streamContext, encoding)) {
                LoadCore(pr);
            }
        }
Exemple #5
0
 public void Load(string fileName)
 {
     if (fileName == null)
     {
         throw new ArgumentNullException("fileName");
     }
     using (PropertiesReader pr = new PropertiesReader(
                StreamContext.FromFile(fileName))) {
         LoadCore(pr);
     }
 }
        public static Properties FromStreamContext(StreamContext source, Encoding encoding = null)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            Properties p = new Properties();

            p.Load(source.OpenRead(), encoding);
            return(p);
        }
Exemple #7
0
        public override object Load(StreamContext inputSource,
                                    Type instanceType)
        {
            if (inputSource == null)
            {
                throw new ArgumentNullException("inputSource");
            }

            using (StreamReader sr = inputSource.OpenText()) {
                return(Load(sr, instanceType));
            }
        }
Exemple #8
0
        // TODO Needs work -- we want there to be as much fallback as
        // possible with parsing and stream loading.  Also probably
        // get encoding from content type

        public static object FromFile(Type componentType, string fileName)
        {
            if (componentType == null)
            {
                throw new ArgumentNullException("componentType");
            }
            if (string.IsNullOrEmpty(fileName))
            {
                throw Failure.NullOrEmptyString(nameof(fileName));
            }

            return(FromStreamContext(componentType, StreamContext.FromFile(fileName)));
        }
Exemple #9
0
        public override void Save(StreamContext outputTarget,
                                  object value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            string     text   = value.ToString();
            TextWriter writer = outputTarget.AppendText();

            writer.Write(text);
        }
Exemple #10
0
        public static object FromStream(Type instanceType, Stream stream, Encoding encoding = null)
        {
            if (instanceType == null)
            {
                throw new ArgumentNullException("instanceType");
            }
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            return(FromStreamContext(instanceType, StreamContext.FromStream(stream), encoding));
        }
Exemple #11
0
        public static object FromSource(Type componentType, Uri uri)
        {
            if (componentType == null)
            {
                throw new ArgumentNullException("componentType");
            }
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }

            return(FromStreamContext(componentType, StreamContext.FromSource(uri)));
        }
Exemple #12
0
        public virtual void Load(StreamContext inputSource, object instance)
        {
            if (inputSource == null)
            {
                throw new ArgumentNullException("inputSource");
            }
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }

            LoadByHydration(inputSource, instance);
        }
Exemple #13
0
        public override void Save(StreamContext outputTarget,
                                  object value)
        {
            if (outputTarget == null)
            {
                throw new ArgumentNullException("outputTarget");
            }
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            using (StreamWriter sw = outputTarget.AppendText(Encoding)) {
                Save(sw, value);
            }
        }
Exemple #14
0
        public override void Load(StreamContext inputSource, object instance)
        {
            if (inputSource == null)
            {
                throw new ArgumentNullException("inputSource");
            }
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }
            if (!(instance is IProperties))
            {
                throw Failure.NotInstanceOf("instance", instance, typeof(IProperties));
            }

            var props = (Properties)Load(inputSource, typeof(Properties));

            props.CopyTo((IProperties)instance);
        }
Exemple #15
0
 public abstract object Load(StreamContext inputSource, Type instanceType);
Exemple #16
0
 public abstract void Save(StreamContext outputTarget, object value);
Exemple #17
0
 public static T FromStreamContext <T>(StreamContext streamContext)
 {
     return((T)FromStreamContext(typeof(T), streamContext));
 }
 public PropertiesReader(StreamContext source, Encoding encoding = null)
 {
     BaseReader = source.OpenText(encoding);
 }
Exemple #19
0
 internal virtual object LoadFromText(string text, Type componentType)
 {
     return(Load(StreamContext.FromText(text), componentType));
 }
Exemple #20
0
        internal void LoadByHydration(StreamContext inputSource, object instance)
        {
            var copyFrom = Load(inputSource, instance.GetType());

            Template.Copy(copyFrom, instance);
        }