I have a model that needs to be saved in to a MongoDB collection. To get the collection name I have two options before me.
1) Attribute
I decorate the class with a custom attribute and use reflection to access the value inside it. I can then cache this with the type
to avoid future lookups.
[MongoCollection("Foo")]
public class Foo
{
}
2) Static Property
Here I have a static property in the class that contains the collection name.
public class Foo
{
public static string CollectionName { get { return "Foo"; } }
}
I find that I am inclined to go with the former as it looks and feels cleaner but some of the senior devs here are turning their nose up at the use of reflection.
Is there a case to be made for the first option or is it just better to go with option 2?
Aucun commentaire:
Enregistrer un commentaire