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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions docs/core/deploying/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Deploying a framework-dependent deployment with no third-party dependencies simp

2. Open the `Program.cs` file in an editor, and replace the auto-generated code with the following code. It prompts the user to enter text, and then displays the individual words entered by the user. It uses the regular expression `\w+` to separate the words in the input text.

```cs
```csharp
using System;
using System.Text.RegularExpressions;

Expand Down Expand Up @@ -142,7 +142,7 @@ Deploying a self-contained deployment with no third-party dependencies involves

2. Open the `Program.cs` file in an editor, and replace the auto-generated code with the following code. It prompts the user to enter text, and then displays the individual words entered by the user. It uses the regular expression `\w+` to separate the words in the input text.

```cs
```csharp
using System;
using System.Text.RegularExpressions;

Expand Down
8 changes: 4 additions & 4 deletions docs/core/testing/unit-testing-with-dotnet-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Open a shell window. Create a directory called *unit-testing-using-dotnet-test*

Make *PrimeService* the current directory and run [`dotnet new classlib`](../tools/dotnet-new.md) to create the source project. Rename *Class1.cs* to *PrimeService.cs*. To use test-driven development (TDD), you'll create a failing implementation of the `PrimeService` class:

```cs
```csharp
using System;

namespace Prime.Services
Expand Down Expand Up @@ -97,7 +97,7 @@ Before building the library or the tests, execute [`dotnet restore`](../tools/do

The TDD approach calls for writing one failing test, making it pass, then repeating the process. Remove *UnitTest1.cs* from the *PrimeService.Tests* directory and create a new C# file named *PrimeService_IsPrimeShould.cs* with the following content:

```cs
```csharp
using Xunit;
using Prime.Services;

Expand Down Expand Up @@ -128,7 +128,7 @@ The `[Fact]` attribute denotes a method as a single test. Execute [`dotnet test`

Your test fails. You haven't created the implementation yet. Write the simplest code in the `PrimeService` class to make this test pass:

```cs
```csharp
public bool IsPrime(int candidate)
{
if (candidate == 1)
Expand All @@ -151,7 +151,7 @@ Instead of creating new tests, leverage these two attributes to create a single

Run `dotnet test`, and two of these tests fail. To make all of the tests pass, change the `if` clause at the beginning of the method:

```cs
```csharp
if (candidate < 2)
```

Expand Down
8 changes: 4 additions & 4 deletions docs/core/testing/unit-testing-with-mstest.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Open a shell window. Create a directory called *unit-testing-using-dotnet-test*

Make *PrimeService* the current directory and run [`dotnet new classlib`](../tools/dotnet-new.md) to create the source project. Rename *Class1.cs* to *PrimeService.cs*. To use test-driven development (TDD), you'll create a failing implementation of the `PrimeService` class:

```cs
```csharp
using System;

namespace Prime.Services
Expand Down Expand Up @@ -97,7 +97,7 @@ Before building the library or the tests, execute [`dotnet restore`](../tools/do

The TDD approach calls for writing one failing test, making it pass, then repeating the process. Remove *UnitTest1.cs* from the *PrimeService.Tests* directory and create a new C# file named *PrimeService_IsPrimeShould.cs* with the following content:

```cs
```csharp
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Prime.Services;

Expand Down Expand Up @@ -130,7 +130,7 @@ Save this file and execute [`dotnet test`](../tools/dotnet-test.md) to build the

Your test fails. You haven't created the implementation yet. Write the simplest code in the `PrimeService` class to make this test pass:

```cs
```csharp
public bool IsPrime(int candidate)
{
if (candidate == 1)
Expand All @@ -153,7 +153,7 @@ Instead of creating new tests, leverage these two attributes to create a single

Run `dotnet test`, and two of these tests fail. To make all of the tests pass, change the `if` clause at the beginning of the method:

```cs
```csharp
if (candidate < 2)
```

Expand Down
4 changes: 2 additions & 2 deletions docs/core/tutorials/using-on-mac-vs-full-solution.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Unit tests provide automated software testing during your development and publis

1. Open the file and replace the code with the following:

```cs
```csharp
using Xunit;
using TextUtils;
using System.Diagnostics;
Expand Down Expand Up @@ -128,7 +128,7 @@ Unit tests provide automated software testing during your development and publis

1. Testing individual return values with a `Fact` is only the beginning of what you can do with unit testing. Another powerful technique allows you to test several values at once using a `Theory`. Add the following method to your `TextUtils_GetWordCountShould` class. You have two methods in the class after you add this method:

```cs
```csharp
[Theory]
[InlineData(0, "Ting", "Does not appear in the string.")]
[InlineData(1, "Ting", "Ting appears once.")]
Expand Down
14 changes: 7 additions & 7 deletions docs/csharp/delegate-class.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ definition.
Let's continue to use the List.Sort() method as our example. The first
step is to create a type for the comparison delegate:

```cs
```csharp
// From the .NET Core library

// Define the delegate type:
Expand Down Expand Up @@ -69,7 +69,7 @@ After defining the delegate, you can create an instance of that type.
Like all variables in C#, you cannot declare delegate instances directly
in a namespace, or in the global namespace.

```cs
```csharp
// inside a class definition:

// Declare an instance of that type:
Expand All @@ -88,7 +88,7 @@ You invoke the methods that are in the invocation list of a delegate by calling
that delegate. Inside the `Sort()` method, the code will call the
comparison method to determine which order to place objects:

```cs
```csharp
int result = comparator(left, right);
```

Expand All @@ -115,7 +115,7 @@ adds the method to the invocation list of that delegate object.
Suppose you wanted to sort a list of strings by their length. Your
comparison function might be the following:

```cs
```csharp
private static int CompareLength(string left, string right)
{
return left.Length.CompareTo(right.Length);
Expand All @@ -131,7 +131,7 @@ the delegate object, and can access it through that delegate.
You create that relationship by passing that method to the
`List.Sort()` method:

```cs
```csharp
phrases.Sort(CompareLength);
```

Expand All @@ -143,7 +143,7 @@ an invocation target.
You could also have been explicit by declaring a variable of type
'Comparison<string>` and doing an assignment:

```cs
```csharp
Comparison<string> comparer = CompareLength;
phrases.Sort(comparer);
```
Expand All @@ -152,7 +152,7 @@ In uses where the method being used as a delegate target is a small method,
it's common to use [Lambda Expression](lambda-expressions.md) syntax
to perform the assignment:

```cs
```csharp
Comparison<string> comparer = (left, right) => left.Length.CompareTo(right.Length);
phrases.Sort(comparer);
```
Expand Down
24 changes: 12 additions & 12 deletions docs/csharp/delegates-patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ One excellent example for this kind of design is LINQ. The LINQ
Query Expression Pattern relies on delegates for all of its
features. Consider this simple example:

```cs
```csharp
var smallNumbers = numbers.Where(n => n < 10);
```

Expand All @@ -34,7 +34,7 @@ implementation of the delegate for this specific purpose.

The prototype for the Where method is:

```cs
```csharp
public static IEnumerable<TSource> Where<in TSource> (IEnumerable<TSource> source, Func<TSource, bool> predicate);
```

Expand Down Expand Up @@ -85,7 +85,7 @@ Let's start small: the initial implementation will accept new messages,
and write them using any attached delegate. You can start with one delegate
that writes messages to the console.

```cs
```csharp
public static class Logger
{
public static Action<string> WriteMessage;
Expand All @@ -101,7 +101,7 @@ The static class above is the simplest thing that can work. We need to
write the single implementation for the method that writes messages
to the console:

```cs
```csharp
public static void LogToConsole(string message)
{
Console.Error.WriteLine(message);
Expand All @@ -111,7 +111,7 @@ public static void LogToConsole(string message)
Finally, you need to hook up the delegate by attaching it to
the WriteMessage delegate declared in the logger:

```cs
```csharp
Logger.WriteMessage += LogToConsole;
```

Expand All @@ -137,7 +137,7 @@ creating other logging mechanisms.
Next, let's add a few arguments to the `LogMessage()` method so that
your log class creates more structured messages:

```cs
```csharp
// Logger implementation two
public enum Severity
{
Expand All @@ -164,7 +164,7 @@ public static class Logger
Next, let's make use of that `Severity` argument to filter the messages
that are sent to the log's output.

```cs
```csharp
public static class Logger
{
public static Action<string> WriteMessage;
Expand Down Expand Up @@ -205,7 +205,7 @@ each message is generated.

Here is that file based logger:

```cs
```csharp
public class FileLogger
{
private readonly string logPath;
Expand Down Expand Up @@ -238,22 +238,22 @@ public class FileLogger
Once you've created this class, you can instantiate it and it attaches
its LogMessage method to the Logger component:

```cs
```csharp
var file = new FileLogger("log.txt");
```

These two are not mutually exclusive. You could attach both log
methods and generate messages to the console and a file:

```cs
```csharp
var fileOutput = new FileLogger("log.txt");
Logger.WriteMessage += LogToConsole;
```

Later, even in the same application, you can remove one of the
delegates without any other issues to the system:

```cs
```csharp
Logger.WriteMessage -= LogToConsole;
```

Expand Down Expand Up @@ -295,7 +295,7 @@ You may prefer a design that silently continues when no methods
have been attached. This is easy using the null conditional operator,
combined with the `Delegate.Invoke()` method:

```cs
```csharp
public static void LogMessage(string msg)
{
WriteMessage?.Invoke(msg);
Expand Down
8 changes: 4 additions & 4 deletions docs/csharp/delegates-strongly-typed.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ when you need new method declarations.

The first of these types is the @System.Action type, and several variations:

```cs
```csharp
public delegate void Action();
public delegate void Action<in T>(T arg);
public delegate void Action<in T1, in T2>(T1 arg1, T2 arg2);
Expand All @@ -56,7 +56,7 @@ Use one of the `Action` types for any delegate type that has a void return type.
The framework also includes several generic delegate types that you can use for
delegate types that return values:

```cs
```csharp
public delegate TResult Func<out TResult>();
public delegate TResult Func<in T1, out TResult>(T1 arg);
public delegate TResult Func<in T1, in T2, out TResult>(T1 arg1, T2 arg2);
Expand All @@ -77,14 +77,14 @@ There's also a specialized
@System.Predicate%601
type for a delegate that returns a test on a single value:

```cs
```csharp
public delegate bool Predicate<in T>(T obj);
```

You may notice that for any `Predicate` type, a structurally equivalent `Func`
type exists For example:

```cs
```csharp
Func<string, bool> TestForString;
Predicate<string> AnotherTestForString;
```
Expand Down
Loading