MatchAttribute 类 
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示使用文本模式匹配进行的匹配的特性。 此类不能被继承。
public ref class MatchAttribute sealed : Attribute[System.AttributeUsage(System.AttributeTargets.All)]
public sealed class MatchAttribute : Attribute[<System.AttributeUsage(System.AttributeTargets.All)>]
type MatchAttribute = class
    inherit AttributePublic NotInheritable Class MatchAttribute
Inherits Attribute- 继承
- 属性
示例
#using <System.dll>
#using <System.Web.Services.dll>
using namespace System;
using namespace System::Web::Services::Protocols;
public ref class Example_Headers
{
public:
   [MatchAttribute("TITLE>(.*?)<")]
   String^ Title;
   [MatchAttribute("",Pattern="h1>(.*?)<",IgnoreCase=true)]
   String^ H1;
   [MatchAttribute("H2>((([^<,]*),?)+)<",Group=3,Capture=4)]
   String^ Element;
   [MatchAttribute("H2>((([^<,]*),?){2,})<",Group=3,MaxRepeats=0)]
   array<String^>^ Elements1;
   [MatchAttribute("H2>((([^<,]*),?){2,})<",Group=3,MaxRepeats=1)]
   array<String^>^ Elements2;
   [MatchAttribute("H3 ([^=]*)=([^>]*)",Group=1)]
   String^ Attribute;
   [MatchAttribute("H3 ([^=]*)=([^>]*)",Group=2)]
   String^ Value;
};
public ref class MatchAttribute_Example: public HttpGetClientProtocol
{
public:
   MatchAttribute_Example()
   {
      Url = "http://localhost";
   }
   [HttpMethodAttribute(TextReturnReader::typeid,UrlParameterWriter::typeid)]
   Example_Headers^ GetHeaders()
   {
      return ((Example_Headers^)(Invoke( "GetHeaders", ( Url + "/MyHeaders.html" ),
         gcnew array<Object^>(0) )));
   }
   System::IAsyncResult^ BeginGetHeaders( System::AsyncCallback^ callback,
      Object^ asyncState )
   {
      return BeginInvoke( "GetHeaders", ( Url + "/MyHeaders.html" ),
         gcnew array<Object^>(0), callback, asyncState );
   }
   Example_Headers^ EndGetHeaders( System::IAsyncResult^ asyncResult )
   {
      return (Example_Headers^)(EndInvoke( asyncResult ));
   }
};
using System;
using System.Web.Services.Protocols;
public class MatchAttribute_Example : HttpGetClientProtocol
{
    public MatchAttribute_Example()
    {
        Url = "http://localhost";
    }
    [HttpMethodAttribute(typeof(TextReturnReader), typeof(UrlParameterWriter))]
    public Example_Headers GetHeaders()
    {
        return ((Example_Headers)Invoke("GetHeaders", (Url + "/MyHeaders.html"),
            new object[0]));
    }
    public System.IAsyncResult BeginGetHeaders(System.AsyncCallback callback,
        object asyncState)
    {
        return BeginInvoke("GetHeaders", (Url + "/MyHeaders.html"),
            new object[0], callback, asyncState);
    }
    public Example_Headers EndGetHeaders(System.IAsyncResult asyncResult)
    {
        return (Example_Headers)(EndInvoke(asyncResult));
    }
}
public class Example_Headers
{
    [MatchAttribute("TITLE>(.*?)<")]
    public string Title;
    [MatchAttribute("", Pattern="h1>(.*?)<", IgnoreCase=true)]
    public string H1;
    [MatchAttribute("H2>((([^<,]*),?)+)<", Group=3, Capture=4)]
    public string Element;
    [MatchAttribute("H2>((([^<,]*),?){2,})<", Group=3, MaxRepeats=0)]
    public string[] Elements1;
    [MatchAttribute("H2>((([^<,]*),?){2,})<", Group=3, MaxRepeats=1)]
    public string[] Elements2;
    [MatchAttribute("H3 ([^=]*)=([^>]*)", Group=1)]
    public string Attribute;
    [MatchAttribute("H3 ([^=]*)=([^>]*)", Group=2)]
    public string Value;
}
Imports System.Web.Services.Protocols
Public Class MatchAttribute_Example
    Inherits HttpGetClientProtocol
    Public Sub New()
        Url = "http://localhost"
    End Sub
    <HttpMethodAttribute(GetType(TextReturnReader), GetType(UrlParameterWriter))> _
    Public Function GetHeaders() As Headers
        Return CType(Invoke("GetHeaders", Url + "/MyHeaders.html", New Object(0) {}), Headers)
    End Function 'GetHeaders
    Public Function BeginGetHeaders(ByVal callback As System.AsyncCallback, ByVal asyncState As Object) As _
                                                                         System.IAsyncResult
        Return BeginInvoke("GetHeaders", Url + "/MyHeaders.html", New Object(0) {}, _
                                                                          callback, asyncState)
    End Function 'BeginGetHeaders
    Public Function EndGetHeaders(ByVal asyncResult As System.IAsyncResult) As Headers
        Return CType(EndInvoke(asyncResult), Headers)
    End Function 'EndGetHeaders
