Browse files

Rename BsonDataType to BsonType which is more simpler.

  • Loading branch information...
1 parent 7c7986a commit 6d7a4df469340961c59c0893422ef73b110fc7cd @lanwin lanwin committed Apr 30, 2010
View
6 source/MongoDB.Tests/UnitTests/Bson/TestBsonWriter.cs
@@ -75,7 +75,7 @@ public class TestBsonWriter : BsonTestBase
var writer = new BsonWriter(ms, new BsonDocumentDescriptor());
var str = new[] {"a", "b", "c"};
- writer.WriteValue(BsonDataType.Array, str);
+ writer.WriteValue(BsonType.Array, str);
var hexdump = BitConverter.ToString(ms.ToArray());
hexdump = hexdump.Replace("-", "");
@@ -160,7 +160,7 @@ public void TestLocalDateTimeIsWrittenAsUtcTime()
BsonWriter writer = new BsonWriter(ms, new BsonDocumentDescriptor());
Single val = Single.MaxValue;
- writer.WriteValue(BsonDataType.Number, val);
+ writer.WriteValue(BsonType.Number, val);
string hexdump = BitConverter.ToString(ms.ToArray());
hexdump = hexdump.Replace("-","");
@@ -177,7 +177,7 @@ public void TestLocalDateTimeIsWrittenAsUtcTime()
BsonWriter writer = new BsonWriter(ms, new BsonDocumentDescriptor());
MongoSymbol val = "symbol";
Assert.IsTrue(String.IsInterned(val) != null);
- writer.WriteValue(BsonDataType.Symbol, val);
+ writer.WriteValue(BsonType.Symbol, val);
string hexdump = BitConverter.ToString(ms.ToArray()).Replace("-","");
Assert.AreEqual(expected, hexdump);
View
4 source/MongoDB.Tests/UnitTests/TestOp.cs
@@ -134,9 +134,9 @@ public void NotExists()
[Test]
public void Type()
{
- var op = Op.Type(BsonDataType.Boolean);
+ var op = Op.Type(BsonType.Boolean);
- Assert.AreEqual((int)BsonDataType.Boolean, op["$type"]);
+ Assert.AreEqual((int)BsonType.Boolean, op["$type"]);
}
[Test]
View
38 source/MongoDB/Bson/BsonReader.cs
@@ -125,46 +125,46 @@ public BsonReader(Stream stream, BsonReaderSettings settings)
/// <param name="typeNumber">The type number.</param>
/// <returns></returns>
public Object ReadElementType(int typeNumber){
- switch((BsonDataType)typeNumber){
- case BsonDataType.Null:
- case BsonDataType.Undefined:
+ switch((BsonType)typeNumber){
+ case BsonType.Null:
+ case BsonType.Undefined:
return null;
- case BsonDataType.MinKey:
+ case BsonType.MinKey:
return MongoMinKey.Value;
- case BsonDataType.MaxKey:
+ case BsonType.MaxKey:
return MongoMaxKey.Value;
- case BsonDataType.Boolean:
+ case BsonType.Boolean:
Position++;
return _reader.ReadBoolean();
- case BsonDataType.Integer:
+ case BsonType.Integer:
Position += 4;
return _reader.ReadInt32();
- case BsonDataType.Long:
+ case BsonType.Long:
Position += 8;
return _reader.ReadInt64();
- case BsonDataType.Date:
+ case BsonType.Date:
return ReadDateTime();
- case BsonDataType.Oid:
+ case BsonType.Oid:
Position += 12;
return new Oid(_reader.ReadBytes(12));
- case BsonDataType.Number:
+ case BsonType.Number:
Position += 8;
return _reader.ReadDouble();
- case BsonDataType.String:
+ case BsonType.String:
return ReadLengthString();
- case BsonDataType.Symbol:
+ case BsonType.Symbol:
return new MongoSymbol(ReadLengthString());
- case BsonDataType.Obj:
+ case BsonType.Obj:
return ReadObject();
- case BsonDataType.Array:
+ case BsonType.Array:
return ReadArray();
- case BsonDataType.Regex:
+ case BsonType.Regex:
return ReadRegex();
- case BsonDataType.Code:
+ case BsonType.Code:
return ReadCode();
- case BsonDataType.CodeWScope:
+ case BsonType.CodeWScope:
return ReadScope();
- case BsonDataType.Binary:
+ case BsonType.Binary:
return ReadBinary();
default:
throw new ArgumentOutOfRangeException(String.Format("Type Number: {0} not recognized", typeNumber));
View
2 source/MongoDB/Bson/BsonDataType.cs → source/MongoDB/Bson/BsonType.cs
@@ -3,7 +3,7 @@ namespace MongoDB.Bson
/// <summary>
///
/// </summary>
- public enum BsonDataType
+ public enum BsonType
{
/// <summary>
///
View
126 source/MongoDB/Bson/BsonWriter.cs
@@ -49,62 +49,62 @@ public class BsonWriter
/// <summary>
/// Writes the value.
/// </summary>
- /// <param name="dataType">Type of the data.</param>
+ /// <param name="type">Type of the data.</param>
/// <param name="obj">The obj.</param>
- public void WriteValue(BsonDataType dataType, Object obj){
- switch(dataType){
- case BsonDataType.MinKey:
- case BsonDataType.MaxKey:
- case BsonDataType.Null:
+ public void WriteValue(BsonType type, Object obj){
+ switch(type){
+ case BsonType.MinKey:
+ case BsonType.MaxKey:
+ case BsonType.Null:
return;
- case BsonDataType.Boolean:
+ case BsonType.Boolean:
_writer.Write((bool)obj);
return;
- case BsonDataType.Integer:
+ case BsonType.Integer:
_writer.Write((int)obj);
return;
- case BsonDataType.Long:
+ case BsonType.Long:
_writer.Write((long)obj);
return;
- case BsonDataType.Date:
+ case BsonType.Date:
Write((DateTime)obj);
return;
- case BsonDataType.Oid:
+ case BsonType.Oid:
Write((Oid)obj);
return;
- case BsonDataType.Number:
+ case BsonType.Number:
_writer.Write(Convert.ToDouble(obj));
return;
- case BsonDataType.String:{
+ case BsonType.String:{
Write((String)obj);
return;
}
- case BsonDataType.Obj:
+ case BsonType.Obj:
if(obj is DBRef)
Write((DBRef)obj);
else
WriteObject(obj);
return;
- case BsonDataType.Array:
+ case BsonType.Array:
WriteArray((IEnumerable)obj);
return;
- case BsonDataType.Regex:{
+ case BsonType.Regex:{
Write((MongoRegex)obj);
return;
}
- case BsonDataType.Code:{
+ case BsonType.Code:{
Write((Code)obj);
return;
}
- case BsonDataType.Symbol:{
- this.WriteValue(BsonDataType.String, ((MongoSymbol)obj).Value);
+ case BsonType.Symbol:{
+ this.WriteValue(BsonType.String, ((MongoSymbol)obj).Value);
return;
}
- case BsonDataType.CodeWScope:{
+ case BsonType.CodeWScope:{
Write((CodeWScope)obj);
return;
}
- case BsonDataType.Binary:{
+ case BsonType.Binary:{
if(obj is Guid)
Write((Guid)obj);
else
@@ -157,16 +157,16 @@ public class BsonWriter
/// <param name="codeScope">The code scope.</param>
private void Write(CodeWScope codeScope){
_writer.Write(CalculateSize(codeScope));
- WriteValue(BsonDataType.String, codeScope.Value);
- WriteValue(BsonDataType.Obj, codeScope.Scope);
+ WriteValue(BsonType.String, codeScope.Value);
+ WriteValue(BsonType.Obj, codeScope.Scope);
}
/// <summary>
/// Writes the specified code.
/// </summary>
/// <param name="code">The code.</param>
private void Write(Code code){
- WriteValue(BsonDataType.String, code.Value);
+ WriteValue(BsonType.String, code.Value);
}
/// <summary>
@@ -283,44 +283,44 @@ private void Write(string value)
return 0;
switch(TranslateToBsonType(obj)){
- case BsonDataType.MinKey:
- case BsonDataType.MaxKey:
- case BsonDataType.Null:
+ case BsonType.MinKey:
+ case BsonType.MaxKey:
+ case BsonType.Null:
return 0;
- case BsonDataType.Boolean:
+ case BsonType.Boolean:
return 1;
- case BsonDataType.Integer:
+ case BsonType.Integer:
return 4;
- case BsonDataType.Long:
- case BsonDataType.Date:
+ case BsonType.Long:
+ case BsonType.Date:
return 8;
- case BsonDataType.Oid:
+ case BsonType.Oid:
return 12;
- case BsonDataType.Number:
+ case BsonType.Number:
return sizeof(Double);
- case BsonDataType.String:
+ case BsonType.String:
return CalculateSize((string)obj);
- case BsonDataType.Obj:{
+ case BsonType.Obj:{
if(obj.GetType() == typeof(DBRef))
return CalculateSize((DBRef)obj);
return CalculateSizeObject(obj);
}
- case BsonDataType.Array:
+ case BsonType.Array:
return CalculateSize((IEnumerable)obj);
- case BsonDataType.Regex:{
+ case BsonType.Regex:{
return CalculateSize((MongoRegex)obj);
}
- case BsonDataType.Code:
+ case BsonType.Code:
return CalculateSize((Code)obj);
- case BsonDataType.CodeWScope:{
+ case BsonType.CodeWScope:{
return CalculateSize((CodeWScope)obj);
}
- case BsonDataType.Binary:{
+ case BsonType.Binary:{
if(obj is Guid)
return CalculateSize((Guid)obj);
return CalculateSize((Binary)obj);
}
- case BsonDataType.Symbol:{
+ case BsonType.Symbol:{
MongoSymbol s = (MongoSymbol)obj;
return CalculateSize(s.Value,true);
}
@@ -483,56 +483,56 @@ private int CalculateSizeObject(object obj, IEnumerable<BsonProperty> propertys)
/// </summary>
/// <param name="obj">The obj.</param>
/// <returns></returns>
- protected BsonDataType TranslateToBsonType(object obj){
+ protected BsonType TranslateToBsonType(object obj){
//TODO:Convert to use a dictionary
if(obj == null)
- return BsonDataType.Null;
+ return BsonType.Null;
var type = obj.GetType();
if(obj is Enum) //special case enums
type = Enum.GetUnderlyingType(type);
if(type == typeof(Double))
- return BsonDataType.Number;
+ return BsonType.Number;
if(type == typeof(Single))
- return BsonDataType.Number;
+ return BsonType.Number;
if(type == typeof(String))
- return BsonDataType.String;
+ return BsonType.String;
if(type == typeof(int))
- return BsonDataType.Integer;
+ return BsonType.Integer;
if(type == typeof(long))
- return BsonDataType.Long;
+ return BsonType.Long;
if(type == typeof(bool))
- return BsonDataType.Boolean;
+ return BsonType.Boolean;
if(type == typeof(Oid))
- return BsonDataType.Oid;
+ return BsonType.Oid;
if(type == typeof(DateTime))
- return BsonDataType.Date;
+ return BsonType.Date;
if(type == typeof(MongoRegex))
- return BsonDataType.Regex;
+ return BsonType.Regex;
if(type == typeof(DBRef))
- return BsonDataType.Obj;
+ return BsonType.Obj;
if(type == typeof(Code))
- return BsonDataType.Code;
+ return BsonType.Code;
if(type == typeof(CodeWScope))
- return BsonDataType.CodeWScope;
+ return BsonType.CodeWScope;
if(type == typeof(DBNull))
- return BsonDataType.Null;
+ return BsonType.Null;
if(type == typeof(Binary))
- return BsonDataType.Binary;
+ return BsonType.Binary;
if(type == typeof(Guid))
- return BsonDataType.Binary;
+ return BsonType.Binary;
if(type == typeof(MongoMinKey))
- return BsonDataType.MinKey;
+ return BsonType.MinKey;
if(type == typeof(MongoMaxKey))
- return BsonDataType.MaxKey;
+ return BsonType.MaxKey;
if(type == typeof(MongoSymbol))
- return BsonDataType.Symbol;
+ return BsonType.Symbol;
if(_descriptor.IsArray(obj))
- return BsonDataType.Array;
+ return BsonType.Array;
if(_descriptor.IsObject(obj))
- return BsonDataType.Obj;
+ return BsonType.Obj;
throw new ArgumentOutOfRangeException(String.Format("Type: {0} not recognized", type.FullName));
}
View
2 source/MongoDB/MongoDB.csproj
@@ -98,7 +98,7 @@
<Compile Include="..\..\AssemblyInfoGlobal.cs">
<Link>AssemblyInfoGlobal.cs</Link>
</Compile>
- <Compile Include="Bson\BsonDataType.cs" />
+ <Compile Include="Bson\BsonType.cs" />
<Compile Include="Bson\BsonInfo.cs" />
<Compile Include="Bson\BsonDocumentBuilder.cs" />
<Compile Include="Bson\BsonDocumentDescriptor.cs" />
View
2 source/MongoDB/Op.cs
@@ -147,7 +147,7 @@ public static Op NotExists()
/// </summary>
/// <param name="bsonType">Type of the bson.</param>
/// <returns></returns>
- public static Op Type(BsonDataType bsonType)
+ public static Op Type(BsonType bsonType)
{
return (Op)new Op().Add("$type", (int)bsonType);
}
View
4 source/MongoDB/Protocol/DeleteMessage.cs
@@ -42,9 +42,9 @@ public DeleteMessage(IBsonObjectDescriptor objectDescriptor)
/// </summary>
/// <param name="writer">The writer.</param>
protected override void WriteBody(BsonWriter writer){
- writer.WriteValue(BsonDataType.Integer, 0);
+ writer.WriteValue(BsonType.Integer, 0);
writer.Write(FullCollectionName, false);
- writer.WriteValue(BsonDataType.Integer, 0);
+ writer.WriteValue(BsonType.Integer, 0);
writer.WriteObject(Selector);
}
View
6 source/MongoDB/Protocol/GetMoreMessage.cs
@@ -64,10 +64,10 @@ public GetMoreMessage(string fullCollectionName, long cursorId, int numberToRetu
/// </summary>
/// <param name="writer">The writer.</param>
protected override void WriteBody(BsonWriter writer){
- writer.WriteValue(BsonDataType.Integer, 0);
+ writer.WriteValue(BsonType.Integer, 0);
writer.Write(FullCollectionName, false);
- writer.WriteValue(BsonDataType.Integer, NumberToReturn);
- writer.WriteValue(BsonDataType.Long, CursorId);
+ writer.WriteValue(BsonType.Integer, NumberToReturn);
+ writer.WriteValue(BsonType.Long, CursorId);
}
/// <summary>
View
2 source/MongoDB/Protocol/InsertMessage.cs
@@ -104,7 +104,7 @@ public class InsertMessage : MessageBase, IRequestMessage
WriteHeader(new BinaryWriter(stream), chunk.Size);
var writer = new BsonWriter(stream, _objectDescriptor);
- writer.WriteValue(BsonDataType.Integer, 0);
+ writer.WriteValue(BsonType.Integer, 0);
writer.Write(FullCollectionName, false);
foreach(var document in chunk.Documents)
View
6 source/MongoDB/Protocol/KillCursorsMessage.cs
@@ -54,11 +54,11 @@ public KillCursorsMessage(long[] cursorIDs) : this()
/// </summary>
/// <param name="writer">The writer.</param>
protected override void WriteBody(BsonWriter writer){
- writer.WriteValue(BsonDataType.Integer, 0);
- writer.WriteValue(BsonDataType.Integer, CursorIds.Length);
+ writer.WriteValue(BsonType.Integer, 0);
+ writer.WriteValue(BsonType.Integer, CursorIds.Length);
foreach(var id in CursorIds)
- writer.WriteValue(BsonDataType.Long, id);
+ writer.WriteValue(BsonType.Long, id);
}
/// <summary>
View
6 source/MongoDB/Protocol/QueryMessage.cs
@@ -117,10 +117,10 @@ public QueryMessage(IBsonObjectDescriptor objectDescriptor, object query, String
/// </summary>
/// <param name="writer">The writer.</param>
protected override void WriteBody(BsonWriter writer){
- writer.WriteValue(BsonDataType.Integer, (int)Options);
+ writer.WriteValue(BsonType.Integer, (int)Options);
writer.Write(FullCollectionName, false);
- writer.WriteValue(BsonDataType.Integer, NumberToSkip);
- writer.WriteValue(BsonDataType.Integer, NumberToReturn);
+ writer.WriteValue(BsonType.Integer, NumberToSkip);
+ writer.WriteValue(BsonType.Integer, NumberToReturn);
writer.WriteObject(Query);
if(ReturnFieldSelector != null)
writer.WriteObject(ReturnFieldSelector);
View
4 source/MongoDB/Protocol/UpdateMessage.cs
@@ -55,9 +55,9 @@ public UpdateMessage(IBsonObjectDescriptor objectDescriptor)
/// </summary>
/// <param name="writer">The writer.</param>
protected override void WriteBody(BsonWriter writer){
- writer.WriteValue(BsonDataType.Integer, 0);
+ writer.WriteValue(BsonType.Integer, 0);
writer.Write(FullCollectionName, false);
- writer.WriteValue(BsonDataType.Integer, Flags);
+ writer.WriteValue(BsonType.Integer, Flags);
writer.WriteObject(Selector);
writer.WriteObject(Document);
}

0 comments on commit 6d7a4df

Please sign in to comment.