none
Return statement found in contract section

    Question

  • I have a property

            private byte? dayOfMonth;
            public byte? DayOfMonth
            {
                get
                {
                    return dayOfMonth;
                }
                set
                {
                    Contract.Requires<ArgumentOutOfRangeException>(ScheduleContractConditions.IsDayOfMonthCorrect(value));
                    if (!SetProperty<byte?>(ref dayOfMonth, value))
                        return;
                    SetProperty<DateTime>(ref finishDate, startDate);
                }
            }

    And static pure method to check condition

        internal static class ScheduleContractConditions
        {
            [Pure]
            public static bool IsDayOfMonthCorrect(byte? dayOfMonth)
            {
                return !dayOfMonth.HasValue || IsDayOfMonthCorrect(dayOfMonth.Value);
            }
    
            [Pure]
            public static bool IsDayOfMonthCorrect(byte dayOfMonth)
            {
                return dayOfMonth >= 1 && dayOfMonth <= 31;
            }
        }

    And I receive an error "Return statement found in contract section." Used build 1.5.60911.10

    Is this a my mistake or a bug?

    Monday, September 16, 2013 8:03 PM

Answers

  • Error was caused by Fody.PropertyChanged rewriter.

    Need to use [DoNotNotify] attribute:

            [DoNotNotify]
            public byte? DayOfMonth
            {
                get
                {
                    return dayOfMonth;
                }
                set
                {
                    Contract.Requires<ArgumentOutOfRangeException>(ScheduleContractConditions.IsDayOfMonthCorrect(value));
                    if (!SetProperty<byte?>(ref dayOfMonth, value))
                        return;
                    SetProperty<DateTime>(ref finishDate, startDate);
                }
            }


    • Edited by Xperiandri Friday, September 27, 2013 10:04 AM
    • Marked as answer by Xperiandri Friday, September 27, 2013 10:04 AM
    Friday, September 27, 2013 10:04 AM