Ejemplo n.º 1
0
        /// <summary>
        /// This is a helper method that converts a property to its string form and writes it to the given text
        /// writer.
        /// </summary>
        /// <param name="prop">The property to use.</param>
        /// <param name="sb"><para>A <see cref="System.Text.StringBuilder"/> used by the property to convert
        /// itself to a string.  This is a shared instance used by all properties written to the text writer.  It
        /// is cleared before the specified property is converted.</para>
        ///
        /// <para>It can be null if the TextWriter is a <see cref="System.IO.StringWriter"/>.  In that case, the
        /// property will append itself directly to its StringBuilder instead.</para></param>
        /// <param name="tw">A <see cref="System.IO.TextWriter"/> to which the string form is written.</param>
        /// <remarks>Properties use a StringBuilder to convert themselves to a string rather than writing
        /// directly to the TextWriter as they may need to manipulate the string to fold lines, etc.</remarks>
        /// <exception cref="InvalidCastException">This is thrown if the StringBuilder parameter is null and the
        /// TextWriter is not a StringWriter.</exception>
        public static void WriteToStream(BaseProperty prop, StringBuilder sb, TextWriter tw)
        {
            if (prop != null)
            {
                if (sb != null)
                {
                    sb.Length = 0;
                    prop.ToString(sb);

                    if (sb.Length != 0)
                    {
                        tw.Write(sb.ToString());
                    }
                }
                else
                {
                    prop.ToString(((StringWriter)tw).GetStringBuilder());
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This is overridden to allow proper comparison of property objects
        /// </summary>
        /// <param name="obj">The object to which this instance is compared</param>
        /// <returns>Returns true if the object equals this instance, false if it does not</returns>
        public override bool Equals(object obj)
        {
            BaseProperty bp = obj as BaseProperty;

            if (bp == null)
            {
                return(false);
            }

            // The ToString() method returns a text representation of the property based on all of its settings
            // so it's a reliable way to tell if two instances are the same.
            return(this == bp || this.ToString() == bp.ToString());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This is a helper method that converts a property to its string form and writes it to the given text
        /// writer.
        /// </summary>
        /// <param name="prop">The property to use.</param>
        /// <param name="sb"><para>A <see cref="System.Text.StringBuilder"/> used by the property to convert
        /// itself to a string.  This is a shared instance used by all properties written to the text writer.  It
        /// is cleared before the specified property is converted.</para>
        /// 
        /// <para>It can be null if the TextWriter is a <see cref="System.IO.StringWriter"/>.  In that case, the
        /// property will append itself directly to its StringBuilder instead.</para></param>
        /// <param name="tw">A <see cref="System.IO.TextWriter"/> to which the string form is written.</param>
        /// <remarks>Properties use a StringBuilder to convert themselves to a string rather than writing
        /// directly to the TextWriter as they may need to manipulate the string to fold lines, etc.</remarks>
        /// <exception cref="InvalidCastException">This is thrown if the StringBuilder parameter is null and the
        /// TextWriter is not a StringWriter.</exception>
        public static void WriteToStream(BaseProperty prop, StringBuilder sb, TextWriter tw)
        {
            if(prop != null)
                if(sb != null)
                {
                    sb.Length = 0;
                    prop.ToString(sb);

                    if(sb.Length != 0)
                        tw.Write(sb.ToString());
                }
                else
                    prop.ToString(((StringWriter)tw).GetStringBuilder());
        }