Skip to content

Commit 9533bb3

Browse files
committed
CSHARP-628: added support for enumerating the registered class maps.
1 parent e66452f commit 9533bb3

File tree

3 files changed

+12
-21
lines changed

3 files changed

+12
-21
lines changed

Bson/Serialization/BsonClassMap.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,14 @@ public static Type GetMemberInfoType(MemberInfo memberInfo)
264264
throw new NotSupportedException("Only field and properties are supported at this time.");
265265
}
266266

267+
/// <summary>
268+
/// Returns all registered class maps.
269+
/// </summary>
270+
public static IEnumerable<BsonClassMap> GetRegisteredClassMaps()
271+
{
272+
return __classMaps.Values;
273+
}
274+
267275
/// <summary>
268276
/// Checks whether a class map is registered for a type.
269277
/// </summary>
@@ -287,14 +295,6 @@ public static bool IsClassMapRegistered(Type type)
287295
}
288296
}
289297

290-
/// <summary>
291-
/// Returns all registered class maps.
292-
/// </summary>
293-
public static IEnumerable<BsonClassMap> AllClassMaps()
294-
{
295-
return __classMaps.Values;
296-
}
297-
298298
/// <summary>
299299
/// Looks up a class map (will AutoMap the class if no class map is registered).
300300
/// </summary>

BsonUnitTests/DefaultSerializer/BsonClassMapTests.cs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,8 @@ public void TestIsClassMapRegistered()
310310
}
311311

312312
[TestFixture]
313-
public class BsonClassMapAllClassMapTests
313+
public class BsonClassMapGetRegisteredClassMapTests
314314
{
315-
private static bool __testAlreadyRan;
316-
317315
public class C
318316
{
319317
public ObjectId Id;
@@ -327,22 +325,14 @@ public class D
327325
}
328326

329327
[Test]
330-
public void TestAllClassMaps()
328+
public void TestGetRegisteredClassMaps()
331329
{
332-
// test can only be run once
333-
if (__testAlreadyRan)
334-
{
335-
return;
336-
}
337-
338-
__testAlreadyRan = true;
339-
340330
Assert.IsFalse(BsonClassMap.IsClassMapRegistered(typeof(C)));
341331
Assert.IsFalse(BsonClassMap.IsClassMapRegistered(typeof(D)));
342332
BsonClassMap.RegisterClassMap<C>(cm => cm.AutoMap());
343333
BsonClassMap.RegisterClassMap<D>(cm => cm.AutoMap());
344334

345-
var classMaps = BsonClassMap.AllClassMaps();
335+
var classMaps = BsonClassMap.GetRegisteredClassMaps();
346336
var classMapTypes = classMaps.Select(x => x.ClassType).ToList();
347337

348338
Assert.IsTrue(BsonClassMap.IsClassMapRegistered(typeof(C)));

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@ http://jira.mongodb.org/browse/CSHARP
3838
* Andrew Rondeau [email protected]
3939
4040
41+
* Alex Brown https://github.com/alexjamesbrown
4142

4243
If you have contributed and we have neglected to add you to this list please contact one of the maintainers to be added to the list (with apologies).

0 commit comments

Comments
 (0)