IMessageFilterTable<TFilterData> IMessageFilterTable<TFilterData> IMessageFilterTable<TFilterData> IMessageFilterTable<TFilterData> Interface

定义

定义协定的 interface,筛选器表必须实现它,从而使用从一个或多个筛选器派生的查询条件来检查消息。An interface that defines the contract that a filter table must implement to inspect messages with query criteria derived from one or more filters.

generic <typename TFilterData>
public interface class IMessageFilterTable : System::Collections::Generic::ICollection<System::Collections::Generic::KeyValuePair<System::ServiceModel::Dispatcher::MessageFilter ^, TFilterData>>, System::Collections::Generic::IDictionary<System::ServiceModel::Dispatcher::MessageFilter ^, TFilterData>, System::Collections::Generic::IEnumerable<System::Collections::Generic::KeyValuePair<System::ServiceModel::Dispatcher::MessageFilter ^, TFilterData>>
public interface IMessageFilterTable<TFilterData> : System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<System.ServiceModel.Dispatcher.MessageFilter,TFilterData>>, System.Collections.Generic.IDictionary<System.ServiceModel.Dispatcher.MessageFilter,TFilterData>, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.ServiceModel.Dispatcher.MessageFilter,TFilterData>>
type IMessageFilterTable<'FilterData> = interface
    interface IDictionary<MessageFilter, 'FilterData>
    interface ICollection<KeyValuePair<MessageFilter, 'FilterData>>
    interface seq<KeyValuePair<MessageFilter, 'FilterData>>
    interface IEnumerable
Public Interface IMessageFilterTable(Of TFilterData)
Implements ICollection(Of KeyValuePair(Of MessageFilter, TFilterData)), IDictionary(Of MessageFilter, TFilterData), IEnumerable(Of KeyValuePair(Of MessageFilter, TFilterData))

类型参数

TFilterData

与表中每个筛选器关联的数据的类型。The type of data associated with each filter in the table.

派生
实现

注解

筛选器表是筛选器引擎的核心组件。The filter table is a core component of the filter engine. 筛选器引擎在 Windows Communication Foundation (WCF)中的主要用途是通过查找与消息匹配的所有筛选器,将应用程序逻辑与消息相匹配。The primary use of the filter engine in Windows Communication Foundation (WCF) is to match application logic to messages by finding all the filters that match a message.

使用筛选器表可以将多个筛选器与单个消息相匹配,这比将它们分别进行匹配效率更高。A filter table allows multiple filters to be matched against a single message more efficiently than they can be matched separately. 筛选器表将筛选器数据与筛选器相关联。A filter table associates filter data with filters. 该表是键值对,其中键是 MessageFilter,值是关联的筛选器数据。The table is a collection of key-value pairs, where the key is the MessageFilter, and the value is the associated filter data. 筛选器数据可以是类型为通用参数中指定的类型的任何数据,并且可用于指定当消息与表中的筛选器相匹配时应采取的操作。Filter data can be any data of the type specified in the generic parameter and can be used to specify what actions to take if a message is matched by a filter in the table.

可以使用 IDictionary<TKey,TValue> 继承的 IMessageFilterTable<TFilterData> 功能来访问筛选器表条目。Filter table entries can be accessed using the IDictionary<TKey,TValue> functionality that IMessageFilterTable<TFilterData> inherits.

注意,筛选器实例只能添加到给定的 IMessageFilterTable<TFilterData> 一次。Note that a filter instance can only be added to a given IMessageFilterTable<TFilterData> once. 若要将此筛选器的多个实例添加到同一个筛选器表,请使用筛选器构造函数来创建其他实例。To add multiple instances of this filter to the same filter table, use a filter constructor to create additional instances.

当消息满足筛选器的查询条件时,筛选器与消息相匹配。A filter matches a message when the message satisfies the query criteria of the filter. 有四种重载匹配方法。There are four overloaded matching methods. 返回的数据是筛选器数据或 MessageFilter 对象自身。The data returned is either the filter data or the MessageFilter objects themselves. 无论是允许多个匹配还是仅一个匹配,都返回此数据。This data is returned whether multiple matches are allowed or only a single match. 下表显示每个重载的此信息。The following table shows this information for each overload.

