public void Add(MessageFilter filter, TFilterData data, int priority) { if (filter == null) { throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("filter"); } if (this.filters.ContainsKey(filter)) { throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("filter", System.ServiceModel.SR.GetString("FilterExists")); } System.Type key = filter.GetType(); System.Type type2 = null; IMessageFilterTable <TFilterData> table = null; if (!this.filterTypeMappings.TryGetValue(key, out type2)) { table = this.CreateFilterTable(filter); this.ValidateTable(table); this.filterTypeMappings.Add(key, table.GetType()); FilterTableEntry <TFilterData> item = new FilterTableEntry <TFilterData>(priority, table); int index = this.tables.IndexOf(item); if (index >= 0) { table = this.tables[index].table; } else { this.tables.Add(item); } table.Add(filter, data); } else { for (int i = 0; i < this.tables.Count; i++) { if ((this.tables[i].priority == priority) && this.tables[i].table.GetType().Equals(type2)) { table = this.tables[i].table; break; } } if (table == null) { table = this.CreateFilterTable(filter); this.ValidateTable(table); if (!table.GetType().Equals(type2)) { throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("FilterTableTypeMismatch"))); } table.Add(filter, data); this.tables.Add(new FilterTableEntry <TFilterData>(priority, table)); } else { table.Add(filter, data); } } this.filters.Add(filter, data); }
public void Add(MessageFilter filter, TFilterData data, int priority) { if (filter == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("filter"); } if (this.filters.ContainsKey(filter)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("filter", SR.GetString(SR.FilterExists)); } #pragma warning suppress 56506 // [....], PreSharp generates a false warning here Type filterType = filter.GetType(); Type tableType = null; IMessageFilterTable <TFilterData> table = null; if (this.filterTypeMappings.TryGetValue(filterType, out tableType)) { for (int i = 0; i < this.tables.Count; ++i) { if (this.tables[i].priority == priority && this.tables[i].table.GetType().Equals(tableType)) { table = this.tables[i].table; break; } } if (table == null) { table = CreateFilterTable(filter); ValidateTable(table); if (!table.GetType().Equals(tableType)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.FilterTableTypeMismatch))); } table.Add(filter, data); this.tables.Add(new FilterTableEntry(priority, table)); } else { table.Add(filter, data); } } else { table = CreateFilterTable(filter); ValidateTable(table); this.filterTypeMappings.Add(filterType, table.GetType()); FilterTableEntry entry = new FilterTableEntry(priority, table); int idx = this.tables.IndexOf(entry); if (idx >= 0) { table = this.tables[idx].table; } else { this.tables.Add(entry); } table.Add(filter, data); } this.filters.Add(filter, data); }
public void Add(MessageFilter filter, TFilterData data, int priority) { if (filter == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(filter)); } if (_filters.ContainsKey(filter)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(nameof(filter), SR.FilterExists); } Type filterType = filter.GetType(); IMessageFilterTable <TFilterData> table = null; if (_filterTypeMappings.TryGetValue(filterType, out Type tableType)) { for (int i = 0; i < _tables.Count; ++i) { if (_tables[i].priority == priority && _tables[i].table.GetType().Equals(tableType)) { table = _tables[i].table; break; } } if (table == null) { table = CreateFilterTable(filter); ValidateTable(table); if (!table.GetType().Equals(tableType)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.FilterTableTypeMismatch)); } table.Add(filter, data); _tables.Add(new FilterTableEntry(priority, table)); } else { table.Add(filter, data); } } else { table = CreateFilterTable(filter); ValidateTable(table); _filterTypeMappings.Add(filterType, table.GetType()); FilterTableEntry entry = new FilterTableEntry(priority, table); int idx = _tables.IndexOf(entry); if (idx >= 0) { table = _tables[idx].table; } else { _tables.Add(entry); } table.Add(filter, data); } _filters.Add(filter, data); }