Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.EPPlus/4.0.3/EPPlus-4.0.3/Style/Dxf/DxfStyleBase.cs @ 12074

Last change on this file since 12074 was 12074, checked in by sraggl, 9 years ago

#2341: Added EPPlus-4.0.3 to ExtLibs

File size: 3.2 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Globalization;
4using System.Linq;
5using System.Text;
6using System.Xml;
7
8namespace OfficeOpenXml.Style.Dxf
9{
10    public abstract class DxfStyleBase<T>
11    {
12        protected ExcelStyles _styles;
13        internal DxfStyleBase(ExcelStyles styles)
14        {
15            _styles = styles;
16            AllowChange = false; //Don't touch this value in the styles.xml (by default). When Dxfs is fully implemented this can be removed.
17        }
18        protected internal abstract string Id { get; }
19        protected internal abstract bool HasValue{get;}
20        protected internal abstract void CreateNodes(XmlHelper helper, string path);
21        protected internal abstract T Clone();
22        protected void SetValueColor(XmlHelper helper,string path, ExcelDxfColor color)
23        {
24            if (color != null && color.HasValue)
25            {
26                if (color.Color != null)
27                {
28                    SetValue(helper, path + "/@rgb", color.Color.Value.ToArgb().ToString("x"));
29                }
30                else if (color.Auto != null)
31                {
32                    SetValueBool(helper, path + "/@auto", color.Auto);
33                }
34                else if (color.Theme != null)
35                {
36                    SetValue(helper, path + "/@theme", color.Theme);
37                }
38                else if (color.Index != null)
39                {
40                    SetValue(helper, path + "/@indexed", color.Index);
41                }
42                if (color.Tint != null)
43                {
44                    SetValue(helper, path + "/@tint", color.Tint);
45                }
46            }
47        }
48        /// <summary>
49        /// Same as SetValue but will set first char to lower case.
50        /// </summary>
51        /// <param name="helper"></param>
52        /// <param name="path"></param>
53        /// <param name="v"></param>
54        protected void SetValueEnum(XmlHelper helper, string path, Enum v)
55        {
56            if (v == null)
57            {
58                helper.DeleteNode(path);
59            }
60            else
61            {
62                var s = v.ToString();
63                s = s.Substring(0, 1).ToLower(CultureInfo.InvariantCulture) + s.Substring(1);
64                helper.SetXmlNodeString(path, s);
65            }
66        }
67        protected void SetValue(XmlHelper helper, string path, object v)
68        {
69            if (v == null)
70            {
71                helper.DeleteNode(path);
72            }
73            else
74            {
75                helper.SetXmlNodeString(path, v.ToString());
76            }
77        }
78        protected void SetValueBool(XmlHelper helper, string path, bool? v)
79        {
80            if (v == null)
81            {
82                helper.DeleteNode(path);
83            }
84            else
85            {
86                helper.SetXmlNodeBool(path, (bool)v);
87            }
88        }
89        protected internal string GetAsString(object v)
90        {
91            return (v ?? "").ToString();
92        }
93        /// <summary>
94        /// Is this value allowed to be changed?
95        /// </summary>
96        protected internal bool AllowChange { get; set; }
97    }
98}
Note: See TracBrowser for help on using the repository browser.