方法名Method Name 匹配Matches 返回的数据Data Returned
GetMatchingValue SingleSingle FilterData
GetMatchingFilter SingleSingle MessageFilter
GetMatchingValues 多页Multiple FilterData
GetMatchingFilters 多页Multiple MessageFilter 对象MessageFilter objects

每个方法包含两个重载。Each method contains two overloads. 两个重载的区别是,一个重载使用 Message 参数,但不允许其检查正文的内容;另一个重载使用 MessageBuffer 参数,可以检查消息的任何部分。The difference between the two overloads is that one takes a Message parameter and is not permitted to examine the contents of the body; the other takes a MessageBuffer parameter and can examine any part of the message. 如果使用消息参数来调用方法,并且筛选器表包含检查消息正文内容的筛选器,则将引发异常。If you call a method with the message parameter, and the filter table contains a filter that examines the content of the message body, an exception is thrown. 如果您对表中的筛选器不确定,请调用使用消息缓冲区的重载。If you are unsure about the filters in a table, call the overload that takes a message buffer.

消息头自动缓冲,并且无需使用即可由筛选器检查。Message headers are automatically buffered and can be inspected by a filter without being consumed. 但是,如果由筛选器检查正文,则必须缓冲整个消息,因为查询将使用未缓冲消息正文并破坏其内容。But if the body is to be inspected by a filter, then the entire message must be buffered because an unbuffered message body is consumed by a query and its contents destroyed.

下面的类实现 IMessageFilterTable<TFilterData>The following classes implement IMessageFilterTable<TFilterData>:

方法

Add(T) Add(T) Add(T) Add(T)

将某项添加到 ICollection<T> 中。Adds an item to the ICollection<T>.

(Inherited from ICollection<T>)
Add(TKey, TValue) Add(TKey, TValue) Add(TKey, TValue) Add(TKey, TValue)

IDictionary<TKey,TValue> 中添加一个带有所提供的键和值的元素。Adds an element with the provided key and value to the IDictionary<TKey,TValue>.

(Inherited from IDictionary<TKey,TValue>)
Clear() Clear() Clear() Clear()

ICollection<T> 中移除所有项。Removes all items from the ICollection<T>.

(Inherited from ICollection<T>)
Contains(T) Contains(T) Contains(T) Contains(T)

确定 ICollection<T> 是否包含特定值。Determines whether the ICollection<T> contains a specific value.

(Inherited from ICollection<T>)
ContainsKey(TKey) ContainsKey(TKey) ContainsKey(TKey) ContainsKey(TKey)

确定是否 IDictionary<TKey,TValue> 包含带有指定键的元素。Determines whether the IDictionary<TKey,TValue> contains an element with the specified key.

(Inherited from IDictionary<TKey,TValue>)
CopyTo(T[], Int32) CopyTo(T[], Int32) CopyTo(T[], Int32) CopyTo(T[], Int32)

从特定的 ICollection<T> 索引开始,将 Array 的元素复制到一个 Array 中。Copies the elements of the ICollection<T> to an Array, starting at a particular Array index.

(Inherited from ICollection<T>)
GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

返回循环访问集合的枚举数。Returns an enumerator that iterates through a collection.

(Inherited from IEnumerable)
GetMatchingFilter(Message, MessageFilter) GetMatchingFilter(Message, MessageFilter) GetMatchingFilter(Message, MessageFilter) GetMatchingFilter(Message, MessageFilter)

返回一个值,该值指示指定的消息是否正好满足表中的一个筛选器的匹配条件,然后在 out 参数中返回该筛选器。Returns a value that indicates whether the match criterion of exactly one filter in the table is satisfied by the specified message, and returns that filter in an out parameter.

GetMatchingFilter(MessageBuffer, MessageFilter) GetMatchingFilter(MessageBuffer, MessageFilter) GetMatchingFilter(MessageBuffer, MessageFilter) GetMatchingFilter(MessageBuffer, MessageFilter)

返回一个值,该值指示指定的消息或缓冲消息是否正好满足表中的一个筛选器的匹配条件,然后在 out 参数中返回该筛选器。Returns a value that indicates whether the match criterion of exactly one filter in the table is satisfied by the specified message or buffered message, and returns that filter in an out parameter.

