简体   繁体   中英

How to declare generic property of type enum?

I have this Model : Filter

namespace SearchContent.Domains
{
    public class Filter
    {
        public enum FilterName {}; //<================== ???
        public string FilterDisplayName { get; set; }
        public string FilterRemoteName { get; set; }
    }
}

And this file : FiltersEnums.cs - list of enums

namespace SearchContent.Domains
{
    public enum filterType
    {
        series, movies, programs, channels
    }

    public enum filterGenre
    {
        action, drama, comedy, horror, documentary, russian
    }
}

I need that - "FilterName" can be a filterType or a filterGenre.

How i declear that property "FilterName" ?

You can use Enum class:

Enum enumGen; //declaring variable with Enum type

enumGen = filterType.series;

//and next you can do for example
enumGen = filterGenre.horror;

您可以使用Enum类型:

 public Enum FilterName { get; set; }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM