public static BsonType Create(BsonDataType type) { BsonType ret = null; if(type == BsonDataType.Number){ ret = new BsonNumber(); }else if(type == BsonDataType.Number){ throw new NotImplementedException(); }else if(type == BsonDataType.String){ ret = new BsonString(); }else if(type == BsonDataType.Obj){ ret = new BsonDocument(); }else if(type == BsonDataType.Array){ ret = new BsonArray(); }else if(type == BsonDataType.Integer){ ret = new BsonInteger(); }else if(type == BsonDataType.Long){ ret = new BsonLong(); }else if(type == BsonDataType.Boolean){ ret = new BsonBoolean(); }else if(type == BsonDataType.Oid){ ret = new BsonOid(); }else if(type == BsonDataType.Date){ ret = new BsonDate(); }else if(type == BsonDataType.Regex){ ret = new BsonRegex(); }else{ throw new ArgumentOutOfRangeException("Type: " + type + " not recognized"); } return ret; }
public void TestSize() { BsonRegex reg = new BsonRegex("test"); Assert.AreEqual(6,reg.Size); reg = new BsonRegex("test", "option"); Assert.AreEqual(12, reg.Size); }
public void TestFormatting() { BsonRegex reg = new BsonRegex("test"); MemoryStream buf = new MemoryStream(); BsonWriter writer = new BsonWriter(buf); reg.Write(writer); writer.Flush(); Byte[] output = buf.ToArray(); String hexdump = BitConverter.ToString(output); hexdump = hexdump.Replace("-",""); Assert.AreEqual("746573740000",hexdump, "Dump not correct"); }
public static BsonType Create(BsonDataType type) { BsonType ret = null; if(type == BsonDataType.Number){ ret = new BsonNumber(); }else if(type == BsonDataType.Number){ throw new NotImplementedException(); }else if(type == BsonDataType.String){ ret = new BsonString(); }else if(type == BsonDataType.Obj){ ret = new BsonDocument(); }else if(type == BsonDataType.Array){ ret = new BsonArray(); }else if(type == BsonDataType.Integer){ ret = new BsonInteger(); }else if(type == BsonDataType.Long){ ret = new BsonLong(); }else if(type == BsonDataType.Boolean){ ret = new BsonBoolean(); }else if(type == BsonDataType.Oid){ ret = new BsonOid(); }else if(type == BsonDataType.Date){ ret = new BsonDate(); }else if(type == BsonDataType.Regex){ ret = new BsonRegex(); }else if(type == BsonDataType.Undefined){ ret = new BsonUndefined(); }else if(type == BsonDataType.Null){ ret = new BsonNull(); }else if(type == BsonDataType.Code){ ret = new BsonCode(); }else if(type == BsonDataType.CodeWScope){ ret = new BsonCodeWScope(); }else{ string typename = Enum.GetName(typeof(BsonDataType), type); throw new ArgumentOutOfRangeException("type",typename + "is not recognized"); } return ret; }