Set an enum property using an integer & validate the argument
<p><strong>EDIT: I have changed the title of the question to include the validation of the argument, to be clearer what I am asking.</strong></p>

<p>I am attempting to create a class in C# which has a property that is set with an int and returns an enum, this may be really basic but I am a C# noob.</p>

<p>The setting by use of an int argument is a particular limitation that I won't go into and is something that is getting set over COM in Vbscript.</p>

<p>I am looking to create these RSSCalendarDay objects so they can be put in a list and each have a unique RSSCalendarRuleDay from Sunday to Saturday (1 to 7).</p>

<p>Its for part of a really basic approach to using xCal with local data to make recurring events.</p>

<p>My code so far is below and you can see the get &amp; set are incomplete, I am stuck on the validation of the argument (check its an int first, etc), thats what I was previously trying to use dayOrderValue for, and all I could find online in relation was the use of int.Parse and int.TryParse but they were for parsing a string, not for what I want to do.</p>

<pre><code>public class RSSCalendarDay {

    private RSSCalendarRuleDay? _dayOrder;
    /// &lt;summary&gt;
    /// Passed an Integer from 1 to 7 to represent the particular day of the week as an enum
    /// &lt;/summary&gt;
    public RSSCalendarRuleDay? DayOrder {
        get {
                       // TODO
        } 
        set {
            if (value != null) {
                int dayOrderValue;
                if () {
                    throw new ArgumentException("Invalid day order specified");
                }
                if(dayOrderValue &lt; 1 || dayOrderValue &gt; 7) {
                    throw new ArgumentException("Invalid day type specified (out of day range of 1 to 7)");
                }
                _dayOrder = (RSSCalendarRuleDay) dayOrderValue;
            }
            else {
                _dayOrder = null;
            }
        } 
    }
    public DateTime? TimeOpens { get; set; }
    public DateTime? TimeCloses { get; set; }

    /// &lt;summary&gt;
    /// These are the relevant BYDAY abbreviations used in the xCal recurring rule specification
    /// to represent what days a recurring event is open in a comma separated list
    /// &lt;/summary&gt;
    public enum RSSCalendarRuleDay {
        SU=1,MO=2,TU=3,WE=4,TH=5,FR=6,SA=7
    }
}
</code></pre>
