//****************************************************************** #region [Remove() Method] //****************************************************************** /// <summary> /// Searches the collection for a feature with the given name and /// removes the matching SyntaxFeature if found. /// </summary> public void Remove(string sName) { Debug.Assert(sName != null); SyntaxFeature oFeature = Find(sName); if (oFeature != null) { InnerList.Remove(oFeature); } Debug.Assert(!Contains(sName)); }
//****************************************************************** /// <summary> /// Gets or sets the value for the feature with the specified name. /// Setting a feature adds or replaces a SyntaxFeature in the /// collection, using the specified name and value. Getting a /// feature searches the collection and returns either the value /// of the SyntaxFeature with the specified name or an empty string /// ("") if the name was not found. /// </summary> public string this[string sName] { set { string sValue = value; //********************************************************** // Validate the feature name and value. if (sName == null) { string sMessage = "Invalid argument: " + "SyntaxFeature.Name cannot be null."; throw new Exception(sMessage); } if (sValue == null) { string sMessage = "Invalid argument: " + "SyntaxFeature.Value cannot be null."; throw new Exception(sMessage); } //********************************************************** // Check if a SyntaxFeature with the specified name already // exists in the collection. // // If so, remove it from the collection. Then create a new // SyntaxFeature and insert it into the collection at the // same index where the existing SyntaxFeature was found. // // Otherwise, create a new SyntaxFeature and add it to the // end of the collection. SyntaxFeature oExistingFeature = Find(sName); if (oExistingFeature != null) { //****************************************************** // Remove the existing SyntaxFeature and replace it with // a new SyntaxFeature at the same index. int iIndex = InnerList.IndexOf(oExistingFeature); InnerList.Remove(oExistingFeature); Debug.Assert(! Contains(sName)); SyntaxFeature oNewFeature = new SyntaxFeature(sName,sValue); InnerList.Insert(iIndex,oNewFeature); } else { //****************************************************** // Add a new SyntaxFeature to the end of the collection. SyntaxFeature oNewFeature = new SyntaxFeature(sName,sValue); InnerList.Add(oNewFeature); } } get { Debug.Assert(sName != null); SyntaxFeature oFeature = Find(sName); if (oFeature != null) { return oFeature.Value; } return ""; } }
//****************************************************************** #region [Indexer Method] //****************************************************************** /// <summary> /// Gets or sets the value for the feature with the specified name. /// Setting a feature adds or replaces a SyntaxFeature in the /// collection, using the specified name and value. Getting a /// feature searches the collection and returns either the value /// of the SyntaxFeature with the specified name or an empty string /// ("") if the name was not found. /// </summary> public string this[string sName] { set { string sValue = value; //********************************************************** // Validate the feature name and value. if (sName == null) { string sMessage = "Invalid argument: " + "SyntaxFeature.Name cannot be null."; throw new Exception(sMessage); } if (sValue == null) { string sMessage = "Invalid argument: " + "SyntaxFeature.Value cannot be null."; throw new Exception(sMessage); } //********************************************************** // Check if a SyntaxFeature with the specified name already // exists in the collection. // // If so, remove it from the collection. Then create a new // SyntaxFeature and insert it into the collection at the // same index where the existing SyntaxFeature was found. // // Otherwise, create a new SyntaxFeature and add it to the // end of the collection. SyntaxFeature oExistingFeature = Find(sName); if (oExistingFeature != null) { //****************************************************** // Remove the existing SyntaxFeature and replace it with // a new SyntaxFeature at the same index. int iIndex = InnerList.IndexOf(oExistingFeature); InnerList.Remove(oExistingFeature); Debug.Assert(!Contains(sName)); SyntaxFeature oNewFeature = new SyntaxFeature(sName, sValue); InnerList.Insert(iIndex, oNewFeature); } else { //****************************************************** // Add a new SyntaxFeature to the end of the collection. SyntaxFeature oNewFeature = new SyntaxFeature(sName, sValue); InnerList.Add(oNewFeature); } } get { Debug.Assert(sName != null); SyntaxFeature oFeature = Find(sName); if (oFeature != null) { return(oFeature.Value); } return(""); } }