当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET XPathQueryGenerator.CreateFromDataContractSerializer方法代码示例

本文整理汇总了VB.NET中System.Runtime.Serialization.XPathQueryGenerator.CreateFromDataContractSerializer方法的典型用法代码示例。如果您正苦于以下问题:VB.NET XPathQueryGenerator.CreateFromDataContractSerializer方法的具体用法?VB.NET XPathQueryGenerator.CreateFromDataContractSerializer怎么用?VB.NET XPathQueryGenerator.CreateFromDataContractSerializer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Runtime.Serialization.XPathQueryGenerator的用法示例。


在下文中一共展示了XPathQueryGenerator.CreateFromDataContractSerializer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。

示例1: Main

' 导入命名空间
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Reflection
Imports System.Runtime.Serialization
Imports System.Xml

Namespace GeneratPathExample

    Class Program

        Shared Sub Main(ByVal args As String())

            ' Get the type of the class that defines the data contract.
            Dim t As Type = GetType(Order)

            ' Get the meta data for the specific members to be used in the query.
            Dim mi As MemberInfo() = t.GetMember("Product")
            Dim mi2 As MemberInfo() = t.GetMember("Value")
            Dim mi3 As MemberInfo() = t.GetMember("Quantity")

            ' Call the function below to generate and display the query.
            GenerateXPath(t, mi)
            GenerateXPath(t, mi2)
            GenerateXPath(t, mi3)


            ' Get the type of the second class that defines a data contract.
            Dim t2 As Type = GetType(Line)

            ' Get the meta data for the member to be used in the query.
            Dim mi4 As MemberInfo() = t2.GetMember("Items")

            GenerateXPath(t2, mi4)

            Console.ReadLine()
        End Sub

        Shared Sub GenerateXPath(ByVal t As Type, ByVal mi As MemberInfo())


            ' Create a new name table and name space manager.
            Dim nt As New NameTable()
            Dim xname As New XmlNamespaceManager(nt)


            ' Generate the query and print it.
            Dim query As String = XPathQueryGenerator.CreateFromDataContractSerializer( _
                t, mi, xname)
            Console.WriteLine(query)
            Console.WriteLine()


            ' Display the namespaces and prefixes used in the data contract.
            Dim s As String
            For Each s In xname
                Console.WriteLine("{0}  = {1}", s, xname.LookupNamespace(s))
            Next

            Console.WriteLine()

        End Sub
    End Class


    <DataContract(Namespace:="http://www.cohowinery.com/")> _
        Public Class Line

        Private itemsValue As Order()

        <DataMember()>
        Public Property Item() As Order()

            Get
                Return itemsValue
            End Get
            Set(ByVal value As Order())
                itemsValue = value
            End Set
        End Property

    End Class

    <DataContract(Namespace:="http://contoso.com")> _
    Public Class Order

        Private productValue As String
        Private quantityValue As Integer
        Private valueValue As Decimal

        <DataMember(Name:="cost")>
        Public Property Value() As String

            Get
                Return valueValue
            End Get
            Set(ByVal value As String)
                valueValue = value
            End Set
        End Property

        <DataMember(Name:="quantity")> _
        Public Property Quantity() As Integer

            Get
                Return quantityValue
            End Get
            set(ByVal value As Integer)
                quantityValue = value
            End Set
        End Property


        <DataMember(Name:="productName")> _
        Public Property Product() As String

            Get
                Return productValue
            End Get
            Set(ByVal value As String)
                productValue = value
            End Set
        End Property
    End Class
End Namespace
开发者ID:VB.NET开发者,项目名称:System.Runtime.Serialization,代码行数:126,代码来源:XPathQueryGenerator.CreateFromDataContractSerializer


注:本文中的System.Runtime.Serialization.XPathQueryGenerator.CreateFromDataContractSerializer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。