End Class
Public Class Headers
    <MatchAttribute("TITLE>(.*?)<")> _
    Public Title As String
    <MatchAttribute("", Pattern:="h1>(.*?)<", IgnoreCase:=True)> _
    Public H1 As String
    <MatchAttribute("H2>((([^<,]*),?)+)<", Group:=3, Capture:=4)> _
    Public Element As String
    <MatchAttribute("H2>((([^<,]*),?){2,})<", Group:=3, MaxRepeats:=0)> _
    Public Elements1() As String
    <MatchAttribute("H2>((([^<,]*),?){2,})<", Group:=3, MaxRepeats:=1)> _
    Public Elements2() As String
    <MatchAttribute("H3 ([^=]*)=([^>]*)", Group:=1)> _
    Public Attribute As String
    <MatchAttribute("H3 ([^=]*)=([^>]*)", Group:=2)> _
    Public Value As String
End Class
注解
文本模式匹配允许 XML Web 服务通过使用正则表达式来分析现有 HTML 内容。 XML Web 服务使用 match 元素指定要在服务说明中分析的内容。 这些 match 元素指定多个项:用于分析现有 HTML 页面内容的正则表达式、分析是否必须不区分大小写,以及应返回多少个与正则表达式匹配的内容实例。 当客户端使用 Wsdl.exe 工具生成代理类时,代理类的方法包括一个 MatchAttribute 详细说明服务说明中找到的 match 元素。
有关文本模式匹配的详细信息,请参阅 如何:创建分析网页内容的 Web 服务。
构造函数
| MatchAttribute(String) | 使用指定的模式初始化 MatchAttribute 类的新实例。 | 
属性
| Capture | 获取或设置一个值,该值表示分组中匹配项的索引。 | 
| Group | 获取或设置一个值,该值表示相关的匹配项的分组。 | 
| IgnoreCase | 获取或设置一个值,该值指示要匹配的模式是否不区分大小写。 | 
| MaxRepeats | 获取或设置要从匹配返回的值的最大数目。 | 
| Pattern | 获取或设置表示要匹配的模式的正则表达式。 | 
| TypeId | 在派生类中实现时,获取此 Attribute 的唯一标识符。(继承自 Attribute) | 
方法
| Equals(Object) | 返回一个值,该值指示此实例是否与指定的对象相等。(继承自 Attribute) | 
| GetHashCode() | 返回此实例的哈希代码。(继承自 Attribute) | 
| GetType() | 获取当前实例的 Type。(继承自 Object) | 
| IsDefaultAttribute() | 在派生类中重写时,指示此实例的值是否是派生类的默认值。(继承自 Attribute) | 
| Match(Object) | 当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。(继承自 Attribute) | 
| MemberwiseClone() | 创建当前 Object 的浅表副本。(继承自 Object) | 
| ToString() | 返回表示当前对象的字符串。(继承自 Object) | 
显式接口实现
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) | 将一组名称映射为对应的一组调度标识符。(继承自 Attribute) | 
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) | 检索对象的类型信息,然后可以使用该信息获取接口的类型信息。(继承自 Attribute) | 
| _Attribute.GetTypeInfoCount(UInt32) | 检索对象提供的类型信息接口的数量(0 或 1)。(继承自 Attribute) | 
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) | 提供对某一对象公开的属性和方法的访问。(继承自 Attribute) |