Skip to content

Commit

Permalink
😊 完成 新流变对象 100% 覆盖旧版本粘土对象模块功能
Browse files Browse the repository at this point in the history
  • Loading branch information
MonkSoul committed Jan 17, 2025
1 parent 2d632f4 commit 0e8756c
Show file tree
Hide file tree
Showing 15 changed files with 85 additions and 191 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="sqlSugarCore" Version="5.1.4.172" />
<PackageReference Include="sqlSugarCore" Version="5.1.4.175" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,7 @@ public partial class Clay
/// <summary>
/// 获取标识符集合
/// </summary>
public IEnumerable<object> Indexes => AsEnumerable().Select(u => u.Key);

/// <summary>
/// 获取标识符集合
/// </summary>
public IEnumerable<object> Keys => Indexes;
public IEnumerable<object> Keys => AsEnumerable().Select(u => u.Key);

/// <summary>
/// 获取值集合
Expand Down Expand Up @@ -95,7 +90,7 @@ public partial class Clay
// 获取循环访问 JsonObject 的枚举数
using var enumerator = JsonCanvas.AsObject().GetEnumerator();

// 遍历 JsonObject 每个键值对
// 遍历 JsonObject 键值对
while (enumerator.MoveNext())
{
// 获取当前的键值对
Expand All @@ -122,7 +117,7 @@ public partial class Clay
// 定义索引变量用于记录数组中元素的位置
var index = 0;

// 遍历 JsonArray 每个元素
// 遍历 JsonArray
while (enumerator.MoveNext())
{
// 获取当前的元素
Expand All @@ -131,4 +126,29 @@ public partial class Clay
yield return new KeyValuePair<int, dynamic?>(index++, DeserializeNode(current, Options));
}
}

/// <summary>
/// 遍历 <see cref="Clay" />
/// </summary>
public void ForEach(Action<dynamic> action)
{
// 空检查
ArgumentNullException.ThrowIfNull(action);

ForEach((_, item) => action(item));
}

/// <summary>
/// 遍历 <see cref="Clay" />
/// </summary>
public void ForEach(Action<object, dynamic> action)
{
ArgumentNullException.ThrowIfNull(action);

// 逐条遍历
foreach (var (identifier, item) in AsEnumerable())
{
action(identifier, item);
}
}
}
71 changes: 7 additions & 64 deletions framework/Furion.Pure/V5_Experience/Shapeless/Clay/Clay.Exports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,45 +74,13 @@ public Clay(ClayType clayType, ClayOptions? options = null)
}

/// <summary>
/// 字符串索引
/// 索引
/// </summary>
/// <param name="key">键</param>
public object? this[string key]
{
get => GetValue(key);
set => SetValue(key, value);
}

/// <summary>
/// 字符索引
/// </summary>
/// <param name="key">键</param>
public object? this[char key]
{
get => GetValue(key);
set => SetValue(key, value);
}

/// <summary>
/// 整数索引
/// </summary>
/// <param name="index">索引</param>
public object? this[int index]
{
get => GetValue(index);
set => SetValue(index, value);
}

/// <summary>
/// <see cref="Index" /> 索引
/// </summary>
/// <param name="index">
/// <see cref="Index" />
/// </param>
public object? this[Index index]
/// <param name="identifier">标识符,可以是键(字符串)或索引(整数)或索引运算符(Index)或范围运算符(Range)</param>
public object? this[object identifier]
{
get => GetValue(index);
set => SetValue(index, value);
get => GetValue(identifier);
set => SetValue(identifier, value);
}

/// <summary>
Expand All @@ -121,7 +89,7 @@ public object? this[Index index]
/// <param name="range">
/// <see cref="Range" />
/// </param>
public Clay? this[Range range] => GetValue(range) as Clay;
public Clay? this[Range range] => this[range as object] as Clay;

