Quantcast
Viewing latest article 4
Browse Latest Browse All 6

Enum accepting any string

Here is the enum:

    [DataContract]
    public enum ActionType
    {
        [EnumMember]
        Attorney = 1,

        [EnumMember]
        SuitAction = 2,

        [EnumMember]
        SuitDate = 3,

        [EnumMember]
        La5108 = 4
    }

Here is the entity that contains the enum and is returned by the service:

    [DataContract]
    public class SuitAction : IsActiveBase
    {
        Entities.Action action;
        DateTime? actionDate, dateStamp, modifiedDate;
        String comment;
        User createdByUser, modifiedByUser;
        Int32? suitId;

        [DataMember]
        public Entities.Action Action
        {
            get { return action; }
            set { action = value; }
        }

        [DataMember]
        public DateTime? ActionDate
        {
            get { return actionDate; }
            set { actionDate = value; }
        }

        [DataMember]
        public String Comment
        {
            get { return comment; }
            set { comment = value; }
        }

        [DataMember]
        public User CreatedByUser
        {
            get { return createdByUser; }
            set { createdByUser = value; }
        }

        [DataMember]
        public DateTime? DateStamp
        {
            get { return dateStamp; }
            set { dateStamp = value; }
        }

        [DataMember]
        public User ModifiedByUser
        {
            get { return modifiedByUser; }
            set { modifiedByUser = value; }
        }

        [DataMember]
        public DateTime? ModifiedDate
        {
            get { return modifiedDate; }
            set { modifiedDate = value; }
        }

        [DataMember]
        public Int32? SuitId
        {
            get { return suitId; }
            set { suitId = value; }
        }
    }
The code that loads it from the database:
        IList<SuitAction> la5108ActionList = new List<SuitAction>();
            if (dataReader.NextResult())
                while (dataReader.Read())
                    la5108ActionList.Add(new SuitAction()
                    {
                        ActionType = dataReader.GetEnum<ActionType?>("ActionTypeDescription") 
                        // other fields omitted for brevity 
                    });
            return la5108ActionList;

The value that comes back from the database is 5108.  This is also the value that gets assigned to the enum, which C# accepts for some weird reason.  The assembly is shared, so the client receives a list of SuitAction entities.



Viewing latest article 4
Browse Latest Browse All 6

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>