我有两个需要映射的数组。在代码中
var result = "[placeholder2] Hello my name is [placeholder1]";
var placeholder = { "[placeholder1]", "[placeholder2]", "[placeholder3]", "[placeholder4]" };
var placeholderValue = { "placeholderValue3", "placeholderValue2", "placeholderValue3" };
Array.ForEach(placeholder , i => result = result.Replace(i, placeholderValue));
给定i
,placeholderValue
需要以智能方式设置。我可以实现一个 switch 语句。对于 30 个左右的元素,圈复杂度将是不可接受的。什么是好的模式、扩展方法或其他方式来实现我的目标?