private static void Read( string content, params RawJson[] raw ) { var sr = new StringReader(content); using( var reader = new JsonReader(sr) ) { Assert.Throws<InvalidOperationException>(() => reader.Token.NotNullReference()); Assert.Throws<InvalidOperationException>(() => reader.RawValue.NotNullReference()); if( raw.NullReference() || raw.Length == 0 ) { Assert.False(reader.Read()); } else { foreach( var r in raw ) { Assert.True(reader.Read()); Assert.AreEqual(r.Token, reader.Token); Test.OrdinalEquals(r.RawValue, reader.RawValue); } Assert.False(reader.Read()); } Assert.False(reader.Read()); Assert.Throws<InvalidOperationException>(() => reader.Token.NotNullReference()); Assert.Throws<InvalidOperationException>(() => reader.RawValue.NotNullReference()); } }
private XmlDataStoreReader( XmlReader xmlReader ) : base() { Ensure.That(xmlReader).NotNull(); this.xmlReader = xmlReader; this.textReader = new IO.StringReader(); }
private JsonDataStoreReader( JsonReader jsonReader, bool isDataStoreJson ) : base() { Ensure.That(jsonReader).NotNull(); this.jsonReader = jsonReader; this.textReader = new IO.StringReader(); this.parents = new Stack<ParentInfo>(); this.isDataStoreJson = isDataStoreJson; }
private static void Read( CsvFormat csvFormat, string content, params Action<Substring[]>[] actions ) { var sr = new StringReader(content); using( var reader = new CsvReader(sr, csvFormat) ) { foreach( var a in actions ) { Assert.True(reader.Read()); Assert.NotNull(reader.Record); a(reader.Record.ToArray()); } Assert.False(reader.Read()); } }
/// <summary> /// Called when the object is being disposed of. Inheritors must call base.OnDispose to be properly disposed. /// </summary> /// <param name="disposing">If set to <c>true</c>, release both managed and unmanaged resources; otherwise release only the unmanaged resources.</param> protected override void OnDispose( bool disposing ) { if( disposing ) { //// dispose-only (i.e. non-finalizable) logic //// (managed, disposable resources you own) if( this.xmlReader.NotNullReference() ) { this.xmlReader.Close(); this.xmlReader = null; } } //// shared cleanup logic //// (unmanaged resources) this.currentValue = null; this.textReader = null; base.OnDispose(disposing); }
/// <summary> /// Initializes a new instance of the <see cref="JsonDataStoreReader"/> class. /// </summary> /// <param name="json">The JSON content to parse.</param> /// <param name="isDataStoreJson">Determines whether the JSON content was produced by a data store, or elsewhere.</param> /// <returns>A new instance of the <see cref="JsonDataStoreReader"/> class.</returns> public static JsonDataStoreReader FromJson( string json, bool isDataStoreJson ) { var reader = new Mechanical.IO.StringReader(); reader.Set(json); return new JsonDataStoreReader(reader, isDataStoreJson); }