diff --git a/CollectionOperationKit/ClientSideArrayOp.cs b/CollectionOperationKit/ClientSideArrayOp.cs index 89d40429b04a69d495f4edd6714ce2c523559c9d..83499d56fadcf25962fd66f615a14414c25a0119 100644 --- a/CollectionOperationKit/ClientSideArrayOp.cs +++ b/CollectionOperationKit/ClientSideArrayOp.cs @@ -191,6 +191,10 @@ namespace CollectionOperationKit { return setPropertyVisiblity(propertyName, true, true, false); } + case SupportedOperations.RenameProperty: + { + return setPropertyVisiblity(propertyName, true, true, true); + } default: { return base.GetDesignerPropertyVisible(propertyName, commandScope); @@ -240,7 +244,9 @@ namespace CollectionOperationKit [Description("Select:提取【输入参数】中每个元素里名为【操作参数A】的属性,将其作为一个新的数组返回")] Select, [Description("Distinct:以名为【操作参数A】的属性为基准(留空则直接比较数组元素),将【输入参数】去除空值和重复值后,作为新数组返回")] - Distinct + Distinct, + [Description("RenameProperty:将【输入参数】中每个对象的【操作参数A】属性重命名为【操作参数B】")] + RenameProperty } } } diff --git a/CollectionOperationKit/CollectionOperationKit.csproj b/CollectionOperationKit/CollectionOperationKit.csproj index 4ebef76cc231da22c8457163fc44f4882acfb4bf..101e60426956782fcd62a43b8e6e46860567b81e 100644 --- a/CollectionOperationKit/CollectionOperationKit.csproj +++ b/CollectionOperationKit/CollectionOperationKit.csproj @@ -1,69 +1,69 @@ - - - net472 - false - 8 - bin\ - true - - - - - - - - - - runtime - - - runtime - - - - - C:\Program Files\Forguncy 8\Website\bin\Forguncy.Commands.dll - False - - - C:\Program Files\Forguncy 8\Website\designerBin\Forguncy.Commands.Design.dll - False - - - C:\Program Files\Forguncy 8\Website\bin\GrapeCity.Forguncy.CellTypes.dll - False - - - C:\Program Files\Forguncy 8\Website\designerBin\GrapeCity.Forguncy.CellTypes.Design.dll - False - - - C:\Program Files\Forguncy 8\Website\bin\GrapeCity.Forguncy.Plugin.dll - False - - - C:\Program Files\Forguncy 8\Website\designerBin\GrapeCity.Forguncy.Plugin.Design.dll - False - - - C:\Program Files\Forguncy 8\Website\bin\GrapeCity.Forguncy.ServerApi.dll - False - - - C:\Program Files\Forguncy 8\Website\bin\Newtonsoft.Json.dll - False - - - False - - - - - - - - - - - + + + net472 + false + 8 + bin\ + true + + + + + + + + + + runtime + + + runtime + + + + + D:\Program Files\Forguncy 8.105\Website\bin\Forguncy.Commands.dll + False + + + D:\Program Files\Forguncy 8.105\Website\designerBin\Forguncy.Commands.Design.dll + False + + + D:\Program Files\Forguncy 8.105\Website\bin\GrapeCity.Forguncy.CellTypes.dll + False + + + D:\Program Files\Forguncy 8.105\Website\designerBin\GrapeCity.Forguncy.CellTypes.Design.dll + False + + + D:\Program Files\Forguncy 8.105\Website\bin\GrapeCity.Forguncy.Plugin.dll + False + + + D:\Program Files\Forguncy 8.105\Website\designerBin\GrapeCity.Forguncy.Plugin.Design.dll + False + + + D:\Program Files\Forguncy 8.105\Website\bin\GrapeCity.Forguncy.ServerApi.dll + False + + + D:\Program Files\Forguncy 8.105\Website\bin\Newtonsoft.Json.dll + False + + + False + + + + + + + + + + + diff --git a/CollectionOperationKit/PluginConfig.json b/CollectionOperationKit/PluginConfig.json index 1a02cd5de2a1bad8ecb06c651c066135596ba573..073c4dda2f8e74624e1c880fae1d3c7f1b4efcca 100644 --- a/CollectionOperationKit/PluginConfig.json +++ b/CollectionOperationKit/PluginConfig.json @@ -1,4 +1,4 @@ -{ +{ "assembly": [ "CollectionOperationKit.dll" ], @@ -11,7 +11,7 @@ "name": "对象与集合操作工具", "pluginType": "command", "guid": "CDD2FBD5-794F-4C7F-A483-030352D73C3C", - "version": "2.10.0.2", + "version": "2.10.0.3", "dependenceVersion": "8.0.0.0", "bundleJavaScript": true, "bundleCSS": true diff --git a/CollectionOperationKit/Resources/CollectionOperationKit.js b/CollectionOperationKit/Resources/CollectionOperationKit.js index 97733e200b21ec1b746bbac9f03a2ce1a13475d1..9d2df4c14500787d4516f1419d75e041e0a62c0c 100644 --- a/CollectionOperationKit/Resources/CollectionOperationKit.js +++ b/CollectionOperationKit/Resources/CollectionOperationKit.js @@ -440,6 +440,44 @@ var ClientSideArrayOp = (function (_super) { break; } + case SupportedOperations.RenameProperty: { + if (!Array.isArray(inP)) { + this.log("Paramater [" + params.InParamaterName + "] should be an Array."); + return; + } + + if (!paramA || paramA === "") { + this.log("Paramater [" + params.OperationParamaterAName + "] (original property name) should not be empty."); + return; + } + + if (!paramB || paramB === "") { + this.log("Paramater [" + params.OperationParamaterBName + "] (new property name) should not be empty."); + return; + } + + var result = []; + inP.forEach(function (obj) { + if (obj && typeof obj === 'object' && !Array.isArray(obj)) { + var newObj = {}; + for (var key in obj) { + if (obj.hasOwnProperty(key)) { + if (key === paramA) { + newObj[paramB] = obj[key]; + } else { + newObj[key] = obj[key]; + } + } + } + result.push(newObj); + } else { + result.push(obj); + } + }); + + COK.returnToParam(OutParamaterName, result); + break; + } } }; @@ -464,7 +502,8 @@ var ClientSideArrayOp = (function (_super) { Join: 16, Split: 17, Select: 18, - Distinct: 19 + Distinct: 19, + RenameProperty: 20 } diff --git a/CollectionOperationKit/ServerSideArrayOp.cs b/CollectionOperationKit/ServerSideArrayOp.cs index f1c0dd5468e21ab6eb505076f353e2b9f51fecff..8a6434c5ba042d05b01cf4855f3bc41aac6e6f92 100644 --- a/CollectionOperationKit/ServerSideArrayOp.cs +++ b/CollectionOperationKit/ServerSideArrayOp.cs @@ -289,6 +289,58 @@ namespace CollectionOperationKit returnToParam(dataContext, string.Join(seprator, values)); break; } + case SupportedOperations.RenameProperty: + { + // 获取输入数组 + ArrayList data = getArrayListParam(dataContext, this.InParamater); + // 获取要替换的原字段名 + string oldPropertyName = getParamValue(dataContext, this.OperationParamaterAName).ToString(); + // 获取新的字段名 + string newPropertyName = getParamValue(dataContext, this.OperationParamaterBName).ToString(); + + // 创建新的数组来存储修改后的对象 + ArrayList result = new ArrayList(); + + // 遍历数组中的每个对象 + for (int i = 0; i < data.Count; i++) + { + var item = data[i]; + + // 如果是Dictionary类型的对象 + if (item is Dictionary dictItem) + { + // 创建新的Dictionary + var newDict = new Dictionary(); + + // 复制所有属性,如果遇到要替换的字段名则使用新字段名 + foreach (var kvp in dictItem) + { + if (kvp.Key == oldPropertyName) + { + // 使用新字段名 + newDict[newPropertyName] = kvp.Value; + } + else + { + // 保持原字段名 + newDict[kvp.Key] = kvp.Value; + } + } + + result.Add(newDict); + } + else + { + // 对于其他类型的对象,直接添加到结果中(不做修改) + // 因为非Dictionary类型的对象属性名无法动态修改 + result.Add(item); + } + } + + // 返回修改后的数组到OutParamaterName2 + returnToParam2(dataContext, result); + break; + } default: { break; @@ -421,6 +473,10 @@ namespace CollectionOperationKit { return setPropertyVisiblity(propertyName, true, true, false); } + case SupportedOperations.RenameProperty: + { + return setPropertyVisiblity(propertyName, true, true, true); + } default: { return base.GetDesignerPropertyVisible(propertyName, commandScope); @@ -495,7 +551,9 @@ namespace CollectionOperationKit [Description("Select:提取【输入参数】中每个元素里名为【操作参数A】的属性,将其作为一个新的数组返回")] Select, [Description("Distinct:以名为【操作参数A】的属性为基准(留空则直接比较数组元素),将【输入参数】去除空值和重复值后,作为新数组返回")] - Distinct + Distinct, + [Description("RenameProperty:将【输入参数】中所有对象的【操作参数A】字段名修改为【操作参数B】字段名,返回修改后的新数组")] + RenameProperty } public class ObjectComparer : IEqualityComparer