예제 #1
0
 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;
 }
예제 #2
0
        public void TestSize()
        {
            BsonRegex reg = new BsonRegex("test");
            Assert.AreEqual(6,reg.Size);

            reg = new BsonRegex("test", "option");
            Assert.AreEqual(12, reg.Size);
        }
예제 #3
0
 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");
 }
예제 #4
0
 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;
 }