Suppose we have the following classes:
public class A {
public int a;
}
public class B : A {
public int b;
}
public class C : B {
public int c;
}
And we serialize an instance of C as follows:
var c = new C { a = 1, b = 2, c = 3 };
Console.WriteLine(c.ToJson<A>()); // nominalType is A
Console.WriteLine(c.ToJson<B>()); // nominalType is B
Console.WriteLine(c.ToJson<C>()); // nominalType is C
we get:
{ "_t" : "C", "a" : 1, "b" : 2, "c" : 3 }
{ "_t" : "C", "a" : 1, "b" : 2, "c" : 3 }
{ "a" : 1, "b" : 2, "c" : 3 }
So there are a couple of things to note:
1. A discriminator is only written if it is "needed"
2. The default discriminator is actually a scalar discriminator
One definition of a discriminator being "needed" is that the actual
type is different from the nominal type, which is true in the first 2
out of these 3 examples.
A hierarchical discriminator is only used when there is a "RootClass".
For example, we can make A a root class like this:
[BsonDiscriminator(RootClass = true)]
public class A {
public int a;
}
Now if we run the same three JSON output statements we get:
{ "_t" : ["A", "B", "C"], "a" : 1, "b" : 2, "c" : 3 }
{ "_t" : ["A", "B", "C"], "a" : 1, "b" : 2, "c" : 3 }
{ "_t" : ["A", "B", "C"], "a" : 1, "b" : 2, "c" : 3 }
And we see that the discriminators are arrays instead of scalars
because the presence of the RootClass attribute signals to use a
hierarchical discriminator.
During deserialization it actually doesn't matter whether the
discriminator is a scalar or an array. It if is an array only the last
element is used.
Given all this you may not have to set the default discriminator
convention. You probably have all the control you want just by using
or not using RootClass.
A document stored in a database using the samus driver can be loaded
successfully into an equivalent class using the official C# driver
assuming you use the same class name and property names. Or if they
differ in any way then you have to configure the class maps
appropriately.
I'll be happy to help further if you need.
Good luck!
Robert