ref: 将 MeloongCore 的 WPF 部分独立到另一个子工程
This commit is contained in:
1 parent
1036bc9642
commit
1910e96567
13 files changed
+103
-29
No files matched your search
@@ -0,0 +1,5 @@
|
||||
|
||||
[*.{cs,vb}]
|
||||
|
||||
# CA1710: 标识符应具有正确的后缀
|
||||
dotnet_diagnostic.CA1710.severity = none
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace MeloongCore.Extensions;
|
||||
using System.Globalization;
|
||||
|
||||
namespace MeloongCore.Extensions;
|
||||
public static class EnumerableExtensions {
|
||||
|
||||
#region Distinct
|
||||
@@ -37,16 +39,16 @@ public static class EnumerableExtensions {
|
||||
/// 选择所有最大值对应的对象。
|
||||
/// 若没有元素则返回空列表。
|
||||
/// </summary>
|
||||
public static List<T> MaxByAll<T, C>(this IEnumerable<T> source, Func<T, C> selector) where C : IComparable<C> {
|
||||
var results = new List<T>();
|
||||
public static List<TKey> MaxByAll<TKey, TValue>(this IEnumerable<TKey> source, Func<TKey, TValue> selector) where TValue : IComparable<TValue> {
|
||||
var results = new List<TKey>();
|
||||
using var enumerator = source.GetEnumerator();
|
||||
if (!enumerator.MoveNext()) return results;
|
||||
T maxItem = enumerator.Current;
|
||||
C maxValue = selector(maxItem);
|
||||
TKey maxItem = enumerator.Current;
|
||||
TValue maxValue = selector(maxItem);
|
||||
results.Add(maxItem);
|
||||
while (enumerator.MoveNext()) {
|
||||
T currentItem = enumerator.Current;
|
||||
C currentValue = selector(currentItem);
|
||||
TKey currentItem = enumerator.Current;
|
||||
TValue currentValue = selector(currentItem);
|
||||
int comparisonResult = currentValue.CompareTo(maxValue);
|
||||
if (comparisonResult > 0) {
|
||||
maxValue = currentValue;
|
||||
@@ -62,16 +64,16 @@ public static class EnumerableExtensions {
|
||||
/// 选择所有最小值对应的对象。
|
||||
/// 若没有元素则返回空列表。
|
||||
/// </summary>
|
||||
public static List<T> MinByAll<T, C>(this IEnumerable<T> source, Func<T, C> selector) where C : IComparable<C> {
|
||||
var results = new List<T>();
|
||||
public static List<TKey> MinByAll<TKey, TValue>(this IEnumerable<TKey> source, Func<TKey, TValue> selector) where TValue : IComparable<TValue> {
|
||||
var results = new List<TKey>();
|
||||
using var enumerator = source.GetEnumerator();
|
||||
if (!enumerator.MoveNext()) return results;
|
||||
T minItem = enumerator.Current;
|
||||
C minValue = selector(minItem);
|
||||
TKey minItem = enumerator.Current;
|
||||
TValue minValue = selector(minItem);
|
||||
results.Add(minItem);
|
||||
while (enumerator.MoveNext()) {
|
||||
T currentItem = enumerator.Current;
|
||||
C currentValue = selector(currentItem);
|
||||
TKey currentItem = enumerator.Current;
|
||||
TValue currentValue = selector(currentItem);
|
||||
int comparisonResult = currentValue.CompareTo(minValue);
|
||||
if (comparisonResult < 0) {
|
||||
minValue = currentValue;
|
||||
@@ -88,13 +90,13 @@ public static class EnumerableExtensions {
|
||||
/// 选择最大值对应的对象。
|
||||
/// 若没有元素则返回 null。
|
||||
/// </summary>
|
||||
public static T? MaxBy<T, C>(this IEnumerable<T> source, Func<T, C> selector) where C : IComparable<C> {
|
||||
public static TKey? MaxBy<TKey, TValue>(this IEnumerable<TKey> source, Func<TKey, TValue> selector) where TValue : IComparable<TValue> {
|
||||
using var enumerator = source.GetEnumerator();
|
||||
if (!enumerator.MoveNext()) return default;
|
||||
T maxItem = enumerator.Current;
|
||||
C maxValue = selector(maxItem);
|
||||
TKey maxItem = enumerator.Current;
|
||||
TValue maxValue = selector(maxItem);
|
||||
while (enumerator.MoveNext()) {
|
||||
C value = selector(enumerator.Current);
|
||||
TValue value = selector(enumerator.Current);
|
||||
if (value.CompareTo(maxValue) <= 0) continue;
|
||||
maxItem = enumerator.Current;
|
||||
maxValue = value;
|
||||
@@ -105,13 +107,13 @@ public static class EnumerableExtensions {
|
||||
/// 选择最小值对应的对象。
|
||||
/// 若没有元素则返回 null。
|
||||
/// </summary>
|
||||
public static T? MinBy<T, C>(this IEnumerable<T> List, Func<T, C> Selector) where C : IComparable<C> {
|
||||
public static TKey? MinBy<TKey, TValue>(this IEnumerable<TKey> List, Func<TKey, TValue> Selector) where TValue : IComparable<TValue> {
|
||||
using var enumerator = List.GetEnumerator();
|
||||
if (!enumerator.MoveNext()) { return default; }
|
||||
T minItem = enumerator.Current;
|
||||
C minValue = Selector(minItem);
|
||||
TKey minItem = enumerator.Current;
|
||||
TValue minValue = Selector(minItem);
|
||||
while (enumerator.MoveNext()) {
|
||||
C value = Selector(enumerator.Current);
|
||||
TValue value = Selector(enumerator.Current);
|
||||
if (value.CompareTo(minValue) >= 0) { continue; }
|
||||
minItem = enumerator.Current;
|
||||
minValue = value;
|
||||
@@ -204,7 +206,7 @@ public static class EnumerableExtensions {
|
||||
/// </remarks>
|
||||
public static IEnumerable<T> Flags<T>(this T value) where T : struct, Enum {
|
||||
foreach (var element in Enum.GetValues(typeof(T)).Cast<T>().Distinct()) {
|
||||
var number = Convert.ToInt64(element);
|
||||
var number = Convert.ToInt64(element, CultureInfo.InvariantCulture);
|
||||
if (number == 0 || (number & (number - 1)) != 0) continue; // 跳过 0 和非 2 的幂的值
|
||||
if (value.HasFlag(element)) yield return element;
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -11,7 +11,8 @@
|
||||
<Deterministic>true</Deterministic>
|
||||
<LangVersion>13.0</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<AnalysisLevel>8.0</AnalysisLevel>
|
||||
<AnalysisLevel>latest-recommended</AnalysisLevel>
|
||||
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -23,7 +24,6 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="PresentationFramework" />
|
||||
<Reference Include="System.ServiceModel" />
|
||||
</ItemGroup>
|
||||
|
||||
File renamed without changes.
File renamed without changes.
@@ -64,12 +64,14 @@ public static class FileUtils {
|
||||
if (pathToShorten.Length <= 10) return fullName;
|
||||
|
||||
// 缩短路径
|
||||
var buffer = new StringBuilder(260);
|
||||
if (GetShortPathNameW(pathToShorten, buffer, buffer.Capacity) == 0) return fullName;
|
||||
return Path.Combine(buffer.ToString(), pathToKeep);
|
||||
char[] buffer = new char[260];
|
||||
int result = GetShortPathNameW(pathToShorten, buffer, buffer.Length);
|
||||
if (result == 0) return fullName;
|
||||
string shortPath = new(buffer, 0, result);
|
||||
return Path.Combine(shortPath, pathToKeep);
|
||||
}
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
|
||||
private static extern int GetShortPathNameW(string lpszLongPath, StringBuilder lpszShortPath, int cchBuffer);
|
||||
private static extern int GetShortPathNameW(string lpszLongPath, [Out] char[] buffer, int cchBuffer);
|
||||
|
||||
#endregion
|
||||
|
||||
File renamed without changes.
@@ -1,6 +1,6 @@
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace MeloongCore.Extensions;
|
||||
namespace MeloongCore.Wpf.Extensions;
|
||||
public static class WpfExtensions {
|
||||
|
||||
public static bool Any(this UIElementCollection? Arr) => Arr?.Count > 0;
|
||||
@@ -0,0 +1,65 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net462</TargetFramework>
|
||||
<OutputType>Library</OutputType>
|
||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||
<OutDir>bin\</OutDir>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
|
||||
<Configurations>Debug;Release;Snapshot</Configurations>
|
||||
<Deterministic>true</Deterministic>
|
||||
<LangVersion>13.0</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<AnalysisLevel>latest-recommended</AnalysisLevel>
|
||||
<AssemblyName>MeloongCore.Wpf</AssemblyName>
|
||||
<RootNamespace>MeloongCore.Wpf</RootNamespace>
|
||||
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Nullable" Version="1.3.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="System.ValueTuple" Version="4.6.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Shared\MeloongCore.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="PresentationFramework" />
|
||||
<Reference Include="System.ServiceModel" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="System" />
|
||||
<Using Include="System.ComponentModel" />
|
||||
<Using Include="System.Collections" />
|
||||
<Using Include="System.Collections.Generic" />
|
||||
<Using Include="System.Diagnostics.CodeAnalysis" />
|
||||
<Using Include="System.Linq" />
|
||||
<Using Include="System.Text" />
|
||||
<Using Include="System.IO" />
|
||||
<Using Include="System.Net" />
|
||||
<Using Include="System.Threading" />
|
||||
<Using Include="System.Collections.Concurrent" />
|
||||
<Using Include="System.Runtime.CompilerServices" />
|
||||
<Using Include="System.Runtime.InteropServices" />
|
||||
<Using Include="MeloongCore" />
|
||||
<Using Include="MeloongCore.Extensions" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<DefineConstants>$(DefineConstants);SNAPSHOT</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'" />
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Snapshot|AnyCPU'">
|
||||
<Optimize>True</Optimize>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
Reference in new issue
Block a user