Hi,
it's me again with a new question. I am trying to serialize polymorphic collections where the root type is an interface (which is quite indispensable for my purposes).
In a follow-up to a discussion thread a year ago (e.g.
http://osdir.com/ml/mongodb-user/2011-06/msg01561.html) there was an indication that the interface support would be included into version 1.2. I am using version 1.2.0.4274, but I do not have an impression that it is really included.
I am trying to serialize/deserialize collections that are declared roughly as follows (simplified):
[BsonKnownTypes(typeof(Person), typeof(Organization))] [BsonDiscriminator(RootClass = true)] public interface ICodedValue { [BsonId] public string Code {get;set;} public string Name {get;set;} } public class Person : ICodedValue { [BsonId]
public string Code {get;set;}
public string Name {get;set;} public Gender Gender {get;set;} public DateTime BirthDate {get;set;} } public class Organization : ICodedValue { [BsonId]
public string Code {get;set;}
public string Name {get;set;} public Address Address {get;set;} public string Phone {get;set;} }(As far as I understand, this is equivalent to the declarations via BsonClassMap.RegisterClassMap() which I also tried with no success).
The interface so declared won't even compile:
"Attribute 'BsonKnownTypes' is not valid on this declaration type. It is only valid on 'class, struct' declarations."
"Attribute 'BsonDiscriminator' is not valid on this declaration type. It is only valid on 'class, struct' declarations."
An attempt to use an abstract class is obviously no solution, since no instances can be initialized. If I declare a normal class as the root type (like in the "Animal-Cat-Tiger" example in the tutorial) everything functions fine. But I need interfaces.
Are interfaces not supported in the end or am I doing things wrongly?
In the best case i would appreciate a minimal code example with an interface as root type that functions.
Thanks in advance,
Stan