Index the value of an Enum, not the string

后端 未结 2 1363
春和景丽
春和景丽 2021-01-24 05:45

Is it possible to index the value of an Enum instead of its string representation using Solrnet?

Say I have to following enum:

[Serializable]
[Flags] 
pu         


        
2条回答
  •  旧时难觅i
    2021-01-24 06:02

    Try this:

    [SolrField("gender")]
    public int GenderAsInt
    {
        get { return (int) Gender; }
        set { Gender = (Gender) value; }
    }
    
    public virtual Gender Gender { get; set; }
    

    Also note that declaring your enum as [Flags] doesn't make much sense:

    • There will hardly be anyone both Male and Female
    • Male will be interpreted as the default in respect to the current values of enum fields

提交回复
热议问题