GetMatchingFilters(Message, ICollection<MessageFilter>) GetMatchingFilters(Message, ICollection<MessageFilter>) GetMatchingFilters(Message, ICollection<MessageFilter>) GetMatchingFilters(Message, ICollection<MessageFilter>)

返回一个值,该值指示指定的消息是否满足表中筛选器的匹配条件,然后将匹配筛选器添加到集合。Returns a value that indicates whether the match criterion of a filter in the table is satisfied by the specified message, and adds the matching filters to a collection.

GetMatchingFilters(MessageBuffer, ICollection<MessageFilter>) GetMatchingFilters(MessageBuffer, ICollection<MessageFilter>) GetMatchingFilters(MessageBuffer, ICollection<MessageFilter>) GetMatchingFilters(MessageBuffer, ICollection<MessageFilter>)

返回一个值,该值指示指定的缓冲消息是否满足表中筛选器的匹配条件,然后将匹配筛选器添加到集合。Returns a value that indicates whether the match criterion of a filter in the table is satisfied by the specified buffered message, and adds the matching filters to a collection.

GetMatchingValue(Message, TFilterData) GetMatchingValue(Message, TFilterData) GetMatchingValue(Message, TFilterData) GetMatchingValue(Message, TFilterData)

返回一个值,该值指示指定的消息是否正好满足表中的一个筛选器的匹配条件,然后将匹配筛选数据添加到集合。Returns a value that indicates whether the match criterion of exactly one filter in the table is satisfied by the specified message, and adds the matching filter data to a collection.

GetMatchingValue(MessageBuffer, TFilterData) GetMatchingValue(MessageBuffer, TFilterData) GetMatchingValue(MessageBuffer, TFilterData) GetMatchingValue(MessageBuffer, TFilterData)

返回一个值,该值指示指定的缓冲消息是否正好满足表中的一个筛选器的匹配条件,然后将匹配筛选数据添加到集合。Returns a value that indicates whether the match criterion of exactly one filter in the table is satisfied by the specified buffered message, and adds the matching filter data to a collection.

GetMatchingValues(Message, ICollection<TFilterData>) GetMatchingValues(Message, ICollection<TFilterData>) GetMatchingValues(Message, ICollection<TFilterData>) GetMatchingValues(Message, ICollection<TFilterData>)

返回一个值,该值指示指定的消息是否满足表中至少一个筛选器的匹配条件,然后将匹配筛选器的 FilterData 添加到集合。Returns a value that indicates whether the match criterion of at least one filter in the table is satisfied by the specified message, and adds the FilterData of the matching filters to a collection.

GetMatchingValues(MessageBuffer, ICollection<TFilterData>) GetMatchingValues(MessageBuffer, ICollection<TFilterData>) GetMatchingValues(MessageBuffer, ICollection<TFilterData>) GetMatchingValues(MessageBuffer, ICollection<TFilterData>)

返回一个值,该值指示指定的缓冲消息是否满足表中至少一个筛选器的匹配条件,然后将匹配筛选器的 FilterData 添加到集合。Returns a value that indicates whether the match criterion of at least one filter in the table is satisfied by the specified buffered message, and adds the FilterData of the matching filters to a collection.

Remove(TKey) Remove(TKey) Remove(TKey) Remove(TKey)

IDictionary<TKey,TValue> 中移除包含指定键的元素。Removes the element with the specified key from the IDictionary<TKey,TValue>.

(Inherited from IDictionary<TKey,TValue>)
TryGetValue(TKey, TValue) TryGetValue(TKey, TValue) TryGetValue(TKey, TValue) TryGetValue(TKey, TValue)

获取与指定键关联的值。Gets the value associated with the specified key.

(Inherited from IDictionary<TKey,TValue>)

属性

Count Count Count Count

获取 ICollection<T> 中包含的元素数。Gets the number of elements contained in the ICollection<T>.

(Inherited from ICollection<T>)
IsReadOnly IsReadOnly IsReadOnly IsReadOnly