/// <summary>
/// 是否是单一对象
Expand Down Expand Up @@ -606,31 +574,6 @@ public Clay Reverse(ClayOptions? options = null) =>
return Slice(new Range(start, end));
}

/// <summary>
/// 遍历 <see cref="Clay" />
/// </summary>
public void ForEach(Action<dynamic> action)
{
// 空检查
ArgumentNullException.ThrowIfNull(action);

ForEach((_, item) => action(item));
}

/// <summary>
/// 遍历 <see cref="Clay" />
/// </summary>
public void ForEach(Action<object, dynamic> action)
{
ArgumentNullException.ThrowIfNull(action);

// 逐条遍历
foreach (var (index, item) in AsEnumerable())
{
action(index, item);
}
}

/// <summary>
/// 组合多个 <see cref="Clay" /> 并返回新 <see cref="Clay" />
/// </summary>
Expand Down Expand Up @@ -669,7 +612,7 @@ public Clay Combine(params Clay[] clays)
// 深度克隆当前 Clay 实例
var combineClay = DeepClone();

// 遍历所有 Clay 并设置新值或替换旧值
// 遍历所有 Clay 并设置值
foreach (var clay in clays)
{
clay.ForEach((key, value) => combineClay[$"{key}"] = value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,25 +114,9 @@ public override bool TryInvoke(InvokeBinder binder, object?[]? args, out object?
case JsonSerializerOptions jsonSerializerOptions:
result = ToJsonString(jsonSerializerOptions);
return true;
// 处理 clay(string) 情况
case string key:
result = GetValue(key);
return true;
// 处理 clay(char) 情况
case char key:
result = GetValue(key);
return true;
// 处理 clay(int) 情况
case int index:
result = GetValue(index);
return true;
// 处理 clay(Index) 情况
case Index index:
result = GetValue(index);
return true;
// 处理 clay(Range) 情况
case Range range:
result = GetValue(range);
// 处理 clay(identifier) 情况
case string or char or int or Index or Range:
result = GetValue(args[0]!);
return true;
default:
return base.TryInvoke(binder, args, out result);
Expand Down
36 changes: 28 additions & 8 deletions framework/Furion/V5_Experience/Shapeless/Clay/Clay.Enumerable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,7 @@ public partial class Clay
/// <summary>
/// 获取标识符集合
/// </summary>
public IEnumerable<object> Indexes => AsEnumerable().Select(u => u.Key);

/// <summary>
/// 获取标识符集合
/// </summary>
public IEnumerable<object> Keys => Indexes;
public IEnumerable<object> Keys => AsEnumerable().Select(u => u.Key);

/// <summary>
/// 获取值集合
Expand Down Expand Up @@ -95,7 +90,7 @@ public partial class Clay
// 获取循环访问 JsonObject 的枚举数
using var enumerator = JsonCanvas.AsObject().GetEnumerator();

// 遍历 JsonObject 每个键值对
// 遍历 JsonObject 键值对
while (enumerator.MoveNext())
{
// 获取当前的键值对
Expand All @@ -122,7 +117,7 @@ public partial class Clay
// 定义索引变量用于记录数组中元素的位置
var index = 0;

// 遍历 JsonArray 每个元素
// 遍历 JsonArray
while (enumerator.MoveNext())
{
// 获取当前的元素
Expand All @@ -131,4 +126,29 @@ public partial class Clay
yield return new KeyValuePair<int, dynamic?>(index++, DeserializeNode(current, Options));
}
}

/// <summary>
/// 遍历 <see cref="Clay" />
/// </summary>
public void ForEach(Action<dynamic> action)
{
// 空检查
ArgumentNullException.ThrowIfNull(action);

ForEach((_, item) => action(item));
}

/// <summary>
/// 遍历 <see cref="Clay" />
/// </summary>
public void ForEach(Action<object, dynamic> action)
{
ArgumentNullException.ThrowIfNull(action);

// 逐条遍历
foreach (var (identifier, item) in AsEnumerable())
{
action(identifier, item);
}
}
}
71 changes: 7 additions & 64 deletions framework/Furion/V5_Experience/Shapeless/Clay/Clay.Exports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,45 +74,13 @@ public Clay(ClayType clayType, ClayOptions? options = null)
}

/// <summary>
/// 字符串索引
/// 索引
/// </summary>
/// <param name="key">键</param>
public object? this[string key]
{
get => GetValue(key);
set => SetValue(key, value);
}

/// <summary>
/// 字符索引
/// </summary>
/// <param name="key">键</param>
public object? this[char key]
{
get => GetValue(key);
set => SetValue(key, value);
}

/// <summary>
/// 整数索引
/// </summary>
/// <param name="index">索引</param>
public object? this[int index]
{
get => GetValue(index);
set => SetValue(index, value);
}

/// <summary>
/// <see cref="Index" /> 索引
/// </summary>
/// <param name="index">
/// <see cref="Index" />
/// </param>
public object? this[Index index]
/// <param name="identifier">标识符,可以是键(字符串)或索引(整数)或索引运算符(Index)或范围运算符(Range)</param>
public object? this[object identifier]
{
get => GetValue(index);
set => SetValue(index, value);
get => GetValue(identifier);
set => SetValue(identifier, value);
}

/// <summary>
Expand All @@ -121,7 +89,7 @@ public object? this[Index index]
/// <param name="range">
/// <see cref="Range" />
/// </param>
public Clay? this[Range range] => GetValue(range) as Clay;
public Clay? this[Range range] => this[range as object] as Clay;

/// <summary>
/// 是否是单一对象
Expand Down Expand Up @@ -606,31 +574,6 @@ public Clay Reverse(ClayOptions? options = null) =>
return Slice(new Range(start, end));
}

