mardi 6 octobre 2020

Performance impact of using reflection instead of an "Options" class

I am trying to refactor a service by providing some options on what to bring back. I can't decide what is best way to go between the below

A. Use a class for the options Create a new class for the options like

    public class Options
    {
        public bool Addresses { get; set; }
        public bool Documents { get; set; }
    }

and call the services as below

    public List<Entity> GetEntitiesByOptions(List<int> entityIds, Options options)
    {
        if (options.Addresses)
        {
            // Add the addresses
        }

        if (options.Documents)
        {
            // Add the Documents
        }
    }

or B. Use the type of class as a parameter

and use with something like that

    public List<Entity> GetEntitiesByOptions(List<int> entityIds, List<Type> options)
    {
        if (options.Any(x => x == typeof(Address)))
        {
            // Add the addresses
        }

        if (options.Any(x => x == typeof(Document)))
        {
            // Add the Documents
        }
    }

Would there be a big impact in the performance if I use reflection?





Aucun commentaire:

Enregistrer un commentaire