#region File Description //----------------------------------------------------------------------------- // CommonState.cs // // Microsoft XNA Community Game Platform // Copyright (C) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- #endregion //----------------------------------------------------------------------------- // CommonState.cs // // Microsoft XNA Community Game Platform // Copyright (C) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- #region Using Statements using System; using System.Collections.Generic; using System.Text; #endregion namespace Xna.Tools { /// /// This generic class holds common stae of multiple states. /// /// class CommonState where T: struct { #region Properties /// /// Gets common value. /// public T Value { get { return value; } } /// /// Gets common value string. /// public string ValueString { get { return ( hasValue && hasSameValues ) ? value.ToString() : String.Empty; } } /// /// Gets HasSameValue that returns true if added states are common. /// public bool HasSameValue { get { return hasSameValues; } } /// /// Gets number of added states. /// public int Count { get { return count; } } #endregion #region Constructor public CommonState() { hasValue = false; hasSameValues = true; count = 0; } #endregion /// /// Add new state to group. /// /// public void Add(T value) { if (!hasValue) { this.value = value; hasValue = true; } if ( !Object.Equals(this.value, value)) hasSameValues = false; count++; } #region Private Members private T value; private bool hasValue; private bool hasSameValues; private int count; #endregion } }