/// <summary> /// Clears all Headers from message /// </summary> public void removeHeaders() { if (headers != null) { headers.Clear(); } }
public void ClearPropertyTest() { PropertyCollection collection = new PropertyCollection(new string[0]); AttachEvents(collection); Property prop1 = new StringProperty("test", "orange"); Property prop2 = new StringProperty("two", "number"); collection.Add(prop1); collection.Add(prop2); int rmCount = 0; collection.PropertyRemoved += (s, e) => { rmCount++; }; _eventsFired = EventFlags.None; collection.Clear(); Assert.AreEqual(EventFlags.PropertyRemoved | EventFlags.Modified, _eventsFired); Assert.AreEqual(2, rmCount); Assert.AreEqual(0, collection.Count); }
/// <summary> /// 将指定文件中的 XML 架构和数据读入 System.Data.DataTable 中。 /// </summary> /// <param name="fileName">从中读取数据的文件的名称。</param> /// <returns>用于读取数据的 System.Data.XmlReadMode。</returns> public virtual void ReadXml(string fileName) { this.FileName = Path.GetFullPath(fileName); properties.Clear(); items.Clear(); others.Clear(); string basePath = Path.GetDirectoryName(this.FileName); XmlDocument xmldoc = new XmlDocument(); XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmldoc.NameTable); nsmgr.AddNamespace("k", Consts.NamesapceURI); xmldoc.Load(fileName); //Project节点 XmlElement nodeProject = xmldoc.DocumentElement; foreach (XmlNode node in nodeProject.ChildNodes) { try { switch (node.Name) { case "PropertyGroup": properties.AddGroup((XmlElement)node, basePath); break; case "ItemGroup": items.AddGroup((XmlElement)node, basePath); break; default: others.Add(node.CloneNode(true)); break; } } catch (Exception ex) { // } } }
/// <summary> /// Combines two PropertyCollections according <c>policy</c> specified /// </summary> /// <param name="existing">Collection that will be changed</param> /// <param name="data">New data to append</param> /// <param name="policy">How to manage key duplicates</param> /// \ingroup_disabled ace_ext_collections_highlight public static void AppendData(this PropertyCollection existing, PropertyCollection data, existingDataMode policy, Boolean showException = true) { PropertyCollection temp = new PropertyCollection(); if ((data == null) && showException) { throw new ArgumentNullException("data", "AppendData failed because data is null"); return; } if (data == null) { return; } switch (policy) { case existingDataMode.clearExisting: existing.Clear(); existing.AddRange(data); break; case existingDataMode.filterAndLeaveExisting: foreach (DictionaryEntry input in data) { if (existing.ContainsKey(input.Key)) { temp.Add(input.Key, existing[input.Key]); } } existing.Clear(); existing.AddRange(temp); break; case existingDataMode.filterNewOverwriteExisting: foreach (DictionaryEntry input in data) { if (existing.ContainsKey(input.Key)) { existing[input.Key] = input.Value; } } break; case existingDataMode.leaveExisting: existing.AddRange(data, true); break; case existingDataMode.overwriteExistingIfEmptyOrNull: foreach (DictionaryEntry input in data) { if (existing.ContainsKey(input.Key)) { if (imbSciStringExtensions.isNullOrEmptyString(existing[input.Key].toStringSafe(""))) { existing[input.Key] = input.Value; } } else { existing.Add(input.Key, input.Value); } } break; case existingDataMode.overwriteExisting: foreach (DictionaryEntry input in data) { if (existing.ContainsKey(input.Key)) { existing[input.Key] = input.Value; } else { existing.Add(input.Key, input.Value); } } break; case existingDataMode.sumWithExisting: foreach (DictionaryEntry input in data) { if (existing.ContainsKey(input.Key)) { Object result = existing[input.Key].sumValues(input.Value); } else { existing.Add(input.Key, input.Value); } } break; default: throw new NotImplementedException(imbStringFormats.toStringSafe(policy) + " called but not implemented"); break; } }
// -------------------------- ADD and APPEND #pragma warning disable CS1574 // XML comment has cref attribute 'existingDataMode' that could not be resolved /// <summary> /// Appends the specified key and value accordint the specified <see cref="aceCommonTypes.enums.existingDataMode"/>. Returns TRUE if <c>newValueCandidate</c> was written as result of the <c>policy</c> specified. /// </summary> /// <param name="data">The data.</param> /// <param name="key">The key.</param> /// <param name="newValueCandidate">The new value candidate - it will be or not written under specified <c>key</c> depending on <c>policy</c> and current <c>data</c> </param> /// <param name="policy">The policy on handling existing entry for the <c>key</c> specified</param> /// <returns>FALSE if <c>newValueCandidate</c> was not written into <c>data</c> collection</returns> public static Boolean Append(this PropertyCollection data, Object key, Object newValueCandidate, existingDataMode policy) #pragma warning restore CS1574 // XML comment has cref attribute 'existingDataMode' that could not be resolved { if (newValueCandidate == null) { return(false); } switch (policy) { case existingDataMode.clearExisting: data.Clear(); data.Add(key, data); break; case existingDataMode.filterAndLeaveExisting: if (data.ContainsKey(key)) { //data[key] = newValueCandidate; return(false); } else { if (key is Enum) { data.add((Enum)key, newValueCandidate, false); } else { data.Add(key.toStringSafe(), newValueCandidate); } } break; case existingDataMode.filterNewOverwriteExisting: if (data.ContainsKey(key)) { data[key] = newValueCandidate; } return(false); break; case existingDataMode.leaveExisting: return(false); break; case existingDataMode.overwriteExistingIfEmptyOrNull: if (data.ContainsKey(key)) { if (imbSciStringExtensions.isNullOrEmptyString(data[key])) { data[key] = newValueCandidate; } else { return(false); } } else { data.Add(key, newValueCandidate); } break; case existingDataMode.overwriteExisting: if (data.ContainsKey(key)) { data[key] = newValueCandidate; } else { data.Add(key, newValueCandidate); } break; case existingDataMode.sumWithExisting: if (data.ContainsKey(key)) { Object result = data[key].sumValues(newValueCandidate); } else { data.Add(key, newValueCandidate); } break; } return(true); }