Skip to content

Commit

Permalink
✨ 优化API
Browse files Browse the repository at this point in the history
  • Loading branch information
xinansky committed Jul 1, 2024
1 parent de1c817 commit aefdb2c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;

#endregion
Expand Down Expand Up @@ -84,10 +85,8 @@ public static T GetMinValue<T>(this IList<T> array)
{
if (array is null) throw new ArgumentNullException(nameof(array));

var value = array[0];
foreach (var item in array)
if (value.CompareTo(item) > 0)
value = item;
var value = array[0];
foreach (var item in array.Where(item => value.CompareTo(item) > 0)) value = item;
return value;
}

Expand Down Expand Up @@ -155,10 +154,8 @@ public static T GetMaxValue<T>(this IList<T> array)
{
if (array is null) throw new ArgumentNullException(nameof(array));

var value = array[0];
foreach (var item in array)
if (value.CompareTo(item) < 0)
value = item;
var value = array[0];
foreach (var item in array.Where(item => value.CompareTo(item) < 0)) value = item;
return value;
}

Expand Down Expand Up @@ -231,4 +228,4 @@ public static (T, T) GetMaxMinValue<T>(this IList<T> array, in Func<T, T, sbyte>

#endregion
}
}
}
16 changes: 14 additions & 2 deletions Tools~/Common/Common/Script/Helper/IO/Binary/IO.Byte.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,19 @@ public static bool Write(
}

/// <summary>
/// 异步读取
/// 读取
/// </summary>
/// <param name="path">路径</param>
/// <param name="bufferSize">缓冲区大小</param>
public static Stream ReadStream(string path, in int bufferSize = 4096)
{
path = path.Replace('\\', Path.AltDirectorySeparatorChar);
if (!ExistsFile(path)) return Stream.Null;
return new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, bufferSize, false);
}

/// <summary>
/// 读取
/// </summary>
/// <param name="path">路径</param>
/// <param name="bufferSize">缓冲区大小</param>
Expand Down Expand Up @@ -114,4 +126,4 @@ public static byte[] Read(

#endregion
}
}
}

0 comments on commit aefdb2c

Please sign in to comment.