Click here to Skip to main content
15,892,161 members
Articles / Web Development / ASP.NET

Signum Framework Principles

Rate me:
Please Sign up or sign in to vote.
4.74/5 (27 votes)
25 Jul 2011CPOL18 min read 99.4K   1.1K   86  
Explains the philosophy behind Signum Framework, an ORM with a full LINQ Provider that encourages an entities-first approach.
//---------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation.  All rights reserved.
//
//---------------------------------------------------------------------------

using System;

namespace Signum.Windows.DateUtils
{
    /// <summary>
    /// This class is used to save the cost of Boxing/UnBoxing boolean values
    /// </summary>
    internal static class BooleanBoxes
    {
        internal static object TrueBox = true;
        internal static object FalseBox = false;

        internal static object Box(bool value)
        {
            if (value)
            {
                return TrueBox;
            }
            else
            {
                return FalseBox;
            }
        }
    }

    /// <summary>
    /// Static helper class
    /// </summary>
    internal static class MonthCalendarHelper
    {
        /// <summary>
        /// Compare the year and month of dt1 and dt2
        /// </summary>
        /// <returns>
        /// less than 0    : dt1 &lt; dt2; 
        /// equal 0        : dt1 == dt2; 
        /// greater than 0 : dt1 &gt; dt2
        /// </returns>
        internal static int CompareYearMonth(DateTime dt1, DateTime dt2)
        {
            return SubtractByMonth(dt1, dt2);
        }

        /// <summary>
        /// Compare the year,month,day of dt1 and dt2
        /// </summary>
        /// <returns>
        /// less than 0    : dt1 &lt; dt2; 
        /// equal 0        : dt1 == dt2; 
        /// greater than 0 : dt1 &gt; dt2
        /// </returns>
        internal static int CompareYearMonthDay(DateTime dt1, DateTime dt2)
        {
            return (dt1.Date - dt2.Date).Days;
        }

        /// <summary>
        /// dt1 subtract dt2 to get the month count between them
        /// </summary>
        /// <returns>the months between dt1 and dt2</returns>
        internal static int SubtractByMonth(DateTime dt1, DateTime dt2)
        {
            return (dt1.Year - dt2.Year) * 12 + (dt1.Month - dt2.Month);
        }

        /// <summary>
        /// True if date is between start and end
        /// </summary>
        internal static bool IsWithinRange(DateTime date, DateTime start, DateTime end)
        {
            return CompareYearMonthDay(date, start) >= 0 && CompareYearMonthDay(date, end) <= 0;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Signum Software
Spain Spain
I'm Computer Scientist, one of the founders of Signum Software, and the lead developer behind Signum Framework.

www.signumframework.com

I love programming in C#, Linq, Compilers, Algorithms, Functional Programming, Computer Graphics, Maths...

Comments and Discussions