Skip to content

Updates to Copilot highlights per revised guidance #46937

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 33 commits into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5cd4a85
Update how-to.md
anandmeg Jun 24, 2025
50e9de2
Update migrate-from-newtonsoft.md
anandmeg Jun 24, 2025
1ad831c
Update how-to.md
anandmeg Jun 24, 2025
365db4c
Update deserialization.md
anandmeg Jun 24, 2025
4b120df
Update customize-properties.md
anandmeg Jun 24, 2025
000e39f
Update how-to-convert-a-string-to-a-number.md
anandmeg Jun 24, 2025
768d6a9
Update how-to-initialize-a-dictionary-with-a-collection-initializer.md
anandmeg Jun 24, 2025
6d4eb0f
Update concatenate-multiple-strings.md
anandmeg Jun 24, 2025
3e69412
Update parse-strings-using-split.md
anandmeg Jun 24, 2025
7f5b8df
Update concatenate-multiple-strings.md
anandmeg Jun 24, 2025
ac4fc21
Update how-to-initialize-a-dictionary-with-a-collection-initializer.md
anandmeg Jun 24, 2025
753bb6d
Update how-to-convert-a-string-to-a-number.md
anandmeg Jun 24, 2025
29fd2f5
Update customize-properties.md
anandmeg Jun 24, 2025
711e5a9
Update deserialization.md
anandmeg Jun 24, 2025
e103dfa
Update migrate-from-newtonsoft.md
anandmeg Jun 24, 2025
3586263
Update how-to.md
anandmeg Jun 24, 2025
f564846
Update concatenate-multiple-strings.md
anandmeg Jun 24, 2025
7af16ac
Update parse-strings-using-split.md
anandmeg Jun 24, 2025
70017b2
Update how-to-initialize-a-dictionary-with-a-collection-initializer.md
anandmeg Jun 24, 2025
afe32d1
Update how-to-convert-a-string-to-a-number.md
anandmeg Jun 24, 2025
5c85852
Update customize-properties.md
anandmeg Jun 24, 2025
0a4d474
Update deserialization.md
anandmeg Jun 24, 2025
a34a0e6
Update how-to.md
anandmeg Jun 24, 2025
5300a75
Update migrate-from-newtonsoft.md
anandmeg Jun 24, 2025
ba3e1b0
Update how-to.md
anandmeg Jun 24, 2025
767c2ce
Apply suggestion
anandmeg Jun 25, 2025
39c7561
Apply suggestion
anandmeg Jun 25, 2025
2a68807
Apply suggestion
anandmeg Jun 25, 2025
4cf63c6
Apply suggestion
anandmeg Jun 25, 2025
01afd38
Apply suggestion
anandmeg Jun 25, 2025
b344817
Apply suggestion
anandmeg Jun 25, 2025
570f874
Apply suggestion
anandmeg Jun 25, 2025
3bbc394
Apply suggestion
anandmeg Jun 25, 2025
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
10 changes: 5 additions & 5 deletions docs/csharp/how-to/concatenate-multiple-strings.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ms.custom: copilot-scenario-highlight
[!INCLUDE[interactive-note](~/includes/csharp-interactive-note.md)]

