15
15
16
16
using System ;
17
17
using System . Collections . Generic ;
18
+ using System . ComponentModel ;
19
+ using System . Diagnostics ;
18
20
using System . Text . RegularExpressions ;
19
21
20
22
namespace MongoDB . Bson
@@ -53,6 +55,7 @@ public abstract class BsonValue : IComparable<BsonValue>, IConvertible, IEquatab
53
55
/// <summary>
54
56
/// Casts the BsonValue to a Boolean (throws an InvalidCastException if the cast is not valid).
55
57
/// </summary>
58
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
56
59
public bool AsBoolean
57
60
{
58
61
get { return ( ( BsonBoolean ) this ) . Value ; }
@@ -61,6 +64,7 @@ public bool AsBoolean
61
64
/// <summary>
62
65
/// Casts the BsonValue to a BsonArray (throws an InvalidCastException if the cast is not valid).
63
66
/// </summary>
67
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
64
68
public BsonArray AsBsonArray
65
69
{
66
70
get { return ( BsonArray ) this ; }
@@ -69,6 +73,7 @@ public BsonArray AsBsonArray
69
73
/// <summary>
70
74
/// Casts the BsonValue to a BsonBinaryData (throws an InvalidCastException if the cast is not valid).
71
75
/// </summary>
76
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
72
77
public BsonBinaryData AsBsonBinaryData
73
78
{
74
79
get { return ( BsonBinaryData ) this ; }
@@ -77,6 +82,7 @@ public BsonBinaryData AsBsonBinaryData
77
82
/// <summary>
78
83
/// Casts the BsonValue to a BsonDateTime (throws an InvalidCastException if the cast is not valid).
79
84
/// </summary>
85
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
80
86
public BsonDateTime AsBsonDateTime
81
87
{
82
88
get { return ( BsonDateTime ) this ; }
@@ -85,6 +91,7 @@ public BsonDateTime AsBsonDateTime
85
91
/// <summary>
86
92
/// Casts the BsonValue to a BsonDocument (throws an InvalidCastException if the cast is not valid).
87
93
/// </summary>
94
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
88
95
public BsonDocument AsBsonDocument
89
96
{
90
97
get { return ( BsonDocument ) this ; }
@@ -93,6 +100,7 @@ public BsonDocument AsBsonDocument
93
100
/// <summary>
94
101
/// Casts the BsonValue to a BsonJavaScript (throws an InvalidCastException if the cast is not valid).
95
102
/// </summary>
103
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
96
104
public BsonJavaScript AsBsonJavaScript
97
105
{
98
106
get { return ( BsonJavaScript ) this ; }
@@ -101,6 +109,7 @@ public BsonJavaScript AsBsonJavaScript
101
109
/// <summary>
102
110
/// Casts the BsonValue to a BsonJavaScriptWithScope (throws an InvalidCastException if the cast is not valid).
103
111
/// </summary>
112
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
104
113
public BsonJavaScriptWithScope AsBsonJavaScriptWithScope
105
114
{
106
115
get { return ( BsonJavaScriptWithScope ) this ; }
@@ -109,6 +118,7 @@ public BsonJavaScriptWithScope AsBsonJavaScriptWithScope
109
118
/// <summary>
110
119
/// Casts the BsonValue to a BsonMaxKey (throws an InvalidCastException if the cast is not valid).
111
120
/// </summary>
121
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
112
122
public BsonMaxKey AsBsonMaxKey
113
123
{
114
124
get { return ( BsonMaxKey ) this ; }
@@ -117,6 +127,7 @@ public BsonMaxKey AsBsonMaxKey
117
127
/// <summary>
118
128
/// Casts the BsonValue to a BsonMinKey (throws an InvalidCastException if the cast is not valid).
119
129
/// </summary>
130
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
120
131
public BsonMinKey AsBsonMinKey
121
132
{
122
133
get { return ( BsonMinKey ) this ; }
@@ -125,6 +136,7 @@ public BsonMinKey AsBsonMinKey
125
136
/// <summary>
126
137
/// Casts the BsonValue to a BsonNull (throws an InvalidCastException if the cast is not valid).
127
138
/// </summary>
139
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
128
140
public BsonNull AsBsonNull
129
141
{
130
142
get { return ( BsonNull ) this ; }
@@ -133,6 +145,7 @@ public BsonNull AsBsonNull
133
145
/// <summary>
134
146
/// Casts the BsonValue to a BsonRegularExpression (throws an InvalidCastException if the cast is not valid).
135
147
/// </summary>
148
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
136
149
public BsonRegularExpression AsBsonRegularExpression
137
150
{
138
151
get { return ( BsonRegularExpression ) this ; }
@@ -141,6 +154,7 @@ public BsonRegularExpression AsBsonRegularExpression
141
154
/// <summary>
142
155
/// Casts the BsonValue to a BsonSymbol (throws an InvalidCastException if the cast is not valid).
143
156
/// </summary>
157
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
144
158
public BsonSymbol AsBsonSymbol
145
159
{
146
160
get { return ( BsonSymbol ) this ; }
@@ -149,6 +163,7 @@ public BsonSymbol AsBsonSymbol
149
163
/// <summary>
150
164
/// Casts the BsonValue to a BsonTimestamp (throws an InvalidCastException if the cast is not valid).
151
165
/// </summary>
166
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
152
167
public BsonTimestamp AsBsonTimestamp
153
168
{
154
169
get { return ( BsonTimestamp ) this ; }
@@ -157,6 +172,7 @@ public BsonTimestamp AsBsonTimestamp
157
172
/// <summary>
158
173
/// Casts the BsonValue to a BsonUndefined (throws an InvalidCastException if the cast is not valid).
159
174
/// </summary>
175
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
160
176
public BsonUndefined AsBsonUndefined
161
177
{
162
178
get { return ( BsonUndefined ) this ; }
@@ -165,6 +181,7 @@ public BsonUndefined AsBsonUndefined
165
181
/// <summary>
166
182
/// Casts the BsonValue to a BsonValue (a way of upcasting subclasses of BsonValue to BsonValue at compile time).
167
183
/// </summary>
184
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
168
185
public BsonValue AsBsonValue
169
186
{
170
187
get { return this ; }
@@ -173,23 +190,16 @@ public BsonValue AsBsonValue
173
190
/// <summary>
174
191
/// Casts the BsonValue to a Byte[] (throws an InvalidCastException if the cast is not valid).
175
192
/// </summary>
193
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
176
194
public byte [ ] AsByteArray
177
195
{
178
196
get { return ( ( BsonBinaryData ) this ) . Bytes ; }
179
197
}
180
198
181
- /// <summary>
182
- /// Casts the BsonValue to a DateTime in UTC (throws an InvalidCastException if the cast is not valid).
183
- /// </summary>
184
- [ Obsolete ( "Use ToUniversalTime instead." ) ]
185
- public DateTime AsDateTime
186
- {
187
- get { return AsUniversalTime ; }
188
- }
189
-
190
199
/// <summary>
191
200
/// Casts the BsonValue to a <see cref="decimal"/> (throws an InvalidCastException if the cast is not valid).
192
201
/// </summary>
202
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
193
203
public decimal AsDecimal
194
204
{
195
205
get { return ( decimal ) ( ( BsonDecimal128 ) this ) . Value ; }
@@ -198,6 +208,7 @@ public decimal AsDecimal
198
208
/// <summary>
199
209
/// Casts the BsonValue to a <see cref="Decimal128"/> (throws an InvalidCastException if the cast is not valid).
200
210
/// </summary>
211
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
201
212
public Decimal128 AsDecimal128
202
213
{
203
214
get { return ( ( BsonDecimal128 ) this ) . Value ; }
@@ -206,6 +217,7 @@ public Decimal128 AsDecimal128
206
217
/// <summary>
207
218
/// Casts the BsonValue to a Double (throws an InvalidCastException if the cast is not valid).
208
219
/// </summary>
220
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
209
221
public double AsDouble
210
222
{
211
223
get { return ( ( BsonDouble ) this ) . Value ; }
@@ -214,6 +226,7 @@ public double AsDouble
214
226
/// <summary>
215
227
/// Casts the BsonValue to a Guid (throws an InvalidCastException if the cast is not valid).
216
228
/// </summary>
229
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
217
230
public Guid AsGuid
218
231
{
219
232
get { return ( ( BsonBinaryData ) this ) . ToGuid ( ) ; }
@@ -222,48 +235,43 @@ public Guid AsGuid
222
235
/// <summary>
223
236
/// Casts the BsonValue to an Int32 (throws an InvalidCastException if the cast is not valid).
224
237
/// </summary>
238
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
225
239
public int AsInt32
226
240
{
227
241
get { return ( ( BsonInt32 ) this ) . Value ; }
228
242
}
229
243
230
- /// <summary>
231
- /// Casts the BsonValue to a DateTime in the local timezone (throws an InvalidCastException if the cast is not valid).
232
- /// </summary>
233
- [ Obsolete ( "Use ToLocalTime instead." ) ]
234
- public DateTime AsLocalTime
235
- {
236
- get { return ( ( BsonDateTime ) this ) . ToLocalTime ( ) ; }
237
- }
238
-
239
244
/// <summary>
240
245
/// Casts the BsonValue to a Int64 (throws an InvalidCastException if the cast is not valid).
241
246
/// </summary>
247
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
242
248
public long AsInt64
243
249
{
244
250
get { return ( ( BsonInt64 ) this ) . Value ; }
245
251
}
246
252
247
253
/// <summary>
248
- /// Casts the BsonValue to a Nullable{Boolean} (throws an InvalidCastException if the cast is not valid).
254
+ /// Casts the BsonValue to a DateTime in the local timezone (throws an InvalidCastException if the cast is not valid).
249
255
/// </summary>
250
- public bool ? AsNullableBoolean
256
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
257
+ public DateTime AsLocalTime
251
258
{
252
- get { return ( BsonType == BsonType . Null ) ? null : ( bool ? ) AsBoolean ; }
259
+ get { return ( ( BsonDateTime ) this ) . ToLocalTime ( ) ; }
253
260
}
254
261
255
262
/// <summary>
256
- /// Casts the BsonValue to a Nullable{DateTime } (throws an InvalidCastException if the cast is not valid).
263
+ /// Casts the BsonValue to a Nullable{Boolean } (throws an InvalidCastException if the cast is not valid).
257
264
/// </summary>
258
- [ Obsolete ( "Use ToNullableUniversalTime instead." ) ]
259
- public DateTime ? AsNullableDateTime
265
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
266
+ public bool ? AsNullableBoolean
260
267
{
261
- get { return ( BsonType == BsonType . Null ) ? null : ( DateTime ? ) AsDateTime ; }
268
+ get { return ( BsonType == BsonType . Null ) ? null : ( bool ? ) AsBoolean ; }
262
269
}
263
270
264
271
/// <summary>
265
272
/// Casts the BsonValue to a Nullable{Decimal} (throws an InvalidCastException if the cast is not valid).
266
273
/// </summary>
274
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
267
275
public decimal ? AsNullableDecimal
268
276
{
269
277
get { return ( BsonType == BsonType . Null ) ? null : ( decimal ? ) AsDecimal128 ; }
@@ -272,6 +280,7 @@ public decimal? AsNullableDecimal
272
280
/// <summary>
273
281
/// Casts the BsonValue to a Nullable{Decimal128} (throws an InvalidCastException if the cast is not valid).
274
282
/// </summary>
283
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
275
284
public Decimal128 ? AsNullableDecimal128
276
285
{
277
286
get { return ( BsonType == BsonType . Null ) ? null : ( Decimal128 ? ) AsDecimal128 ; }
@@ -280,6 +289,7 @@ public Decimal128? AsNullableDecimal128
280
289
/// <summary>
281
290
/// Casts the BsonValue to a Nullable{Double} (throws an InvalidCastException if the cast is not valid).
282
291
/// </summary>
292
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
283
293
public double ? AsNullableDouble
284
294
{
285
295
get { return ( BsonType == BsonType . Null ) ? null : ( double ? ) AsDouble ; }
@@ -288,6 +298,7 @@ public double? AsNullableDouble
288
298
/// <summary>
289
299
/// Casts the BsonValue to a Nullable{Guid} (throws an InvalidCastException if the cast is not valid).
290
300
/// </summary>
301
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
291
302
public Guid ? AsNullableGuid
292
303
{
293
304
get { return ( BsonType == BsonType . Null ) ? null : ( Guid ? ) AsGuid ; }
@@ -296,6 +307,7 @@ public Guid? AsNullableGuid
296
307
/// <summary>
297
308
/// Casts the BsonValue to a Nullable{Int32} (throws an InvalidCastException if the cast is not valid).
298
309
/// </summary>
310
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
299
311
public int ? AsNullableInt32
300
312
{
301
313
get { return ( BsonType == BsonType . Null ) ? null : ( int ? ) AsInt32 ; }
@@ -304,22 +316,43 @@ public int? AsNullableInt32
304
316
/// <summary>
305
317
/// Casts the BsonValue to a Nullable{Int64} (throws an InvalidCastException if the cast is not valid).
306
318
/// </summary>
319
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
307
320
public long ? AsNullableInt64
308
321
{
309
322
get { return ( BsonType == BsonType . Null ) ? null : ( long ? ) AsInt64 ; }
310
323
}
311
324
325
+ /// <summary>
326
+ /// Casts the BsonValue to a Nullable{DateTime} in the local timezone (throws an InvalidCastException if the cast is not valid).
327
+ /// </summary>
328
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
329
+ public DateTime ? AsNullableLocalTime
330
+ {
331
+ get { return ( BsonType == BsonType . Null ) ? null : ( ( BsonDateTime ) this ) . ToLocalTime ( ) ; }
332
+ }
333
+
312
334
/// <summary>
313
335
/// Casts the BsonValue to a Nullable{ObjectId} (throws an InvalidCastException if the cast is not valid).
314
336
/// </summary>
337
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
315
338
public ObjectId ? AsNullableObjectId
316
339
{
317
340
get { return ( BsonType == BsonType . Null ) ? null : ( ObjectId ? ) AsObjectId ; }
318
341
}
319
342
343
+ /// <summary>
344
+ /// Casts the BsonValue to a Nullable{DateTime} in UTC (throws an InvalidCastException if the cast is not valid).
345
+ /// </summary>
346
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
347
+ public DateTime ? AsNullableUniversalTime
348
+ {
349
+ get { return ( BsonType == BsonType . Null ) ? null : ( ( BsonDateTime ) this ) . ToUniversalTime ( ) ; }
350
+ }
351
+
320
352
/// <summary>
321
353
/// Casts the BsonValue to an ObjectId (throws an InvalidCastException if the cast is not valid).
322
354
/// </summary>
355
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
323
356
public ObjectId AsObjectId
324
357
{
325
358
get { return ( ( BsonObjectId ) this ) . Value ; }
@@ -328,6 +361,7 @@ public ObjectId AsObjectId
328
361
/// <summary>
329
362
/// Casts the BsonValue to a Regex (throws an InvalidCastException if the cast is not valid).
330
363
/// </summary>
364
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
331
365
public Regex AsRegex
332
366
{
333
367
get { return ( ( BsonRegularExpression ) this ) . ToRegex ( ) ; }
@@ -336,6 +370,7 @@ public Regex AsRegex
336
370
/// <summary>
337
371
/// Casts the BsonValue to a String (throws an InvalidCastException if the cast is not valid).
338
372
/// </summary>
373
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
339
374
public string AsString
340
375
{
341
376
get { return ( ( BsonString ) this ) . Value ; }
@@ -344,7 +379,7 @@ public string AsString
344
379
/// <summary>
345
380
/// Casts the BsonValue to a DateTime in UTC (throws an InvalidCastException if the cast is not valid).
346
381
/// </summary>
347
- [ Obsolete ( "Use ToUniversalTime instead." ) ]
382
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
348
383
public DateTime AsUniversalTime
349
384
{
350
385
get { return ( ( BsonDateTime ) this ) . ToUniversalTime ( ) ; }
@@ -467,15 +502,6 @@ public bool IsBsonUndefined
467
502
get { return BsonType == BsonType . Undefined ; }
468
503
}
469
504
470
- /// <summary>
471
- /// Tests whether this BsonValue is a DateTime.
472
- /// </summary>
473
- [ Obsolete ( "Use IsValidDateTime instead." ) ]
474
- public bool IsDateTime
475
- {
476
- get { return IsValidDateTime ; }
477
- }
478
-
479
505
/// <summary>
480
506
/// Tests whether this BsonValue is a Decimal128.
481
507
/// </summary>
@@ -1248,7 +1274,7 @@ public bool Equals(BsonValue rhs)
1248
1274
public virtual bool ToBoolean ( )
1249
1275
{
1250
1276
// some subclasses override as appropriate
1251
- return true ; // everything else is true
1277
+ return true ; // everything else is true
1252
1278
}
1253
1279
1254
1280
/// <summary>
0 commit comments