Ejemplo n.º 1
0
        /// <summary>
        /// Determines whether [is empty style] [the specified style].
        /// </summary>
        /// <param name="style">The style.</param>
        /// <returns>
        /// 	<c>true</c> if [is empty style] [the specified style]; otherwise, <c>false</c>.
        /// </returns>
        /// <remarks>Documented by Dev03, 2008-09-29</remarks>
        private bool IsEmptyStyle(ICardStyle style)
        {
            if (style == null) return true;
            bool result = true;

            Type typeCardStyle = style.GetType();
            foreach (PropertyInfo property in typeCardStyle.GetProperties())
            {
                if (property.GetType().Equals(typeof(ITextStyle)))
                {
                    ITextStyle textStyle = property.GetValue(style, null) as ITextStyle;
                    Type typeTextStyle = textStyle.GetType();
                    foreach (PropertyInfo prop in typeTextStyle.GetProperties())
                    {
                        if (prop.GetType().Equals(typeof(int)))
                        {
                            int value = (int)prop.GetValue(textStyle, null);
                            result = result && (value == 0);
                        }
                        else if (prop.GetType().Equals(typeof(string)))
                        {
                            string value = (string)prop.GetValue(textStyle, null);
                            result = result && (value.Length == 0);
                        }
                        else if (prop.GetType().Equals(typeof(System.Drawing.Color)))
                        {
                            System.Drawing.Color value = (System.Drawing.Color)prop.GetValue(textStyle, null);
                            result = result && (value == System.Drawing.Color.Empty);
                        }
                        else if (prop.GetType().Equals(typeof(System.Drawing.FontFamily)))
                        {
                            System.Drawing.FontFamily value = (System.Drawing.FontFamily)prop.GetValue(textStyle, null);
                            result = result && (value == null);
                        }
                        else if (prop.GetType().Equals(typeof(FontSizeUnit)))
                        {
                            FontSizeUnit value = (FontSizeUnit)prop.GetValue(textStyle, null);
                            result = result && (value == FontSizeUnit.Pixel);
                        }
                        else if (prop.GetType().Equals(typeof(CSSFontStyle)))
                        {
                            CSSFontStyle value = (CSSFontStyle)prop.GetValue(textStyle, null);
                            result = result && (value == CSSFontStyle.None);
                        }
                        else if (prop.GetType().Equals(typeof(HorizontalAlignment)))
                        {
                            HorizontalAlignment value = (HorizontalAlignment)prop.GetValue(textStyle, null);
                            result = result && (value == HorizontalAlignment.None);
                        }
                        else if (prop.GetType().Equals(typeof(VerticalAlignment)))
                        {
                            VerticalAlignment value = (VerticalAlignment)prop.GetValue(textStyle, null);
                            result = result && (value == VerticalAlignment.None);
                        }
                        else if (prop.Name == "OtherElements")
                        {
                            SerializableDictionary<string, string> otherElements = prop.GetValue(textStyle, null) as SerializableDictionary<string, string>;
                            result = result && (otherElements.Count == 0);
                        }
                    }
                }
            }
            return result;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Determines whether [is empty style] [the specified style].
        /// </summary>
        /// <param name="style">The style.</param>
        /// <returns>
        ///     <c>true</c> if [is empty style] [the specified style]; otherwise, <c>false</c>.
        /// </returns>
        /// <remarks>Documented by Dev03, 2008-09-29</remarks>
        private bool IsEmptyStyle(ICardStyle style)
        {
            if (style == null)
            {
                return(true);
            }
            bool result = true;

            Type typeCardStyle = style.GetType();

            foreach (PropertyInfo property in typeCardStyle.GetProperties())
            {
                if (property.GetType().Equals(typeof(ITextStyle)))
                {
                    ITextStyle textStyle     = property.GetValue(style, null) as ITextStyle;
                    Type       typeTextStyle = textStyle.GetType();
                    foreach (PropertyInfo prop in typeTextStyle.GetProperties())
                    {
                        if (prop.GetType().Equals(typeof(int)))
                        {
                            int value = (int)prop.GetValue(textStyle, null);
                            result = result && (value == 0);
                        }
                        else if (prop.GetType().Equals(typeof(string)))
                        {
                            string value = (string)prop.GetValue(textStyle, null);
                            result = result && (value.Length == 0);
                        }
                        else if (prop.GetType().Equals(typeof(System.Drawing.Color)))
                        {
                            System.Drawing.Color value = (System.Drawing.Color)prop.GetValue(textStyle, null);
                            result = result && (value == System.Drawing.Color.Empty);
                        }
                        else if (prop.GetType().Equals(typeof(System.Drawing.FontFamily)))
                        {
                            System.Drawing.FontFamily value = (System.Drawing.FontFamily)prop.GetValue(textStyle, null);
                            result = result && (value == null);
                        }
                        else if (prop.GetType().Equals(typeof(FontSizeUnit)))
                        {
                            FontSizeUnit value = (FontSizeUnit)prop.GetValue(textStyle, null);
                            result = result && (value == FontSizeUnit.Pixel);
                        }
                        else if (prop.GetType().Equals(typeof(CSSFontStyle)))
                        {
                            CSSFontStyle value = (CSSFontStyle)prop.GetValue(textStyle, null);
                            result = result && (value == CSSFontStyle.None);
                        }
                        else if (prop.GetType().Equals(typeof(HorizontalAlignment)))
                        {
                            HorizontalAlignment value = (HorizontalAlignment)prop.GetValue(textStyle, null);
                            result = result && (value == HorizontalAlignment.None);
                        }
                        else if (prop.GetType().Equals(typeof(VerticalAlignment)))
                        {
                            VerticalAlignment value = (VerticalAlignment)prop.GetValue(textStyle, null);
                            result = result && (value == VerticalAlignment.None);
                        }
                        else if (prop.Name == "OtherElements")
                        {
                            SerializableDictionary <string, string> otherElements = prop.GetValue(textStyle, null) as SerializableDictionary <string, string>;
                            result = result && (otherElements.Count == 0);
                        }
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Compares two objects that implement ICardStyle.
        /// </summary>
        /// <param name="one">The first ICardStyle object one.</param>
        /// <param name="two">The second ICardStyle object.</param>
        /// <remarks>Documented by Dev03, 2008-09-26</remarks>
        private void CompareStyles(ICardStyle one, ICardStyle two)
        {
            if ((one == null) || (two == null))
            {
                Assert.IsTrue(IsEmptyStyle(one), "Both styles should be null! (one)");
                Assert.IsTrue(IsEmptyStyle(two), "Both styles should be null! (two)");
                return;
            }

            Type typeCardStyle = one.GetType();
            foreach (PropertyInfo property in typeCardStyle.GetProperties())
            {
                if (property.GetType().Equals(typeof(ITextStyle)))
                {
                    ITextStyle textStyleOne = property.GetValue(one, null) as ITextStyle;
                    ITextStyle textStyleTwo = property.GetValue(two, null) as ITextStyle;
                    Type typeTextStyle = textStyleOne.GetType();
                    foreach (PropertyInfo prop in typeTextStyle.GetProperties())
                    {
                        if (prop.GetType().Equals(typeof(int)))
                        {
                            int valueOne = (int)prop.GetValue(textStyleOne, null);
                            int valueTwo = (int)prop.GetValue(textStyleTwo, null);
                            Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name));
                        }
                        else if (prop.GetType().Equals(typeof(string)))
                        {
                            string valueOne = (string)prop.GetValue(textStyleOne, null);
                            string valueTwo = (string)prop.GetValue(textStyleTwo, null);
                            Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name));
                        }
                        else if (prop.GetType().Equals(typeof(System.Drawing.Color)))
                        {
                            System.Drawing.Color valueOne = (System.Drawing.Color)prop.GetValue(textStyleOne, null);
                            System.Drawing.Color valueTwo = (System.Drawing.Color)prop.GetValue(textStyleTwo, null);
                            Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name));
                        }
                        else if (prop.GetType().Equals(typeof(System.Drawing.FontFamily)))
                        {
                            System.Drawing.FontFamily valueOne = (System.Drawing.FontFamily)prop.GetValue(textStyleOne, null);
                            System.Drawing.FontFamily valueTwo = (System.Drawing.FontFamily)prop.GetValue(textStyleTwo, null);
                            Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name));
                        }
                        else if (prop.GetType().Equals(typeof(FontSizeUnit)))
                        {
                            FontSizeUnit valueOne = (FontSizeUnit)prop.GetValue(textStyleOne, null);
                            FontSizeUnit valueTwo = (FontSizeUnit)prop.GetValue(textStyleTwo, null);
                            Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name));
                        }
                        else if (prop.GetType().Equals(typeof(CSSFontStyle)))
                        {
                            CSSFontStyle valueOne = (CSSFontStyle)prop.GetValue(textStyleOne, null);
                            CSSFontStyle valueTwo = (CSSFontStyle)prop.GetValue(textStyleTwo, null);
                            Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name));
                        }
                        else if (prop.GetType().Equals(typeof(HorizontalAlignment)))
                        {
                            HorizontalAlignment valueOne = (HorizontalAlignment)prop.GetValue(textStyleOne, null);
                            HorizontalAlignment valueTwo = (HorizontalAlignment)prop.GetValue(textStyleTwo, null);
                            Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name));
                        }
                        else if (prop.GetType().Equals(typeof(VerticalAlignment)))
                        {
                            VerticalAlignment valueOne = (VerticalAlignment)prop.GetValue(textStyleOne, null);
                            VerticalAlignment valueTwo = (VerticalAlignment)prop.GetValue(textStyleTwo, null);
                            Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name));
                        }
                        else if (prop.Name == "OtherElements")
                        {
                            SerializableDictionary<string, string> otherElementsOne = prop.GetValue(textStyleOne, null) as SerializableDictionary<string, string>;
                            SerializableDictionary<string, string> otherElementsTwo = prop.GetValue(textStyleTwo, null) as SerializableDictionary<string, string>;
                            foreach (string key in otherElementsOne.Keys)
                            {
                                Assert.IsTrue((otherElementsTwo.ContainsKey(key) && otherElementsOne[key].Equals(otherElementsTwo[key])), String.Format("Both values for {0}[{1}] should be equal!", prop.Name, key));
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Compares two objects that implement ICardStyle.
        /// </summary>
        /// <param name="one">The first ICardStyle object one.</param>
        /// <param name="two">The second ICardStyle object.</param>
        /// <remarks>Documented by Dev03, 2008-09-26</remarks>
        private void CompareStyles(ICardStyle one, ICardStyle two)
        {
            if ((one == null) || (two == null))
            {
                Assert.IsTrue(IsEmptyStyle(one), "Both styles should be null! (one)");
                Assert.IsTrue(IsEmptyStyle(two), "Both styles should be null! (two)");
                return;
            }

            Type typeCardStyle = one.GetType();

            foreach (PropertyInfo property in typeCardStyle.GetProperties())
            {
                if (property.GetType().Equals(typeof(ITextStyle)))
                {
                    ITextStyle textStyleOne  = property.GetValue(one, null) as ITextStyle;
                    ITextStyle textStyleTwo  = property.GetValue(two, null) as ITextStyle;
                    Type       typeTextStyle = textStyleOne.GetType();
                    foreach (PropertyInfo prop in typeTextStyle.GetProperties())
                    {
                        if (prop.GetType().Equals(typeof(int)))
                        {
                            int valueOne = (int)prop.GetValue(textStyleOne, null);
                            int valueTwo = (int)prop.GetValue(textStyleTwo, null);
                            Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name));
                        }
                        else if (prop.GetType().Equals(typeof(string)))
                        {
                            string valueOne = (string)prop.GetValue(textStyleOne, null);
                            string valueTwo = (string)prop.GetValue(textStyleTwo, null);
                            Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name));
                        }
                        else if (prop.GetType().Equals(typeof(System.Drawing.Color)))
                        {
                            System.Drawing.Color valueOne = (System.Drawing.Color)prop.GetValue(textStyleOne, null);
                            System.Drawing.Color valueTwo = (System.Drawing.Color)prop.GetValue(textStyleTwo, null);
                            Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name));
                        }
                        else if (prop.GetType().Equals(typeof(System.Drawing.FontFamily)))
                        {
                            System.Drawing.FontFamily valueOne = (System.Drawing.FontFamily)prop.GetValue(textStyleOne, null);
                            System.Drawing.FontFamily valueTwo = (System.Drawing.FontFamily)prop.GetValue(textStyleTwo, null);
                            Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name));
                        }
                        else if (prop.GetType().Equals(typeof(FontSizeUnit)))
                        {
                            FontSizeUnit valueOne = (FontSizeUnit)prop.GetValue(textStyleOne, null);
                            FontSizeUnit valueTwo = (FontSizeUnit)prop.GetValue(textStyleTwo, null);
                            Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name));
                        }
                        else if (prop.GetType().Equals(typeof(CSSFontStyle)))
                        {
                            CSSFontStyle valueOne = (CSSFontStyle)prop.GetValue(textStyleOne, null);
                            CSSFontStyle valueTwo = (CSSFontStyle)prop.GetValue(textStyleTwo, null);
                            Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name));
                        }
                        else if (prop.GetType().Equals(typeof(HorizontalAlignment)))
                        {
                            HorizontalAlignment valueOne = (HorizontalAlignment)prop.GetValue(textStyleOne, null);
                            HorizontalAlignment valueTwo = (HorizontalAlignment)prop.GetValue(textStyleTwo, null);
                            Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name));
                        }
                        else if (prop.GetType().Equals(typeof(VerticalAlignment)))
                        {
                            VerticalAlignment valueOne = (VerticalAlignment)prop.GetValue(textStyleOne, null);
                            VerticalAlignment valueTwo = (VerticalAlignment)prop.GetValue(textStyleTwo, null);
                            Assert.AreEqual(valueOne, valueOne, String.Format("Both values for {0} should be equal!", prop.Name));
                        }
                        else if (prop.Name == "OtherElements")
                        {
                            SerializableDictionary <string, string> otherElementsOne = prop.GetValue(textStyleOne, null) as SerializableDictionary <string, string>;
                            SerializableDictionary <string, string> otherElementsTwo = prop.GetValue(textStyleTwo, null) as SerializableDictionary <string, string>;
                            foreach (string key in otherElementsOne.Keys)
                            {
                                Assert.IsTrue((otherElementsTwo.ContainsKey(key) && otherElementsOne[key].Equals(otherElementsTwo[key])), String.Format("Both values for {0}[{1}] should be equal!", prop.Name, key));
                            }
                        }
                    }
                }
            }
        }