> [!TIP]
> You can use AI assistance to [concatenate strings with GitHub Copilot](#use-github-copilot-to-concatenate-strings).
> You can use AI assistance to [concatenate strings](#use-ai-to-concatenate-strings).

## String literals

Expand Down Expand Up @@ -70,9 +70,9 @@ combines an array of words, adding a space between each word in the array:

This option can cause more allocations than other methods for concatenating collections, as it creates an intermediate string for each iteration. If optimizing performance is critical, consider the [`StringBuilder`](#stringbuilder) class or the [`String.Concat` or `String.Join`](#stringconcat-or-stringjoin) method to concatenate a collection, instead of `Enumerable.Aggregate`.

## Use GitHub Copilot to concatenate strings
## Use AI to concatenate strings

You can use GitHub Copilot in your IDE to generate C# code to concatenate multiple strings. You can customize the prompt to specify strings and the method to use per your requirements.
You can use AI tools, such as GitHub Copilot, to generate C# code to concatenate multiple strings. You can customize the prompt to specify strings and the method to use per your requirements.

The following text shows an example prompt for Copilot Chat:

Expand All @@ -82,10 +82,10 @@ Generate C# code to use String.Format to build an output string "Hi x, today's d

GitHub Copilot is powered by AI, so surprises and mistakes are possible. For more information, see [Copilot FAQs](https://aka.ms/copilot-general-use-faqs).

Learn more about [GitHub Copilot in Visual Studio](/visualstudio/ide/visual-studio-github-copilot-install-and-states) and [GitHub Copilot in VS Code](https://code.visualstudio.com/docs/copilot/overview).

## See also

- <xref:System.String>
- <xref:System.Text.StringBuilder>
- [Strings](../programming-guide/strings/index.md)
- [GitHub Copilot in Visual Studio](/visualstudio/ide/visual-studio-github-copilot-install-and-states)
- [GitHub Copilot in VS Code](https://code.visualstudio.com/docs/copilot/overview)
10 changes: 5 additions & 5 deletions docs/csharp/how-to/parse-strings-using-split.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The <xref:System.String.Split%2A?displayProperty=nameWithType> method creates an
[!INCLUDE[interactive-note](~/includes/csharp-interactive-note.md)]

> [!TIP]
> You can use AI assistance to [split a string with GitHub Copilot](#use-github-copilot-to-split-a-string).
> You can use AI assistance to [split a string](#use-ai-to-split-a-string).

## Split a string into words

Expand Down Expand Up @@ -76,9 +76,9 @@ The following example shows the effect of trimming entries:

The untrimmed entries have extra whitespace before the numerals.

## Use GitHub Copilot to split a string
## Use AI to split a string

You can use GitHub Copilot in your IDE to generate code to split strings using `String.Split` in C#. You can customize the prompt to use strings and delimiters per your requirements.
You can use AI tools, such as GitHub Copilot, to generate code to split strings using `String.Split` in C#. You can customize the prompt to use strings and delimiters per your requirements.

The following text shows an example prompt for Copilot Chat:

Expand All @@ -90,10 +90,10 @@ Provide example output.

GitHub Copilot is powered by AI, so surprises and mistakes are possible. For more information, see [Copilot FAQs](https://aka.ms/copilot-general-use-faqs).

Learn more about [GitHub Copilot in Visual Studio](/visualstudio/ide/visual-studio-github-copilot-install-and-states) and [GitHub Copilot in VS Code](https://code.visualstudio.com/docs/copilot/overview).

## See also

- [Extract elements from a string](../../standard/base-types/divide-up-strings.md)
- [Strings](../programming-guide/strings/index.md)
- [.NET regular expressions](../../standard/base-types/regular-expressions.md)
- [GitHub Copilot in Visual Studio](/visualstudio/ide/visual-studio-github-copilot-install-and-states)
- [GitHub Copilot in VS Code](https://code.visualstudio.com/docs/copilot/overview)
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ A <xref:System.Collections.Generic.Dictionary%602> contains a collection of key/
> while the second part of example, the public read / write indexer method, quietly overwrites the already existing entry with the same key.

> [!TIP]
> You can use AI assistance to [initialize a dictionary with GitHub Copilot](#use-github-copilot-to-initialize-a-dictionary).
> You can use AI assistance to [initialize a dictionary](#use-ai-to-initialize-a-dictionary).

## Example

Expand All @@ -34,9 +34,9 @@ In the following code example, a <xref:System.Collections.Generic.Dictionary%602

Note the two pairs of braces in each element of the collection in the first declaration. The innermost braces enclose the object initializer for the `StudentName`, and the outermost braces enclose the initializer for the key/value pair to be added to the `students` <xref:System.Collections.Generic.Dictionary%602>. Finally, the whole collection initializer for the dictionary is enclosed in braces. In the second initialization, the left side of the assignment is the key and the right side is the value, using an object initializer for `StudentName`.

## Use GitHub Copilot to initialize a dictionary
## Use AI to initialize a dictionary

You can use GitHub Copilot in your IDE to generate C# code to initialize a dictionary with a collection initializer. You can customize the prompt to add specifics per your requirements.
You can use AI tools, such as GitHub Copilot, to generate C# code to initialize a dictionary with a collection initializer. You can customize the prompt to add specifics per your requirements.

The following text shows an example prompt for Copilot Chat:

Expand All @@ -46,8 +46,8 @@ Generate C# code to initialize Dictionary<int, Employee> using key-value pairs w

GitHub Copilot is powered by AI, so surprises and mistakes are possible. For more information, see [Copilot FAQs](https://aka.ms/copilot-general-use-faqs).

Learn more about [GitHub Copilot in Visual Studio](/visualstudio/ide/visual-studio-github-copilot-install-and-states) and [GitHub Copilot in VS Code](https://code.visualstudio.com/docs/copilot/overview).

## See also

- [Object and Collection Initializers](./object-and-collection-initializers.md)
- [GitHub Copilot in Visual Studio](/visualstudio/ide/visual-studio-github-copilot-install-and-states)
- [GitHub Copilot in VS Code](https://code.visualstudio.com/docs/copilot/overview)
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ It's slightly more efficient and straightforward to call a `TryParse` method (fo
You use `Parse` or `TryParse` methods on the numeric type you expect the string contains, such as the <xref:System.Int32?displayProperty=nameWithType> type. The <xref:System.Convert.ToInt32%2A?displayProperty=nameWithType> method uses <xref:System.Int32.Parse%2A> internally. The `Parse` method returns the converted number; the `TryParse` method returns a boolean value that indicates whether the conversion succeeded, and returns the converted number in an `out` parameter. If the string isn't in a valid format, `Parse` throws an exception, but `TryParse` returns `false`. When calling a `Parse` method, you should always use exception handling to catch a <xref:System.FormatException> when the parse operation fails.

> [!TIP]
> You can use AI assistance to [convert a string to a number with GitHub Copilot](#use-github-copilot-to-convert-a-string-to-a-number).
> You can use AI assistance to [convert a string to a number](#use-ai-to-convert-a-string-to-a-number).

## Call Parse or TryParse methods

Expand Down Expand Up @@ -55,9 +55,9 @@ The following example calls the <xref:System.Convert.ToInt32%28System.String%29?

[!code-csharp[Parsing with Convert methods](~/samples/snippets/csharp/programming-guide/string-to-number/convert/program.cs)]

## Use GitHub Copilot to convert a string to a number
## Use AI to convert a string to a number

You can use GitHub Copilot in your IDE to generate C# code to convert a string to a number. You can customize the prompt to use a string per your requirements.
You can use AI tools, such as GitHub Copilot, to generate C# code to convert a string to a number. You can customize the prompt to use a string per your requirements.

The following text shows an example prompt for Copilot Chat:

Expand All @@ -67,4 +67,7 @@ Show me how to parse a string as a number, but don't throw an exception if the i

GitHub Copilot is powered by AI, so surprises and mistakes are possible. For more information, see [Copilot FAQs](https://aka.ms/copilot-general-use-faqs).

Learn more about [GitHub Copilot in Visual Studio](/visualstudio/ide/visual-studio-github-copilot-install-and-states) and [GitHub Copilot in VS Code](https://code.visualstudio.com/docs/copilot/overview).
## See also

- [GitHub Copilot in Visual Studio](/visualstudio/ide/visual-studio-github-copilot-install-and-states)
- [GitHub Copilot in VS Code](https://code.visualstudio.com/docs/copilot/overview)
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ By default, property names and dictionary keys are unchanged in the JSON output,
> The [web default](configure-options.md#web-defaults-for-jsonserializeroptions) naming policy is camel case.

> [!TIP]
> You can use AI assistance to [create an object with custom serialization properties with GitHub Copilot](#use-github-copilot-to-customize-how-property-names-are-serialized).
> You can use AI assistance to [create an object with custom serialization properties](#use-ai-to-customize-how-property-names-are-serialized).

For other scenarios that require special handling of JSON property names and values, you can [implement custom converters](converters-how-to.md).

Expand Down Expand Up @@ -243,9 +243,9 @@ By default, properties are serialized in the order in which they're defined in t

:::code language="csharp" source="snippets/how-to-6-0/csharp/PropertyOrder.cs":::

## Use GitHub Copilot to customize how property names are serialized
## Use AI to customize how property names are serialized

You can prompt GitHub Copilot to apply patterns of changes to how your code serializes.
You can use AI tools, such as GitHub Copilot, to apply patterns of changes to how your code serializes.

Suppose your class declaration has properties that follow `PascalCasing`, and the JSON standard for your project is `snake_casing`. You can use AI to add the necessary [[JsonPropertyName]](xref:System.Text.Json.Serialization.JsonPropertyNameAttribute) attributes to every property in your class. You can use Copilot to make these changes with a chat prompt like this:

Expand Down Expand Up @@ -275,9 +275,9 @@ Use built-in serialization attributes.

GitHub Copilot is powered by AI, so surprises and mistakes are possible. For more information, see [Copilot FAQs](https://aka.ms/copilot-general-use-faqs).

Learn more about [GitHub Copilot in Visual Studio](/visualstudio/ide/visual-studio-github-copilot-install-and-states) and [GitHub Copilot in VS Code](https://code.visualstudio.com/docs/copilot/overview).

## See also

- [System.Text.Json overview](overview.md)
- [How to serialize and deserialize JSON](how-to.md)
- [GitHub Copilot in Visual Studio](/visualstudio/ide/visual-studio-github-copilot-install-and-states)
- [GitHub Copilot in VS Code](https://code.visualstudio.com/docs/copilot/overview)
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ This article shows how to use the <xref:System.Text.Json?displayProperty=fullNam
A common way to deserialize JSON is to have (or create) a .NET class with properties and fields that represent one or more of the JSON properties. Then, to deserialize from a string or a file, call the <xref:System.Text.Json.JsonSerializer.Deserialize%2A?displayProperty=nameWithType> method. For the generic overloads, the generic type parameter is the .NET class. For the non-generic overloads, you pass the type of the class as a method parameter. You can deserialize either synchronously or asynchronously.

> [!TIP]
> You can use AI assistance to [deserialize a JSON string with GitHub Copilot](#use-github-copilot-to-deserialize-json).
> You can use AI assistance to [deserialize a JSON string](#use-ai-to-deserialize-json).

Any JSON properties that aren't represented in your class are ignored [by default](missing-members.md). Also, if any properties on the type are [required](required-properties.md) but not present in the JSON payload, deserialization will fail.

Expand Down Expand Up @@ -87,9 +87,9 @@ To deserialize from UTF-8, call a <xref:System.Text.Json.JsonSerializer.Deserial
:::code language="csharp" source="snippets/how-to/csharp/RoundtripToUtf8.cs" id="Deserialize2":::
:::code language="vb" source="snippets/how-to/vb/RoundtripToUtf8.vb" id="Deserialize2":::

## Use GitHub Copilot to deserialize JSON
## Use AI to deserialize JSON

You can use GitHub Copilot in your IDE to generate code that uses `System.Text.Json` to deserialize from JSON. You can customize the prompt to use a JSON string with property names and values that suit your requirements.
You can use AI tools, such as GitHub Copilot, to generate code that uses `System.Text.Json` to deserialize from JSON. You can customize the prompt to use a JSON string with property names and values that suit your requirements.

The following text shows an example prompt for Copilot Chat:

Expand All @@ -101,4 +101,7 @@ Provide example output.

GitHub Copilot is powered by AI, so surprises and mistakes are possible. For more information, see [Copilot FAQs](https://aka.ms/copilot-general-use-faqs).

Learn more about [GitHub Copilot in Visual Studio](/visualstudio/ide/visual-studio-github-copilot-install-and-states) and [GitHub Copilot in VS Code](https://code.visualstudio.com/docs/copilot/overview).
## See also

- [GitHub Copilot in Visual Studio](/visualstudio/ide/visual-studio-github-copilot-install-and-states)
- [GitHub Copilot in VS Code](https://code.visualstudio.com/docs/copilot/overview)
13 changes: 8 additions & 5 deletions docs/standard/serialization/system-text-json/how-to.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ adobe-target: true
This article shows how to use the <xref:System.Text.Json?displayProperty=fullName> namespace to serialize to JavaScript Object Notation (JSON). If you're porting existing code from `Newtonsoft.Json`, see [How to migrate to `System.Text.Json`](migrate-from-newtonsoft.md).

> [!TIP]
> You can use AI assistance to [serialize to JSON with GitHub Copilot](#use-github-copilot-to-serialize-to-json).
> You can use AI assistance to [serialize to JSON](#use-ai-to-serialize-to-json).

To write JSON to a string or to a file, call the <xref:System.Text.Json.JsonSerializer.Serialize%2A?displayProperty=nameWithType> method.

Expand Down Expand Up @@ -49,7 +49,7 @@ The preceding examples use type inference for the type being serialized. An over
:::code language="csharp" source="snippets/how-to/csharp/SerializeWithGenericParameter.cs" highlight="23":::
:::code language="vb" source="snippets/how-to/vb/RoundtripToString.vb" id="SerializeWithGenericParameter":::

You can also use GitHub Copilot to generate serialization code for you. For instructions, see the [Use GitHub Copilot](#use-github-copilot-to-serialize-to-json) section in this article.
You can also use AI to generate serialization code for you. For instructions, see the [Use AI](#use-ai-to-serialize-to-json) section in this article.

## Serialization behavior

Expand Down Expand Up @@ -108,9 +108,9 @@ Starting in .NET 9, you can also customize the indent character and size using <
> [!TIP]
> If you use `JsonSerializerOptions` repeatedly with the same options, don't create a new `JsonSerializerOptions` instance each time you use it. Reuse the same instance for every call. For more information, see [Reuse JsonSerializerOptions instances](configure-options.md#reuse-jsonserializeroptions-instances).

## Use GitHub Copilot to serialize to JSON
## Use AI to serialize to JSON

You can use GitHub Copilot in your IDE to generate code that uses `System.Text.Json` to serialize to JSON. You can customize the prompt to use object fields that suit your requirements.
You can use AI tools, such as GitHub Copilot, to generate code that uses `System.Text.Json` to serialize to JSON. You can customize the prompt to use object fields that suit your requirements.

The following text shows an example prompt for Copilot Chat:

Expand All @@ -122,4 +122,7 @@ Provide example output.

GitHub Copilot is powered by AI, so surprises and mistakes are possible. For more information, see [Copilot FAQs](https://aka.ms/copilot-general-use-faqs).

Learn more about [GitHub Copilot in Visual Studio](/visualstudio/ide/visual-studio-github-copilot-install-and-states) and [GitHub Copilot in VS Code](https://code.visualstudio.com/docs/copilot/overview).
## See also

- [GitHub Copilot in Visual Studio](/visualstudio/ide/visual-studio-github-copilot-install-and-states)
- [GitHub Copilot in VS Code](https://code.visualstudio.com/docs/copilot/overview)
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The `System.Text.Json` namespace provides functionality for serializing to and d
* .NET Core 2.0, 2.1, and 2.2

> [!TIP]
> You can use AI assistance to [migrate from `Newtonsoft.Json`](#use-github-copilot-to-migrate).
> You can use AI assistance to [migrate from `Newtonsoft.Json`](#use-ai-to-migrate).

`System.Text.Json` focuses primarily on performance, security, and standards compliance. It has some key differences in default behavior and doesn't aim to have feature parity with `Newtonsoft.Json`. For some scenarios, `System.Text.Json` currently has no built-in functionality, but there are recommended workarounds. For other scenarios, workarounds are impractical.

Expand Down Expand Up @@ -630,9 +630,9 @@ System.Text.Json sets limits that can't be changed for some values, such as the

Newtonsoft parses `NaN`, `Infinity`, and `-Infinity` JSON string tokens. With System.Text.Json, use <xref:System.Text.Json.Serialization.JsonNumberHandling.AllowNamedFloatingPointLiterals?displayProperty=nameWithType>. For information about how to use this setting, see [Allow or write numbers in quotes](invalid-json.md#allow-or-write-numbers-in-quotes).

## Use GitHub Copilot to migrate
## Use AI to migrate

You can get coding help from GitHub Copilot to migrate your code from `Newtonsoft.Json` to `System.Text.Json` within your IDE. You can customize the prompt per your requirements.
You can use AI tools, such as GitHub Copilot, to migrate your code from `Newtonsoft.Json` to `System.Text.Json` within your IDE. You can customize the prompt per your requirements.

**Example prompt for Copilot Chat**

Expand All @@ -651,9 +651,9 @@ Console.WriteLine(output);

GitHub Copilot is powered by AI, so surprises and mistakes are possible. For more information, see [Copilot FAQs](https://aka.ms/copilot-general-use-faqs).

Learn more about [GitHub Copilot in Visual Studio](/visualstudio/ide/visual-studio-github-copilot-install-and-states) and [GitHub Copilot in VS Code](https://code.visualstudio.com/docs/copilot/overview).

## Additional resources

* [System.Text.Json overview](overview.md)
* [How to serialize and deserialize JSON](how-to.md)
* [GitHub Copilot in Visual Studio](/visualstudio/ide/visual-studio-github-copilot-install-and-states)
* [GitHub Copilot in VS Code](https://code.visualstudio.com/docs/copilot/overview)