-
Notifications
You must be signed in to change notification settings - Fork 1.3k
CSHARP-5319: Remove AsDateTime and similar from BsonValue #1494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7f39cda
ad80331
8d3c1bb
5e46aaa
14931bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ | |
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Diagnostics; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace MongoDB.Bson | ||
|
@@ -53,6 +55,7 @@ public abstract class BsonValue : IComparable<BsonValue>, IConvertible, IEquatab | |
/// <summary> | ||
/// Casts the BsonValue to a Boolean (throws an InvalidCastException if the cast is not valid). | ||
/// </summary> | ||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
public bool AsBoolean | ||
{ | ||
get { return ((BsonBoolean)this).Value; } | ||
|
@@ -61,6 +64,7 @@ public bool AsBoolean | |
/// <summary> | ||
/// Casts the BsonValue to a BsonArray (throws an InvalidCastException if the cast is not valid). | ||
/// </summary> | ||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
public BsonArray AsBsonArray | ||
{ | ||
get { return (BsonArray)this; } | ||
|
@@ -69,6 +73,7 @@ public BsonArray AsBsonArray | |
/// <summary> | ||
/// Casts the BsonValue to a BsonBinaryData (throws an InvalidCastException if the cast is not valid). | ||
/// </summary> | ||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
public BsonBinaryData AsBsonBinaryData | ||
{ | ||
get { return (BsonBinaryData)this; } | ||
|
@@ -77,6 +82,7 @@ public BsonBinaryData AsBsonBinaryData | |
/// <summary> | ||
/// Casts the BsonValue to a BsonDateTime (throws an InvalidCastException if the cast is not valid). | ||
/// </summary> | ||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
public BsonDateTime AsBsonDateTime | ||
{ | ||
get { return (BsonDateTime)this; } | ||
|
@@ -85,6 +91,7 @@ public BsonDateTime AsBsonDateTime | |
/// <summary> | ||
/// Casts the BsonValue to a BsonDocument (throws an InvalidCastException if the cast is not valid). | ||
/// </summary> | ||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
public BsonDocument AsBsonDocument | ||
{ | ||
get { return (BsonDocument)this; } | ||
|
@@ -93,6 +100,7 @@ public BsonDocument AsBsonDocument | |
/// <summary> | ||
/// Casts the BsonValue to a BsonJavaScript (throws an InvalidCastException if the cast is not valid). | ||
/// </summary> | ||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
public BsonJavaScript AsBsonJavaScript | ||
{ | ||
get { return (BsonJavaScript)this; } | ||
|
@@ -101,6 +109,7 @@ public BsonJavaScript AsBsonJavaScript | |
/// <summary> | ||
/// Casts the BsonValue to a BsonJavaScriptWithScope (throws an InvalidCastException if the cast is not valid). | ||
/// </summary> | ||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
public BsonJavaScriptWithScope AsBsonJavaScriptWithScope | ||
{ | ||
get { return (BsonJavaScriptWithScope)this; } | ||
|
@@ -109,6 +118,7 @@ public BsonJavaScriptWithScope AsBsonJavaScriptWithScope | |
/// <summary> | ||
/// Casts the BsonValue to a BsonMaxKey (throws an InvalidCastException if the cast is not valid). | ||
/// </summary> | ||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
public BsonMaxKey AsBsonMaxKey | ||
{ | ||
get { return (BsonMaxKey)this; } | ||
|
@@ -117,6 +127,7 @@ public BsonMaxKey AsBsonMaxKey | |
/// <summary> | ||
/// Casts the BsonValue to a BsonMinKey (throws an InvalidCastException if the cast is not valid). | ||
/// </summary> | ||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
public BsonMinKey AsBsonMinKey | ||
{ | ||
get { return (BsonMinKey)this; } | ||
|
@@ -125,6 +136,7 @@ public BsonMinKey AsBsonMinKey | |
/// <summary> | ||
/// Casts the BsonValue to a BsonNull (throws an InvalidCastException if the cast is not valid). | ||
/// </summary> | ||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
public BsonNull AsBsonNull | ||
{ | ||
get { return (BsonNull)this; } | ||
|
@@ -133,6 +145,7 @@ public BsonNull AsBsonNull | |
/// <summary> | ||
/// Casts the BsonValue to a BsonRegularExpression (throws an InvalidCastException if the cast is not valid). | ||
/// </summary> | ||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
public BsonRegularExpression AsBsonRegularExpression | ||
{ | ||
get { return (BsonRegularExpression)this; } | ||
|
@@ -141,6 +154,7 @@ public BsonRegularExpression AsBsonRegularExpression | |
/// <summary> | ||
/// Casts the BsonValue to a BsonSymbol (throws an InvalidCastException if the cast is not valid). | ||
/// </summary> | ||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
public BsonSymbol AsBsonSymbol | ||
{ | ||
get { return (BsonSymbol)this; } | ||
|
@@ -149,6 +163,7 @@ public BsonSymbol AsBsonSymbol | |
/// <summary> | ||
/// Casts the BsonValue to a BsonTimestamp (throws an InvalidCastException if the cast is not valid). | ||
/// </summary> | ||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
public BsonTimestamp AsBsonTimestamp | ||
{ | ||
get { return (BsonTimestamp)this; } | ||
|
@@ -157,6 +172,7 @@ public BsonTimestamp AsBsonTimestamp | |
/// <summary> | ||
/// Casts the BsonValue to a BsonUndefined (throws an InvalidCastException if the cast is not valid). | ||
/// </summary> | ||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
public BsonUndefined AsBsonUndefined | ||
{ | ||
get { return (BsonUndefined)this; } | ||
|
@@ -165,6 +181,7 @@ public BsonUndefined AsBsonUndefined | |
/// <summary> | ||
/// Casts the BsonValue to a BsonValue (a way of upcasting subclasses of BsonValue to BsonValue at compile time). | ||
/// </summary> | ||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing attribute on line 192. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤦 just added |
||
public BsonValue AsBsonValue | ||
{ | ||
get { return this; } | ||
|
@@ -173,23 +190,16 @@ public BsonValue AsBsonValue | |
/// <summary> | ||
/// Casts the BsonValue to a Byte[] (throws an InvalidCastException if the cast is not valid). | ||
/// </summary> | ||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
public byte[] AsByteArray | ||
{ | ||
get { return ((BsonBinaryData)this).Bytes; } | ||
} | ||
|
||
/// <summary> | ||
/// Casts the BsonValue to a DateTime in UTC (throws an InvalidCastException if the cast is not valid). | ||
/// </summary> | ||
[Obsolete("Use ToUniversalTime instead.")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This obsoletion was proper and the member can be deleted. The error message was wrong though. It should have been "Use AsUniversalTime" instead. |
||
public DateTime AsDateTime | ||
{ | ||
get { return AsUniversalTime; } | ||
} | ||
|
||
/// <summary> | ||
/// Casts the BsonValue to a <see cref="decimal"/> (throws an InvalidCastException if the cast is not valid). | ||
/// </summary> | ||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
public decimal AsDecimal | ||
{ | ||
get { return (decimal)((BsonDecimal128)this).Value; } | ||
|
@@ -198,6 +208,7 @@ public decimal AsDecimal | |
/// <summary> | ||
/// Casts the BsonValue to a <see cref="Decimal128"/> (throws an InvalidCastException if the cast is not valid). | ||
/// </summary> | ||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
public Decimal128 AsDecimal128 | ||
{ | ||
get { return ((BsonDecimal128)this).Value; } | ||
|
@@ -206,6 +217,7 @@ public Decimal128 AsDecimal128 | |
/// <summary> | ||
/// Casts the BsonValue to a Double (throws an InvalidCastException if the cast is not valid). | ||
/// </summary> | ||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
public double AsDouble | ||
{ | ||
get { return ((BsonDouble)this).Value; } | ||
|
@@ -214,6 +226,7 @@ public double AsDouble | |
/// <summary> | ||
/// Casts the BsonValue to a Guid (throws an InvalidCastException if the cast is not valid). | ||
/// </summary> | ||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
public Guid AsGuid | ||
{ | ||
get { return ((BsonBinaryData)this).ToGuid(); } | ||
|
@@ -222,48 +235,43 @@ public Guid AsGuid | |
/// <summary> | ||
/// Casts the BsonValue to an Int32 (throws an InvalidCastException if the cast is not valid). | ||
/// </summary> | ||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
public int AsInt32 | ||
{ | ||
get { return ((BsonInt32)this).Value; } | ||
} | ||
|
||
/// <summary> | ||
/// Casts the BsonValue to a DateTime in the local timezone (throws an InvalidCastException if the cast is not valid). | ||
/// </summary> | ||
[Obsolete("Use ToLocalTime instead.")] | ||
public DateTime AsLocalTime | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this was obsoleted by mistake and we should keep the property and remove the |
||
{ | ||
get { return ((BsonDateTime)this).ToLocalTime(); } | ||
} | ||
|
||
/// <summary> | ||
/// Casts the BsonValue to a Int64 (throws an InvalidCastException if the cast is not valid). | ||
/// </summary> | ||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
public long AsInt64 | ||
{ | ||
get { return ((BsonInt64)this).Value; } | ||
} | ||
|
||
/// <summary> | ||
/// Casts the BsonValue to a Nullable{Boolean} (throws an InvalidCastException if the cast is not valid). | ||
/// Casts the BsonValue to a DateTime in the local timezone (throws an InvalidCastException if the cast is not valid). | ||
/// </summary> | ||
public bool? AsNullableBoolean | ||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
public DateTime AsLocalTime | ||
{ | ||
get { return (BsonType == BsonType.Null) ? null : (bool?)AsBoolean; } | ||
get { return ((BsonDateTime)this).ToLocalTime(); } | ||
} | ||
|
||
/// <summary> | ||
/// Casts the BsonValue to a Nullable{DateTime} (throws an InvalidCastException if the cast is not valid). | ||
/// Casts the BsonValue to a Nullable{Boolean} (throws an InvalidCastException if the cast is not valid). | ||
/// </summary> | ||
[Obsolete("Use ToNullableUniversalTime instead.")] | ||
public DateTime? AsNullableDateTime | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This property should be replaced with two properties: |
||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
public bool? AsNullableBoolean | ||
{ | ||
get { return (BsonType == BsonType.Null) ? null : (DateTime?)AsDateTime; } | ||
get { return (BsonType == BsonType.Null) ? null : (bool?)AsBoolean; } | ||
} | ||
|
||
/// <summary> | ||
/// Casts the BsonValue to a Nullable{Decimal} (throws an InvalidCastException if the cast is not valid). | ||
/// </summary> | ||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
public decimal? AsNullableDecimal | ||
{ | ||
get { return (BsonType == BsonType.Null) ? null : (decimal?)AsDecimal128; } | ||
|
@@ -272,6 +280,7 @@ public decimal? AsNullableDecimal | |
/// <summary> | ||
/// Casts the BsonValue to a Nullable{Decimal128} (throws an InvalidCastException if the cast is not valid). | ||
/// </summary> | ||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
public Decimal128? AsNullableDecimal128 | ||
{ | ||
get { return (BsonType == BsonType.Null) ? null : (Decimal128?)AsDecimal128; } | ||
|
@@ -280,6 +289,7 @@ public Decimal128? AsNullableDecimal128 | |
/// <summary> | ||
/// Casts the BsonValue to a Nullable{Double} (throws an InvalidCastException if the cast is not valid). | ||
/// </summary> | ||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
public double? AsNullableDouble | ||
{ | ||
get { return (BsonType == BsonType.Null) ? null : (double?)AsDouble; } | ||
|
@@ -288,6 +298,7 @@ public double? AsNullableDouble | |
/// <summary> | ||
/// Casts the BsonValue to a Nullable{Guid} (throws an InvalidCastException if the cast is not valid). | ||
/// </summary> | ||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
public Guid? AsNullableGuid | ||
{ | ||
get { return (BsonType == BsonType.Null) ? null : (Guid?)AsGuid; } | ||
|
@@ -296,6 +307,7 @@ public Guid? AsNullableGuid | |
/// <summary> | ||
/// Casts the BsonValue to a Nullable{Int32} (throws an InvalidCastException if the cast is not valid). | ||
/// </summary> | ||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
public int? AsNullableInt32 | ||
{ | ||
get { return (BsonType == BsonType.Null) ? null : (int?)AsInt32; } | ||
|
@@ -304,22 +316,43 @@ public int? AsNullableInt32 | |
/// <summary> | ||
/// Casts the BsonValue to a Nullable{Int64} (throws an InvalidCastException if the cast is not valid). | ||
/// </summary> | ||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
public long? AsNullableInt64 | ||
{ | ||
get { return (BsonType == BsonType.Null) ? null : (long?)AsInt64; } | ||
} | ||
|
||
/// <summary> | ||
/// Casts the BsonValue to a Nullable{DateTime} in the local timezone (throws an InvalidCastException if the cast is not valid). | ||
/// </summary> | ||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
public DateTime? AsNullableLocalTime | ||
{ | ||
get { return (BsonType == BsonType.Null) ? null : ((BsonDateTime)this).ToLocalTime(); } | ||
} | ||
|
||
/// <summary> | ||
/// Casts the BsonValue to a Nullable{ObjectId} (throws an InvalidCastException if the cast is not valid). | ||
/// </summary> | ||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
public ObjectId? AsNullableObjectId | ||
{ | ||
get { return (BsonType == BsonType.Null) ? null : (ObjectId?)AsObjectId; } | ||
} | ||
|
||
/// <summary> | ||
/// Casts the BsonValue to a Nullable{DateTime} in UTC (throws an InvalidCastException if the cast is not valid). | ||
/// </summary> | ||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
public DateTime? AsNullableUniversalTime | ||
{ | ||
get { return (BsonType == BsonType.Null) ? null : ((BsonDateTime)this).ToUniversalTime(); } | ||
} | ||
|
||
/// <summary> | ||
/// Casts the BsonValue to an ObjectId (throws an InvalidCastException if the cast is not valid). | ||
/// </summary> | ||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
public ObjectId AsObjectId | ||
{ | ||
get { return ((BsonObjectId)this).Value; } | ||
|
@@ -328,6 +361,7 @@ public ObjectId AsObjectId | |
/// <summary> | ||
/// Casts the BsonValue to a Regex (throws an InvalidCastException if the cast is not valid). | ||
/// </summary> | ||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
public Regex AsRegex | ||
{ | ||
get { return ((BsonRegularExpression)this).ToRegex(); } | ||
|
@@ -336,6 +370,7 @@ public Regex AsRegex | |
/// <summary> | ||
/// Casts the BsonValue to a String (throws an InvalidCastException if the cast is not valid). | ||
/// </summary> | ||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
public string AsString | ||
{ | ||
get { return ((BsonString)this).Value; } | ||
|
@@ -344,7 +379,7 @@ public string AsString | |
/// <summary> | ||
/// Casts the BsonValue to a DateTime in UTC (throws an InvalidCastException if the cast is not valid). | ||
/// </summary> | ||
[Obsolete("Use ToUniversalTime instead.")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this was obsoleted by mistake and we should keep the property and remove the |
||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
public DateTime AsUniversalTime | ||
{ | ||
get { return ((BsonDateTime)this).ToUniversalTime(); } | ||
|
@@ -467,15 +502,6 @@ public bool IsBsonUndefined | |
get { return BsonType == BsonType.Undefined; } | ||
} | ||
|
||
/// <summary> | ||
/// Tests whether this BsonValue is a DateTime. | ||
/// </summary> | ||
[Obsolete("Use IsValidDateTime instead.")] | ||
public bool IsDateTime | ||
{ | ||
get { return IsValidDateTime; } | ||
} | ||
|
||
/// <summary> | ||
/// Tests whether this BsonValue is a Decimal128. | ||
/// </summary> | ||
|
@@ -1248,7 +1274,7 @@ public bool Equals(BsonValue rhs) | |
public virtual bool ToBoolean() | ||
{ | ||
// some subclasses override as appropriate | ||
return true; // everything else is true | ||
return true; // everything else is true | ||
} | ||
|
||
/// <summary> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing attribute on line 94.