Skip to content

Commit 9d5989c

Browse files
committed
markdown fixes
1 parent 0298b86 commit 9d5989c

File tree

5 files changed

+118
-121
lines changed

5 files changed

+118
-121
lines changed

proposals/caller-argument-expression.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Allow developers to capture the expressions passed to a method, to enable better
1515

1616
When an assertion or argument validation fails, the developer wants to know as much as possible about where and why it failed. However, today's diagnostic APIs do not fully facilitate this. Consider the following method:
1717

18-
```cs
18+
```csharp
1919
T Single<T>(this T[] array)
2020
{
2121
Debug.Assert(array != null);
@@ -31,7 +31,7 @@ This is also the reason testing frameworks have to provide a variety of assert m
3131

3232
While the situation is a bit better for argument validation because the names of invalid arguments are shown to the developer, the developer must pass these names to exceptions manually. If the above example were rewritten to use traditional argument validation instead of `Debug.Assert`, it would look like
3333

34-
```cs
34+
```csharp
3535
T Single<T>(this T[] array)
3636
{
3737
if (array == null)
@@ -55,7 +55,7 @@ Notice that `nameof(array)` must be passed to each exception, although it's alre
5555

5656
In the above examples, including the string `"array != null"` or `"array.Length == 1"` in the assert message would help the developer determine what failed. Enter `CallerArgumentExpression`: it's an attribute the framework can use to obtain the string associated with a particular method argument. We would add it to `Debug.Assert` like so
5757

58-
```cs
58+
```csharp
5959
public static class Debug
6060
{
6161
public static void Assert(bool condition, [CallerArgumentExpression("condition")] string message = null);
@@ -64,7 +64,7 @@ public static class Debug
6464

6565
The source code in the above example would stay the same. However, the code the compiler actually emits would correspond to
6666

67-
```cs
67+
```csharp
6868
T Single<T>(this T[] array)
6969
{
7070
Debug.Assert(array != null, "array != null");
@@ -78,7 +78,7 @@ The compiler specially recognizes the attribute on `Debug.Assert`. It passes the
7878

7979
For argument validation, the attribute cannot be used directly, but can be made use of through a helper class:
8080

81-
```cs
81+
```csharp
8282
public static class Verify
8383
{
8484
public static void Argument(bool condition, string message, [CallerArgumentExpression("condition")] string conditionExpression = null)
@@ -137,7 +137,7 @@ A proposal to add such a helper class to the framework is underway at https://gi
137137

138138
The `this` parameter in an extension method may be referenced by `CallerArgumentExpression`. For example:
139139

140-
```cs
140+
```csharp
141141
public static void ShouldBe<T>(this T @this, T expected, [CallerArgumentExpression("this")] string thisExpression = null) {}
142142

143143
contestant.Points.ShouldBe(1337); // thisExpression: "contestant.Points"
@@ -167,7 +167,7 @@ There should always be an expression corresponding to the `this` parameter. Even
167167
- If being able to see source code at call sites for methods that use this attribute proves to be a problem, we can make the attribute's effects opt-in. Developers will enable it through an assembly-wide `[assembly: EnableCallerArgumentExpression]` attribute they put in `AssemblyInfo.cs`.
168168
- In the case the attribute's effects are not enabled, calling methods marked with the attribute would not be an error, to allow existing methods to use the attribute and maintain source compatibility. However, the attribute would be ignored and the method would be called with whatever default value was provided.
169169

170-
```cs
170+
```csharp
171171
// Assembly1
172172
173173
void Foo(string bar); // V1
@@ -189,7 +189,7 @@ Foo(a, "provided"); // V2, V3: Compiles to Foo(a, "provided")
189189

190190
- To prevent the [binary compatibility problem][drawbacks] from occurring every time we want to add new caller info to `Debug.Assert`, an alternative solution would be to add a `CallerInfo` struct to the framework that contains all the necessary information about the caller.
191191

192-
```cs
192+
```csharp
193193
struct CallerInfo
194194
{
195195
public string MemberName { get; set; }

proposals/covariant-returns.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ The implementation of this would be for the compiler to emit the overriding meth
5050

5151
We could relax the language rules slightly to allow, in source,
5252

53-
``` c#
53+
```csharp
5454
abstract class Cloneable
5555
{
5656
public abstract Cloneable Clone();
@@ -77,5 +77,4 @@ class Digit : Cloneable
7777

7878
## Design meetings
7979

80-
None yet. There has been some discussion at https://github.com/dotnet/roslyn/issues/357
81-
80+
None yet. There has been some discussion at <https://github.com/dotnet/roslyn/issues/357>.

proposals/declaration-expressions.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ Support declaration assignments as expressions.
66
[motivation]: #motivation
77

88
Allow initialization at the point of declaration in more cases, simplifying code, and allowing `var` to be used.
9-
```C#
9+
10+
```csharp
1011
SpecialType ReferenceType =>
1112
(var st = _type.SpecialType).IsValueType() ? SpecialType.None : st;
1213
```
1314

1415
Allow declarations for `ref` arguments, similar to `out var`.
15-
```C#
16+
17+
```csharp
1618
Convert(source, destination, ref List<Diagnostic> diagnostics = null);
1719
```
1820

@@ -48,7 +50,8 @@ the expression is a copy.
4850
The declaration assignment expression may declare a `ref` local.
4951
There is an ambiguity when `ref` is used for a declaration expression in a `ref` argument.
5052
The local variable initializer determines whether the declaration is a `ref` local.
51-
```C#
53+
54+
```csharp
5255
F(ref int x = IntFunc()); // int x;
5356
F(ref int y = RefIntFunc()); // ref int y;
5457
```

0 commit comments

Comments
 (0)