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)); }
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)); }
public void Load(StreamContext streamContext, Encoding encoding) { if (streamContext == null) { throw new ArgumentNullException("streamContext"); } using (PropertiesReader pr = new PropertiesReader(streamContext, encoding)) { LoadCore(pr); } }
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); }
public override object Load(StreamContext inputSource, Type instanceType) { if (inputSource == null) { throw new ArgumentNullException("inputSource"); } using (StreamReader sr = inputSource.OpenText()) { return(Load(sr, instanceType)); } }
// 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))); }
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); }
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)); }
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))); }
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); }
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); } }
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); }
public abstract object Load(StreamContext inputSource, Type instanceType);
public abstract void Save(StreamContext outputTarget, object value);
public static T FromStreamContext <T>(StreamContext streamContext) { return((T)FromStreamContext(typeof(T), streamContext)); }
public PropertiesReader(StreamContext source, Encoding encoding = null) { BaseReader = source.OpenText(encoding); }
internal virtual object LoadFromText(string text, Type componentType) { return(Load(StreamContext.FromText(text), componentType)); }
internal void LoadByHydration(StreamContext inputSource, object instance) { var copyFrom = Load(inputSource, instance.GetType()); Template.Copy(copyFrom, instance); }