Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static void BrokenCustomTypeExample()
Person person = new Person { Name = "John", Age = 30 };
Clipboard.SetData("MyApp.Person", person); // No data is stored

// Later attempts to retrieve the data return null
// Later attempts to retrieve the data return a NotSupportedException instance
object data = Clipboard.GetData("MyApp.Person");
}
// </ObsoleteCustomType>
Expand All @@ -31,10 +31,9 @@ public static void ObsoleteGetDataExample()
// Don't use - GetData() is obsolete in .NET 10
object data = Clipboard.GetData("MyApp.Person"); // Obsolete method

// Always returns null on a custom object type
if (data != null)
// Returns a NotSupportedException instance for a custom object type
if (data is Person person)
{
Person person = (Person)data;
Console.WriteLine($"Processing person: {person.Name}, Age: {person.Age}");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Namespace ClipboardExamples
Dim person As New Person With {.Name = "John", .Age = 30}
Clipboard.SetData("MyApp.Person", person) ' No data is stored

' Later attempts to retrieve the data return null
' Later attempts to retrieve the data return a NotSupportedException instance
Dim data As Object = Clipboard.GetData("MyApp.Person")
End Sub
' </ObsoleteCustomType>
Expand All @@ -26,9 +26,9 @@ Namespace ClipboardExamples
' Don't use - GetData() is obsolete in .NET 10
Dim data As Object = Clipboard.GetData("MyApp.Person") ' Obsolete method

' Always returns null on a custom object type
If data IsNot Nothing Then
Dim person As Person = CType(data, Person)
' Returns a NotSupportedException instance for a custom object type
If TypeOf data Is Person Then
Dim person As Person = DirectCast(data, Person)
Console.WriteLine($"Processing person: {person.Name}, Age: {person.Age}")
End If
End Sub
Expand Down
Loading