/// <summary> /// 在一个关键字上按照输入的“附加函数”附加一个值:如果该关键字本不存在或者“附加函数”为空,直接将该值放到关键字上;如果关键字存在且存在“附加函数”,则按照该附加函数修改关键字位置的值 /// </summary> /// <param name="key">关键字</param> /// <param name="value">输入值</param> /// <param name="appendFunc">“附加函数”,第一个参数为关键字所在位置的值,第二个参数为输入值</param> /// <returns>返回Attributes本身</returns> public Map <TKey, TValue> AppendValue(TKey key, TValue value, _AppendFunc appendFunc = null) { if (!ContainsKey(key) || appendFunc == null) { this[key] = value; } else { this[key] = appendFunc(this[key], value); } if (OnChange != null) { OnChange(key); } return(this); }
/// <summary> /// 在一个关键字上按照输入的“附加函数”附加一个值,按照该附加函数修改关键字位置的值 /// </summary> public Map <TKey, TValue> AppendValue <TAppend>(TKey key, TAppend appendValue, TValue init, _AppendFunc <TAppend> appendFunc) { if (!ContainsKey(key) || appendFunc == null) { this[key] = init; } else { this[key] = appendFunc(this[key], appendValue); } if (OnChange != null) { OnChange(key); } return(this); }