/// <summary>
/// 遍历 <see cref="Clay" />
/// </summary>
public void ForEach(Action<dynamic> action)
{
// 空检查
ArgumentNullException.ThrowIfNull(action);

ForEach((_, item) => action(item));
}

/// <summary>
/// 遍历 <see cref="Clay" />
/// </summary>
public void ForEach(Action<object, dynamic> action)
{
ArgumentNullException.ThrowIfNull(action);

// 逐条遍历
foreach (var (index, item) in AsEnumerable())
{
action(index, item);
}
}

/// <summary>
/// 组合多个 <see cref="Clay" /> 并返回新 <see cref="Clay" />
/// </summary>
Expand Down Expand Up @@ -669,7 +612,7 @@ public Clay Combine(params Clay[] clays)
// 深度克隆当前 Clay 实例
var combineClay = DeepClone();

// 遍历所有 Clay 并设置新值或替换旧值
// 遍历所有 Clay 并设置值
foreach (var clay in clays)
{
clay.ForEach((key, value) => combineClay[$"{key}"] = value);
Expand Down
22 changes: 3 additions & 19 deletions framework/Furion/V5_Experience/Shapeless/Clay/Clay.Override.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,25 +114,9 @@ public override bool TryInvoke(InvokeBinder binder, object?[]? args, out object?
case JsonSerializerOptions jsonSerializerOptions:
result = ToJsonString(jsonSerializerOptions);
return true;
// 处理 clay(string) 情况
case string key:
result = GetValue(key);
return true;
// 处理 clay(char) 情况
case char key:
result = GetValue(key);
return true;
// 处理 clay(int) 情况
case int index:
result = GetValue(index);
return true;
// 处理 clay(Index) 情况
case Index index:
result = GetValue(index);
return true;
// 处理 clay(Range) 情况
case Range range:
result = GetValue(range);
// 处理 clay(identifier) 情况
case string or char or int or Index or Range:
result = GetValue(args[0]!);
return true;
default:
return base.TryInvoke(binder, args, out result);
Expand Down
Loading

0 comments on commit 0e8756c

Please sign in to comment.