本文整理匯總了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())
輸出:
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)
輸出:
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
示例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
輸出:
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")
示例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