I have few classes deriving from abstract class A - A1, A2, A3, etc.
I need to register these classes to BsonClassMap using their own discriminators using code like this:
BsonClassMap.RegisterClassMap<A1>(cm => { cm.AutoMap(); cm.SetDiscriminator(discriminator) }); Since I will have more of such classes in future, I want to use reflection to do that:
foreach (var type in Assembly.GetAssembly(typeof(A)) .GetTypes().Where(t => t.IsClass && !t.IsAbstract && t.IsSubclassOf(typeof(A)))) { var discriminator = type.GetField("Discriminator") .GetRawConstantValue() .ToString(); var method = typeof(BsonClassMap).GetMethods() .FirstOrDefault(m => m.IsGenericMethod && m.Name == "RegisterClassMap"); if (method == null) continue; var generic = method.MakeGenericMethod(type); generic.Invoke(this, null); } How can I pass such lambda expression to this function?
cm => { cm.AutoMap(); cm.SetDiscriminator(discriminator) }); I have found many descriptions of how to call generic methods, but can't get this to work.