當前位置: 首頁>>代碼示例>>VB.NET>>正文


VB.NET ExpandoObject類代碼示例

本文整理匯總了VB.NET中System.Dynamic.ExpandoObject的典型用法代碼示例。如果您正苦於以下問題:VB.NET ExpandoObject類的具體用法?VB.NET ExpandoObject怎麽用?VB.NET ExpandoObject使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ExpandoObject類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。

示例1:

sampleObject.Test = "Dynamic Property"
Console.WriteLine(sampleObject.test)
Console.WriteLine(sampleObject.test.GetType())
開發者ID:VB.NET開發者,項目名稱:System.Dynamic,代碼行數:3,代碼來源:ExpandoObject

輸出:

Dynamic Property
System.String

示例2: Function

sampleObject.Number = 10
sampleObject.Increment = Function() sampleObject.Number + 1
' Before calling the Increment method.
Console.WriteLine(sampleObject.number)

sampleObject.Increment.Invoke()

' After calling the Increment method.
Console.WriteLine(sampleObject.number)
開發者ID:VB.NET開發者,項目名稱:System.Dynamic,代碼行數:9,代碼來源:ExpandoObject

輸出:

10
11

示例3: Main

Sub Main()
    Dim employee, manager As Object

    employee = New ExpandoObject()
    employee.Name = "John Smith"
    employee.Age = 33

    manager = New ExpandoObject()
    manager.Name = "Allison Brown"
    manager.Age = 42
    manager.TeamSize = 10

    WritePerson(manager)
    WritePerson(employee)
End Sub

Private Sub WritePerson(ByVal person As Object)

    Console.WriteLine("{0} is {1} years old.",
                      person.Name, person.Age)
    ' The following statement causes an exception
    ' if you pass the employee object.
    ' Console.WriteLine("Manages {0} people", person.TeamSize)

End Sub
開發者ID:VB.NET開發者,項目名稱:System.Dynamic,代碼行數:25,代碼來源:ExpandoObject

示例4: ExpandoObject

Dim employee As Object = New ExpandoObject()
employee.Name = "John Smith"
employee.Age = 33
For Each member In CType(employee, IDictionary(Of String, Object))
    Console.WriteLine(member.Key & ": " & member.Value)
Next
開發者ID:VB.NET開發者,項目名稱:System.Dynamic,代碼行數:6,代碼來源:ExpandoObject

輸出:

Name: John Smith
Age: 33

示例5: ExpandoObject

Dim employee As Object = New ExpandoObject()
employee.Name = "John Smith"
CType(employee, IDictionary(Of String, Object)).Remove("Name")
開發者ID:VB.NET開發者,項目名稱:System.Dynamic,代碼行數:3,代碼來源:ExpandoObject

示例6: Main

' Add "Imports System.ComponentModel" line 
' to the beginning of the file.
Sub Main()
    Dim employee As Object = New ExpandoObject
    AddHandler CType(
        employee, INotifyPropertyChanged).PropertyChanged,
        AddressOf HandlePropertyChanges
    employee.Name = "John Smith"
End Sub

Private Sub HandlePropertyChanges(
       ByVal sender As Object, ByVal e As PropertyChangedEventArgs)
    Console.WriteLine("{0} has changed.", e.PropertyName)
End Sub
開發者ID:VB.NET開發者,項目名稱:System.Dynamic,代碼行數:14,代碼來源:ExpandoObject


注:本文中的System.Dynamic.ExpandoObject類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。