Skip to content

Commit 436a600

Browse files
committed
Use benefits of FrozenDictionary only for net8, no cumbersome net462 with an additional package
1 parent 9b8f240 commit 436a600

File tree

4 files changed

+22
-21
lines changed

4 files changed

+22
-21
lines changed

src/Html2OpenXml/Expressions/Numbering/NumberingExpressionBase.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
* IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
1010
* PARTICULAR PURPOSE.
1111
*/
12+
#if NET5_0_OR_GREATER
1213
using System.Collections.Frozen;
14+
#endif
1315
using System.Collections.Generic;
1416
using System.Linq;
1517
using AngleSharp.Html.Dom;
@@ -293,6 +295,10 @@ private static IReadOnlyDictionary<string, AbstractNum> InitKnownLists()
293295
knownAbstractNums.Add(listName, abstractNum);
294296
}
295297

298+
#if NET5_0_OR_GREATER
296299
return knownAbstractNums.ToFrozenDictionary();
300+
#else
301+
return knownAbstractNums;
302+
#endif
297303
}
298304
}

src/Html2OpenXml/HtmlToOpenXml.csproj

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@
3737
<ItemGroup Condition=" '$(TargetFramework)' == 'net462' ">
3838
<Reference Include="System.Net.Http" />
3939
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
40-
<PackageReference Include="System.Collections.Immutable" Version="9.0.0" />
41-
</ItemGroup>
42-
43-
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
44-
<PackageReference Include="System.Collections.Immutable" Version="9.0.0" />
4540
</ItemGroup>
4641

4742
<PropertyGroup Condition=" '$(TargetFramework)' == 'net8.0' ">

src/Html2OpenXml/IO/ImageHeader.cs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* EMF Specifications: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-emf/ae7e7437-cfe5-485e-84ea-c74b51b000be
1515
*/
1616
using System;
17-
using System.Collections.Frozen;
1817
using System.Collections.Generic;
1918
using System.IO;
2019
using System.Linq;
@@ -36,22 +35,17 @@ public enum FileType { Unrecognized, Bitmap, Gif, Png, Jpeg, Emf, Xml }
3635

3736
private static readonly byte[] pngSignatureBytes = [0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A];
3837

39-
private static readonly IReadOnlyDictionary<byte[], FileType> imageFormatDecoders = InitKnownFormatDecoders();
40-
41-
private static IReadOnlyDictionary<byte[], FileType> InitKnownFormatDecoders()
38+
private static readonly Dictionary<byte[], FileType> imageFormatDecoders = new()
4239
{
43-
var decoders = new Dictionary<byte[], FileType>() {
44-
{ new byte[] { 0x42, 0x4D }, FileType.Bitmap },
45-
{ Encoding.UTF8.GetBytes("GIF87a"), FileType.Gif },
46-
{ Encoding.UTF8.GetBytes("GIF89a"), FileType.Gif }, // animated gif
47-
{ pngSignatureBytes, FileType.Png },
48-
{ new byte[] { 0xff, 0xd8 }, FileType.Jpeg },
49-
{ new byte[] { 0x1, 0, 0, 0 }, FileType.Emf },
50-
{ Encoding.UTF8.GetBytes("<?xml "), FileType.Xml }, // Xml so potentially Svg
51-
};
52-
53-
return decoders.ToFrozenDictionary();
54-
}
40+
{ new byte[] { 0x42, 0x4D }, FileType.Bitmap },
41+
{ Encoding.UTF8.GetBytes("GIF87a"), FileType.Gif },
42+
{ Encoding.UTF8.GetBytes("GIF89a"), FileType.Gif }, // animated gif
43+
{ pngSignatureBytes, FileType.Png },
44+
{ new byte[] { 0xff, 0xd8 }, FileType.Jpeg },
45+
{ new byte[] { 0x1, 0, 0, 0 }, FileType.Emf },
46+
{ Encoding.UTF8.GetBytes("<?xml "), FileType.Xml }, // Xml so potentially Svg
47+
};
48+
5549

5650
private static readonly int MaxMagicBytesLength = imageFormatDecoders
5751
.Keys.OrderByDescending(x => x.Length).First().Length;

src/Html2OpenXml/Primitives/HtmlColor.Named.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
#if NET5_0_OR_GREATER
23
using System.Collections.Frozen;
4+
#endif
35
using System.Collections.Generic;
46

57
namespace HtmlToOpenXml;
@@ -169,6 +171,10 @@ private static IReadOnlyDictionary<string, HtmlColor> InitKnownColors()
169171
{ "transparent", FromArgb(0, 0, 0, 0) }
170172
};
171173

174+
#if NET5_0_OR_GREATER
172175
return colors.ToFrozenDictionary();
176+
#else
177+
return colors;
178+
#endif
173179
}
174180
}

0 commit comments

Comments
 (0)