Beispiel #1
0
 /// <summary>
 /// Appends the specified style parts to the current one. The parts can be instances of sub-classes like Border or CellXf or a Style instance. Only the altered properties of the specified style or style part that differs from a new / untouched style instance will be appended. This enables method chaining
 /// </summary>
 /// <param name="styleToAppend">The style to append or a sub-class of Style</param>
 /// <returns>Current style with appended style parts</returns>
 public Style Append(AbstractStyle styleToAppend)
 {
     if (styleToAppend.GetType() == typeof(Border))
     {
         CurrentBorder.CopyProperties<Border>((Border)styleToAppend, new Border());
     }
     else if (styleToAppend.GetType() == typeof(CellXf))
     {
         CurrentCellXf.CopyProperties<CellXf>((CellXf)styleToAppend, new CellXf());
     }
     else if (styleToAppend.GetType() == typeof(Fill))
     {
         CurrentFill.CopyProperties<Fill>((Fill)styleToAppend, new Fill());
     }
     else if (styleToAppend.GetType() == typeof(Font))
     {
         CurrentFont.CopyProperties<Font>((Font)styleToAppend, new Font());
     }
     else if (styleToAppend.GetType() == typeof(NumberFormat))
     {
         CurrentNumberFormat.CopyProperties<NumberFormat>((NumberFormat)styleToAppend, new NumberFormat());
     }
     else if (styleToAppend.GetType() == typeof(Style))
     {
         CurrentBorder.CopyProperties<Border>(((Style)styleToAppend).CurrentBorder, new Border());
         CurrentCellXf.CopyProperties<CellXf>(((Style)styleToAppend).CurrentCellXf, new CellXf());
         CurrentFill.CopyProperties<Fill>(((Style)styleToAppend).CurrentFill, new Fill());
         CurrentFont.CopyProperties<Font>(((Style)styleToAppend).CurrentFont, new Font());
         CurrentNumberFormat.CopyProperties<NumberFormat>(((Style)styleToAppend).CurrentNumberFormat, new NumberFormat());
     }
     return this;
 }
Beispiel #2
0
 /// <summary>
 /// Method to copy the current object to a new one without casting
 /// </summary>
 /// <returns>Copy of the current object without the internal ID</returns>
 public override AbstractStyle Copy()
 {
     if (CurrentBorder == null || CurrentCellXf == null || CurrentFill == null || CurrentFont == null || CurrentNumberFormat == null)
     {
         throw new StyleException("MissingReferenceException", "The style could not be copied because one or more components are missing as references");
     }
     Style copy = new Style();
     copy.CurrentBorder = CurrentBorder.CopyBorder();
     copy.CurrentCellXf = CurrentCellXf.CopyCellXf();
     copy.CurrentFill = CurrentFill.CopyFill();
     copy.CurrentFont = CurrentFont.CopyFont();
     copy.CurrentNumberFormat = CurrentNumberFormat.CopyNumberFormat();
     return copy;
 }
Beispiel #3
0
        /// <summary>
        /// Override method to calculate the hash of this component
        /// </summary>
        /// <returns>Calculated hash as string</returns>
        public sealed override string CalculateHash()
        {
            StringBuilder sb = new StringBuilder();

            if (CurrentBorder == null || CurrentCellXf == null || CurrentFill == null || CurrentFont == null || CurrentNumberFormat == null)
            {
                throw new StyleException("MissingReferenceException", "The hash of the style could not be created because one or more components are missing as references");
            }
            sb.Append(StyleManager.STYLEPREFIX);
            if (InternalID.HasValue == true)
            {
                sb.Append(InternalID.Value);
                sb.Append(':');
            }
            sb.Append(CurrentBorder.CalculateHash());
            sb.Append(CurrentCellXf.CalculateHash());
            sb.Append(CurrentFill.CalculateHash());
            sb.Append(CurrentFont.CalculateHash());
            sb.Append(CurrentNumberFormat.CalculateHash());
            return(sb.ToString());
        }