/// <summary> /// Gets the value of the field referenced by "String" with all field filter applied. /// </summary> /// <param name="fieldName"></param> /// <exception cref="ArgumentException">Thrown when the fieldName field is null or empty.</exception> /// <returns></returns> public string GetField(string fieldName) { if (string.IsNullOrEmpty(fieldName)) { throw new ArgumentException("The field name may not be null or empty."); } string rtnValue = string.Empty; FieldFilterDelegate del = FieldFilterDelegates[fieldName.ToLower()]; if (del != null) { //Initialize the field data to empty field data FieldFilterData data = new FieldFilterData(); //Call delegate, all delegates will modify the FieldData string of the //FieldFilterData object we are passing in. del(fieldName, data); //set the return value to the processed value of the FieldFilterData rtnValue = data.Value; } return(rtnValue); }
public void AddFieldFilter(string fieldName, FieldFilterDelegate filter) { if (FieldFilterDelegates.ContainsKey(fieldName.ToLower()) == false) { FieldFilterDelegates.Add(fieldName.ToLower(), filter); } else { FieldFilterDelegate existingFieldFilterLinkDelegate = FieldFilterDelegates[fieldName.ToLower()]; existingFieldFilterLinkDelegate += filter; } }
/// <summary> /// Adds a field filter which modifies the value of the field referenced by "string" when /// GetField is called. /// </summary> /// <param name="fieldName"></param> /// <param name="filter"></param> /// Changed from public to private PageAssembly Instruction protected void AddFieldFilter(string fieldName, FieldFilterDelegate filter) { if (string.IsNullOrEmpty(fieldName)) { // Throws exception if fieldName is null/empty throw new ArgumentException("The fieldName parameter may not be null or empty."); } string fieldNameKey = fieldName.ToLower(); // If the delegates do not contain the passed filter key, add a new delegate if (FieldFilterDelegates.ContainsKey(fieldNameKey) == false) { FieldFilterDelegates.Add(fieldNameKey, filter); } // Add filter to dictionary associated with fieldNameKey // Because Delegates are immutable, an intermediate value cannot be used else { FieldFilterDelegates[fieldNameKey] += filter; } }
/// <summary> /// Adds a field filter which modifies the value of the field referenced by "string" /// when GetField is called. /// </summary> /// <param name="fieldName"></param> /// <param name="filter"></param> public void AddFieldFilter(string fieldName, FieldFilterDelegate filter) { if (string.IsNullOrEmpty(fieldName)) { throw new ArgumentException("The fieldName parameter may not be null or empty."); } string fieldNameKey = fieldName.ToLower(); if (FieldFilterDelegates.ContainsKey(fieldNameKey) == false) { FieldFilterDelegates.Add(fieldNameKey, filter); } else { //Note, this must be called this way and cannot use an intermediate value, I.E. // FieldFilterDelegate foo = FieldFilterDelegates[fieldName.ToLower()]; // foo += filter; //will not work. The reason is, Delegates are Immutable!! FieldFilterDelegates[fieldNameKey] += filter; } }
/// <summary> /// Gets the value of the field referenced by "String" with all field filters applied /// </summary> /// <param name="fieldName"></param> /// <exception cref="ArgumentException">Thrown when the fieldName field is null or empty.</exception> /// <returns></returns> public string GetField(string fieldName) { if (string.IsNullOrEmpty(fieldName)) { // Throws exception if fieldName is null/empty throw new ArgumentException("The field name may not be null or empty."); } string rtnValue = string.Empty; // Initialize delegate FieldFilterDelegate del = FieldFilterDelegates[fieldName.ToLower()]; if (del != null) { // Initialize FieldFilterData to empty FieldFilterData data = new FieldFilterData(); // Call delegate, to modify Field Data string of FieldFilterData object being passed in del(fieldName, data); // Set return value to processed value of FieldFilterData rtnValue = data.Value; } return(rtnValue); }