diff --git a/ClosedXML/Extensions.cs b/ClosedXML/Extensions.cs index aaca2a7..304355a 100644 --- a/ClosedXML/Extensions.cs +++ b/ClosedXML/Extensions.cs @@ -1,30 +1,28 @@ -using System; -using System.Collections; +using ClosedXML.Utils; +using DocumentFormat.OpenXml; +using System; using System.Collections.Generic; using System.Drawing; using System.Globalization; +using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; -using System.Xml.Linq; -using System.IO; using System.Xml; -using ClosedXML.Utils; -using DocumentFormat.OpenXml; +using System.Xml.Linq; [assembly: CLSCompliantAttribute(true)] + namespace ClosedXML.Excel { public static class Extensions { // Adds the .ForEach method to all IEnumerables - - private static readonly char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; + private static readonly char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; public static String ToHex(this Color color) { - byte[] bytes = new byte[4]; bytes[0] = color.A; @@ -39,17 +37,14 @@ for (int i = 0; i < bytes.Length; i++) { - int b = bytes[i]; chars[i * 2] = hexDigits[b >> 4]; chars[i * 2 + 1] = hexDigits[b & 0xF]; - } return new string(chars); - } public static String RemoveSpecialCharacters(this String str) @@ -75,10 +70,10 @@ HashSet distinctItems = new HashSet(); foreach (var item in source) { - if (!distinctItems.Add(item)) - { - return true; - } + if (!distinctItems.Add(item)) + { + return true; + } } return false; } @@ -87,7 +82,6 @@ { return (T)Convert.ChangeType(o, typeof(T)); } - } public static class DictionaryExtensions @@ -106,6 +100,7 @@ public static class StringExtensions { private static readonly Regex RegexNewLine = new Regex(@"((? intToString; public static String ToInvariantString(this Int32 value) { - String sValue; - if (intToString == null) - { - intToString = new Dictionary(); - sValue = value.ToString(nfi); - intToString.Add(value, sValue); - } - else - { - if (!intToString.TryGetValue(value, out sValue)) - { - sValue = value.ToString(nfi); - intToString.Add(value, sValue); - } - } - return sValue; + return value.ToString(CultureInfo.InvariantCulture.NumberFormat); } - } public static class DecimalExtensions @@ -233,7 +208,6 @@ public static class FontBaseExtensions { - private static Font GetCachedFont(IXLFontBase fontBase, Dictionary fontCache) { Font font; @@ -266,7 +240,7 @@ if (font.Bold) fontStyle |= FontStyle.Bold; if (font.Italic) fontStyle |= FontStyle.Italic; if (font.Strikethrough) fontStyle |= FontStyle.Strikeout; - if (font.Underline != XLFontUnderlineValues.None ) fontStyle |= FontStyle.Underline; + if (font.Underline != XLFontUnderlineValues.None) fontStyle |= FontStyle.Underline; return fontStyle; } @@ -343,4 +317,3 @@ } } } -