@@ -679,7 +679,7 @@ Nested types can be declared in multiple parts by using the `partial` modifier.
679
679
680
680
> * Example* : The following partial class is implemented in two parts, which reside in different compilation units. The first part is machine generated by a database-mapping tool while the second part is manually authored:
681
681
>
682
- > <!-- RequiresSeparateFiles$ Example: {template:"standalone-lib-without-using", name:"PartialDeclarations1", replaceEllipsis:true, expectedWarnings:["CS0169","CS0169","CS0169","CS0649"], additionalFiles:["Order.cs"]} -->
682
+ > <!-- Example: {template:"standalone-lib-without-using", name:"PartialDeclarations1", replaceEllipsis:true, expectedWarnings:["CS0169","CS0169","CS0169","CS0649"], additionalFiles:["Order.cs"]} -->
683
683
> ``` csharp
684
684
> public partial class Customer
685
685
> {
@@ -694,6 +694,7 @@ Nested types can be declared in multiple parts by using the `partial` modifier.
694
694
> }
695
695
> }
696
696
>
697
+ > // File: Customer2.cs
697
698
> public partial class Customer
698
699
> {
699
700
> public void SubmitOrder (Order orderSubmitted ) => orders .Add (orderSubmitted );
@@ -1596,7 +1597,7 @@ Constants and readonly fields have different binary versioning semantics. When a
1596
1597
1597
1598
> *Example *: Consider an application that consists of two separate programs :
1598
1599
>
1599
- > < ! -- RequiresSeparateFiles $Example : {template : " standalone-lib-without-using" , name : " VersioningOfConstantsAndStaticReadonlyFields1" } -- >
1600
+ > < ! -- RequiresSeparateProjects $Example : {template : " standalone-lib-without-using" , name : " VersioningOfConstantsAndStaticReadonlyFields1" } -- >
1600
1601
> ```csharp
1601
1602
> namespace Program1
1602
1603
> {
@@ -1609,7 +1610,7 @@ Constants and readonly fields have different binary versioning semantics. When a
1609
1610
>
1610
1611
> and
1611
1612
>
1612
- > < ! -- RequiresSeparateFiles $Example : {template : " standalone-console" , name : " VersioningOfConstantsAndStaticReadonlyFields2" , expectedOutput : [" x" , " x" , " x" ], expectedErrors : [" x" ," x" ], expectedWarnings : [" x" ," x" ]} -- >
1613
+ > < ! -- RequiresSeparateProjects $Example : {template : " standalone-console" , name : " VersioningOfConstantsAndStaticReadonlyFields2" , expectedOutput : [" x" , " x" , " x" ], expectedErrors : [" x" ," x" ], expectedWarnings : [" x" ," x" ]} -- >
1613
1614
> ```csharp
1614
1615
> namespace Program2
1615
1616
> {
@@ -2793,20 +2794,17 @@ An implementing partial method declaration can appear in the same part as the co
2793
2794
2794
2795
Only a defining partial method participates in overload resolution . Thus , whether or not an implementing declaration is given , invocation expressions may resolve to invocations of the partial method . Because a partial method always returns `void `, such invocation expressions will always be expression statements . Furthermore , because a partial method is implicitly `private `, such statements will always occur within one of the parts of the type declaration within which the partial method is declared .
2795
2796
2796
- > *Note *: The definition of matching defining and implementing partial method declarations does not require parameter names to match . This can produce * surprising * , albeit * well defined * , behaviour when named arguments ([§11.6.2.1 ](expressions .md #11621 - general )) are used . For example , given the defining partial method declaration for `M `:
2797
+ > *Note *: The definition of matching defining and implementing partial method declarations does not require parameter names to match . This can produce * surprising * , albeit * well defined * , behaviour when named arguments ([§11.6.2.1 ](expressions .md #11621 - general )) are used . For example , given the defining partial method declaration for `M ` in one file , and the implementing partial method declaration in another file :
2797
2798
>
2798
- > < ! -- RequiresSeparateFiles $ Example : {template : " standalone-lib-without-using" , name : " PartialMethods1" } -- >
2799
+ > < ! -- Example : {template : " standalone-lib-without-using" , name : " PartialMethods1" , " expectedErrors " : [ " CS1739 " ], " expectedWarnings " : [ " CS8826 " ] } -- >
2799
2800
> ```csharp
2801
+ > // File P1.cs:
2800
2802
> partial class P
2801
2803
> {
2802
2804
> static partial void M (int x );
2803
2805
> }
2804
- > ```
2805
- >
2806
- > Then the implementing partial method declaration and invocation in other file :
2807
2806
>
2808
- > < ! -- RequiresSeparateFiles $Example : {template : " standalone-lib-without-using" , name : " PartialMethods2" , expectedErrors : [" x" ," x" ], expectedWarnings : [" x" ," x" ]} -- >
2809
- > ```csharp
2807
+ > // File P2.cs:
2810
2808
> partial class P
2811
2809
> {
2812
2810
> static void Caller () => M (y : 0 );
@@ -2841,6 +2839,7 @@ If a defining declaration but not an implementing declaration is given for a par
2841
2839
Partial methods are useful for allowing one part of a type declaration to customize the behavior of another part , e .g ., one that is generated by a tool . Consider the following partial class declaration :
2842
2840
2843
2841
< ! -- Example : {template : " standalone-lib-without-using" , name : " PartialMethods3" } -- >
2842
+ < ! -- Maintenance Note : This code exists in additional - files as " Customer.cs" to be used in an example below . As such , certain changes to this example should be reflected in that file , in which case , * all * examples using that file should be tested . -- >
2844
2843
```csharp
2845
2844
partial class Customer
2846
2845
{
@@ -2880,7 +2879,7 @@ class Customer
2880
2879
2881
2880
Assume that another part is given , however , which provides implementing declarations of the partial methods :
2882
2881
2883
- < ! -- RequiresSeparateFiles $ Example : {template : " standalone-lib" , name : " PartialMethods5" , expectedErrors : [" x " , " x " ], expectedWarnings : [ " x " , " x " ]} -- >
2882
+ < ! -- Example : {template : " standalone-lib" , name : " PartialMethods5" , additionalFiles : [" Customer.cs " ]} -- >
2884
2883
```csharp
2885
2884
partial class Customer
2886
2885
{
@@ -2926,6 +2925,7 @@ When the first parameter of a method includes the `this` modifier, that method i
2926
2925
> * Example * : The following is an example of a static class that declares two extension methods :
2927
2926
>
2928
2927
> < ! -- Example : {template : " standalone-lib" , name : " ExtensionMethods1" } -- >
2928
+ > < ! -- Maintenance Note : This code exists in additional - files as " Extensions.cs" to be used in the examples below . As such , certain changes to this example should be reflected in that file , in which case , * all * examples using that file should be tested . -- >
2929
2929
> ```csharp
2930
2930
> public static class Extensions
2931
2931
> {
@@ -2950,7 +2950,7 @@ An extension method is a regular static method. In addition, where its enclosing
2950
2950
2951
2951
> * Example * : The following program uses the extension methods declared above :
2952
2952
>
2953
- > < ! -- RequiresSeparateFiles $ Example : {template : " standalone-console" , name : " ExtensionMethods2" , expectedOutput : [" x " , " x " , " x " ], expectedErrors : [" x " , " x " ], expectedWarnings : [ " x " , " x " ]} -- >
2953
+ > < ! -- Example : {template : " standalone-console" , name : " ExtensionMethods2" , additionalFiles : [" Extensions.cs " ], expectedOutput : [" 22 " , " 333 " ]} -- >
2954
2954
> ```csharp
2955
2955
> static class Program
2956
2956
> {
@@ -2967,7 +2967,7 @@ An extension method is a regular static method. In addition, where its enclosing
2967
2967
>
2968
2968
> The `Slice ` method is available on the `string []`, and the `ToInt32 ` method is available on `string `, because they have been declared as extension methods . The meaning of the program is the same as the following , using ordinary static method calls :
2969
2969
>
2970
- > < ! -- RequiresSeparateFiles $ Example : {template : " standalone-console" , name : " ExtensionMethods3" , expectedOutput : [" x " , " x " , " x " ], expectedErrors : [" x " , " x " ], expectedWarnings : [ " x " , " x " ]} -- >
2970
+ > < ! -- Example : {template : " standalone-console" , name : " ExtensionMethods3" , additionalFiles : [" Extensions.cs " ], expectedOutput : [" 22 " , " 333 " ]} -- >
2971
2971
> ```csharp
2972
2972
> static class Program
2973
2973
> {
0 commit comments