Skip to content

Commit e04ef32

Browse files
committed
删除包引用 System.Memory
1 parent 19c7076 commit e04ef32

3 files changed

Lines changed: 64 additions & 3 deletions

File tree

src/MiniExcel/MiniExcelLibs.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,4 @@
4343
<ItemGroup>
4444
<None Include="icon.png" Pack="true" PackagePath="\" />
4545
</ItemGroup>
46-
<ItemGroup Condition="'$(TargetFramework)' == 'net45' Or '$(TargetFramework)' == 'netstandard2.0'">
47-
<PackageReference Include="System.Memory" Version="4.5.5" />
48-
</ItemGroup>
4946
</Project>

src/MiniExcel/Utils/ImageHelper.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,43 @@ public enum ImageFormat
1616
unknown
1717
}
1818

19+
#if NET45||NETSTANDARD2_0
20+
public static ImageFormat GetImageFormat(byte[] bytes)
21+
{
22+
byte[] bmp = new byte[] { (byte)'B', (byte)'M' }; // BMP
23+
byte[] gif = new byte[] { (byte)'G', (byte)'I', (byte)'F' }; // GIF
24+
byte[] png = new byte[] { 137, 80, 78, 71 }; // PNG
25+
byte[] tiff = new byte[] { 73, 73, 42 }; // TIFF
26+
byte[] tiff2 = new byte[] { 77, 77, 42 }; // TIFF
27+
byte[] jpeg = new byte[] { 255, 216, 255, 224 }; // jpeg
28+
byte[] jpeg2 = new byte[] { 255, 216, 255, 225 }; // jpeg canon
29+
30+
if (bytes.StartsWith(bmp))
31+
return ImageFormat.bmp;
32+
33+
if (bytes.StartsWith(gif))
34+
return ImageFormat.gif;
35+
36+
if (bytes.StartsWith(png))
37+
return ImageFormat.png;
38+
39+
if (bytes.StartsWith(tiff))
40+
return ImageFormat.tiff;
41+
42+
if (bytes.StartsWith(tiff2))
43+
return ImageFormat.tiff;
44+
45+
if (bytes.StartsWith(jpeg))
46+
return ImageFormat.jpg;
47+
48+
if (bytes.StartsWith(jpeg2))
49+
return ImageFormat.jpg;
50+
51+
return ImageFormat.unknown;
52+
}
53+
#endif
54+
55+
#if NET5_0
1956
public static ImageFormat GetImageFormat(ReadOnlySpan<byte> bytes)
2057
{
2158
ReadOnlySpan<byte> bmp = stackalloc byte[] { (byte)'B', (byte)'M' }; // BMP
@@ -49,6 +86,8 @@ public static ImageFormat GetImageFormat(ReadOnlySpan<byte> bytes)
4986

5087
return ImageFormat.unknown;
5188
}
89+
#endif
90+
5291
}
5392

5493
}

src/MiniExcel/Utils/ListHelper.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
namespace MiniExcelLibs.Utils
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
7+
public static class IEnumerableHelper
8+
{
9+
public static bool StartsWith<T>(this IList<T> span, IList<T> value) where T : IEquatable<T>
10+
{
11+
if (value.Count() == 0)
12+
return true;
13+
14+
var b = span.Take(value.Count());
15+
if (b.Count() != value.Count())
16+
return false;
17+
18+
for (int i = 0; i < b.Count(); i++)
19+
if (!span[i].Equals(value[i]))
20+
return false;
21+
22+
return true;
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)