获取一个值,该值指示 ICollection<T> 是否为只读。Gets a value indicating whether the ICollection<T> is read-only.

(Inherited from ICollection<T>)
Item[TKey] Item[TKey] Item[TKey] Item[TKey]

获取或设置具有指定键的元素。Gets or sets the element with the specified key.

(Inherited from IDictionary<TKey,TValue>)
Keys Keys Keys Keys

获取包含 ICollection<T> 的键的 IDictionary<TKey,TValue>Gets an ICollection<T> containing the keys of the IDictionary<TKey,TValue>.

(Inherited from IDictionary<TKey,TValue>)
Values Values Values Values

获取一个 ICollection<T>,它包含 IDictionary<TKey,TValue> 中的值。Gets an ICollection<T> containing the values in the IDictionary<TKey,TValue>.

(Inherited from IDictionary<TKey,TValue>)

扩展方法

CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>)

在给定其泛型参数 TDataTable 的输入 DataRow 对象的情况下,返回包含 IEnumerable<T> 对象副本的 DataRowReturns a DataTable that contains copies of the DataRow objects, given an input IEnumerable<T> object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption)

在给定其泛型参数 TDataRow 的输入 DataTable 对象的情况下,将 IEnumerable<T> 对象复制到指定的 DataRowCopies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler)

在给定其泛型参数 TDataRow 的输入 DataTable 对象的情况下,将 IEnumerable<T> 对象复制到指定的 DataRowCopies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

启用查询的并行化。Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>)

返回元素集合,其中包含源集合中每个节点的上级。Returns a collection of elements that contains the ancestors of every node in the source collection.

Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName)

返回经过筛选的元素集合,其中包含源集合中每个节点的上级。Returns a filtered collection of elements that contains the ancestors of every node in the source collection. 集合中仅包括具有匹配 XName 的元素。Only elements that have a matching XName are included in the collection.

DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>)

返回源集合中每个文档和元素的子代节点的集合。Returns a collection of the descendant nodes of every document and element in the source collection.

Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>)

返回元素集合,其中包含源集合中每个元素和文档的子代元素。Returns a collection of elements that contains the descendant elements of every element and document in the source collection.

Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName)

返回经过筛选的元素集合,其中包含源集合中每个元素和文档的子代元素。Returns a filtered collection of elements that contains the descendant elements of every element and document in the source collection. 集合中仅包括具有匹配 XName 的元素。Only elements that have a matching XName are included in the collection.

Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>)

返回源集合中每个元素和文档的子元素的集合。Returns a collection of the child elements of every element and document in the source collection.

Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName)

返回源集合中经过筛选的每个元素和文档的子元素集合。Returns a filtered collection of the child elements of every element and document in the source collection. 集合中仅包括具有匹配 XName 的元素。Only elements that have a matching XName are included in the collection.

InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>)

返回节点集合(其中包含源集合中的所有节点),并按文档顺序排列。Returns a collection of nodes that contains all nodes in the source collection, sorted in document order.

Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>)

返回源集合中每个文档和元素的子节点集合。Returns a collection of the child nodes of every document and element in the source collection.

Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>)

将源集合中的每个节点从其父节点中移除。Removes every node in the source collection from its parent node.

适用于

线程安全性

对于匹配的操作,筛选器表是线程安全的;但对于修改,不是线程安全的。Filter tables are thread-safe with respect to matching operations, but are not thread-safe with respect to modification. 访问筛选器表的线程应由 ReaderWriterLock 或类似的锁定语义来进行同步。Threads that access a filter table should be synchronized by the ReaderWriterLock or similar locking semantic. 使用此锁定使筛选器表可以同时运行多个读入操作,例如匹配操作;不过,若要写入筛选器表(例如添加筛选器),则线程必须等待独占锁。This lock allows multiple reads of a filter table (for example, a match operation) to run simultaneously, but in order to write to a filter table (for example, adding a filter), a thread must wait for an exclusive lock.

当将筛选器添加到表时,完成所有编译。All compilation is done when filters are added to the table. 如果您提前创建筛选器表,并且始终没有编辑它,则在匹配过程中不需要锁定。If you create a filter table in advance, and never edit it, locking is not necessary during a match.