/// <summary> /// Reads a BsonDocument from a file. /// </summary> /// <param name="filename">The name of the file.</param> /// <returns>A BsonDocument.</returns> public static BsonDocument ReadFrom( string filename ) { FileStream stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.None); using (BsonReader bsonReader = BsonReader.Create(stream)) { return(ReadFrom(bsonReader)); } }
/// <summary> /// Reads a BsonDocument from a byte array. /// </summary> /// <param name="bytes">The byte array.</param> /// <returns>A BsonDocument.</returns> public static BsonDocument ReadFrom( byte[] bytes ) { MemoryStream stream = new MemoryStream(bytes); using (BsonReader bsonReader = BsonReader.Create(stream)) { return(ReadFrom(bsonReader)); } }
public static BsonValue ToBsonValue(this string valueInJsonFormat) { if (string.IsNullOrWhiteSpace(valueInJsonFormat)) { return(BsonNull.Value); } try { using (var reader = BsonReader.Create(valueInJsonFormat)) { return(BsonValue.ReadFrom(reader)); } } catch (Exception e) { string text = String.Format(Messages.InvalidJsonValue, valueInJsonFormat ?? "is null"); throw new ArgumentException(text, "valueInJsonFormat", e); } }