Skip to content

Commit 7e0341d

Browse files
Copilotadegeo
andauthored
Fix clipboard GetData documentation to reflect NotSupportedException instead of null (#2150)
* Initial plan * Fix clipboard GetData comments to reflect NotSupportedException instead of null Co-authored-by: adegeo <67293991+adegeo@users.noreply.github.com> * Change null check to type check for Person in ObsoleteGetDataExample Co-authored-by: adegeo <67293991+adegeo@users.noreply.github.com> * Use DirectCast instead of CType for Person type in VB example Co-authored-by: adegeo <67293991+adegeo@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: adegeo <67293991+adegeo@users.noreply.github.com>
1 parent 6d91a1d commit 7e0341d

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

dotnet-desktop-guide/winforms/migration/snippets/clipboard-dataobject-net10/net/csharp/ObsoletePatterns.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static void BrokenCustomTypeExample()
2020
Person person = new Person { Name = "John", Age = 30 };
2121
Clipboard.SetData("MyApp.Person", person); // No data is stored
2222

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

34-
// Always returns null on a custom object type
35-
if (data != null)
34+
// Returns a NotSupportedException instance for a custom object type
35+
if (data is Person person)
3636
{
37-
Person person = (Person)data;
3837
Console.WriteLine($"Processing person: {person.Name}, Age: {person.Age}");
3938
}
4039
}

dotnet-desktop-guide/winforms/migration/snippets/clipboard-dataobject-net10/net/vb/ObsoletePatterns.vb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Namespace ClipboardExamples
1616
Dim person As New Person With {.Name = "John", .Age = 30}
1717
Clipboard.SetData("MyApp.Person", person) ' No data is stored
1818

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

29-
' Always returns null on a custom object type
30-
If data IsNot Nothing Then
31-
Dim person As Person = CType(data, Person)
29+
' Returns a NotSupportedException instance for a custom object type
30+
If TypeOf data Is Person Then
31+
Dim person As Person = DirectCast(data, Person)
3232
Console.WriteLine($"Processing person: {person.Name}, Age: {person.Age}")
3333
End If
3434
End Sub

0 commit comments

Comments
 (0)