lundi 5 décembre 2016

c# mvc get generic type using reflection

Currently trying to find a way to get the type of a generically typed class and have been unable to find a way to do so. My current, working method looks as follows:

public class CategoryConfiguration : EntityTypeConfiguration<Category>
    {
        public CategoryConfiguration()
        {
            ToTable("Categories");
            Property(c => c.Name).IsRequired().HasMaxLength(50);
        }
    }

and I'd like to change this method to be something like:

public class CategoryConfiguration : EntityTypeConfiguration<T>
    {
        public CategoryConfiguration()
        {
            ToTable(/*get string representation of 'T' here and pluralize*/);
            Property(c => c.Name).IsRequired().HasMaxLength(50);
        }
    }





Aucun commentaire:

Enregistrer un commentaire