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

Take MVC to the Next Level in .NET

Rate me:
Please Sign up or sign in to vote.
4.62/5 (11 votes)
30 Apr 2013GPL315 min read 73.1K   858   75  
How to quickly build reusable and flexible WPF, Silverlight, or ASP.NET applications with the powerful Xomega Framework using the best MVVM principles.
// Copyright (c) 2010-2012 Xomega.Net. All rights reserved.

using System.Collections;

namespace Xomega.Framework
{
    /// <summary>
    /// A class that represents different formats that data property values can be converted to.
    /// </summary>
    public class ValueFormat
    {
        /// <summary>
        /// The format in which values are stored internally in data properties.
        /// The format is typically typed, that is an integer would be stored as an <c>int</c>.
        /// Whenever a value is set on a data property, it will always try to convert it 
        /// to the internal format first. If it fails to convert it, it may store it as is.
        /// For multivalued data properties, each value in the list will be converted to an internal format.
        /// </summary>
        public static readonly ValueFormat Internal = new ValueFormat();

        /// <summary>
        /// The format in which data property values are transported between layers
        /// during a service call. The format is typically typed and may or may not be
        /// the same as the internal format. For example, we may want to store a resolved
        /// <c>Header</c> object internally, but send only the ID part in a service call.
        /// </summary>
        public static readonly ValueFormat Transport = new ValueFormat();

        /// <summary>
        /// The string format in which the user inputs the value. It may or may not be the same
        /// as the format in which the value is displayed to the user when it's not editable.
        /// </summary>
        public static readonly ValueFormat EditString = new ValueFormat();

        /// <summary>
        /// The string format in which the value is displayed to the user when it's not editable.
        /// When internal value is an object such as <c>Header</c>, the display string may
        /// consist of a combination of several of its parts (see <see cref="Header.ToString(string)"/>).
        /// </summary>
        public static readonly ValueFormat DisplayString = new ValueFormat();

        /// <summary>
        /// Checks if the current format is one of the string formats.
        /// </summary>
        /// <returns>True this is a string format, otherwise false</returns>
        public virtual bool IsString()
        {
            return this == EditString || this == DisplayString;
        }

        /// <summary>
        /// Checks if the current format is one of the typed formats.
        /// </summary>
        /// <returns>True this is a typed format, otherwise false</returns>
        public virtual bool IsTyped()
        {
            return this == Internal || this == Transport;
        }

        #region Construction / Shutdown

        /// <summary>
        /// Protected constructor to allow defining additional value formats through subclasses.
        /// </summary>
        protected ValueFormat()
        {
            if (!startedUp) StartUp();
        }

        /// <summary>
        /// Finalizer that calls application shutdown hook.
        /// </summary>
        ~ValueFormat()
        {
            // The following is commented out since it seems to be unsafe
            // to shut down instrumentation in a garbage collection thread.
            // Need to come up with a way of calling ShutDown from a non-daemon thread.

            // make sure shutdown is called just once
            //if (!shutDown) ShutDown();
        }

        /// <summary>
        /// A flag to track the startup status.
        /// </summary>
        protected static bool startedUp = false;

        /// <summary>
        /// A startup hook that Dotfuscator can set the Setup attribute for.
        /// </summary>
        protected static void StartUp()
        {
            startedUp = true;
#if SILVERLIGHT
            Silverlight();
        }

        /// <summary>
        /// A feature hook that Dotfuscator can use to track Silverlight usage.
        /// </summary>
        protected static void Silverlight() { }
#else
        }
#endif

        /// <summary>
        /// A flag to track the shutdown status.
        /// </summary>
        protected static bool shutDown = false;

        /// <summary>
        /// A shutdown hook that Dotfuscator can set the Teardown attribute for.
        /// </summary>
        protected static void ShutDown() { shutDown = true; }

        #endregion
    }
}

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 GNU General Public License (GPLv3)


Written By
Architect Xomega.Net
United States United States
Xomega Team is striving to increase productivity and development quality by utilizing Model Driven Development coupled with Code Generation and the best design practices for application development.
We provide MDD tools, code generators and frameworks for Visual Studio and .Net development.
Visit us at http://www.xomega.net
This is a Organisation

1 members

Comments and Discussions