From b9f621b561e96bdc3b4a7afc6895d7df06dd8031 Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Thu, 21 Nov 2024 11:12:07 +0000 Subject: [PATCH 1/4] Remove accidentally-nested template directory --- .../standalone-lib/standalone-lib-without-using/Library.cs | 1 - 1 file changed, 1 deletion(-) delete mode 100644 tools/example-templates/standalone-lib/standalone-lib-without-using/Library.cs diff --git a/tools/example-templates/standalone-lib/standalone-lib-without-using/Library.cs b/tools/example-templates/standalone-lib/standalone-lib-without-using/Library.cs deleted file mode 100644 index bb8d3f010..000000000 --- a/tools/example-templates/standalone-lib/standalone-lib-without-using/Library.cs +++ /dev/null @@ -1 +0,0 @@ -$example-code From a567d41c3cd0d73be3d5001940e2f9e358630886 Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Thu, 21 Nov 2024 11:13:24 +0000 Subject: [PATCH 2/4] Use LangVersion=8 where feasible in testing This should allow us to avoid accidentally using C# 9+ features, at least in most cases. The standalone-console and standalone-console-without-using templates are unchanged, as many examples using them expect to use top-level statements. (Once we've got as far as C# 10, we should be able to use LangVersion for all projects.) --- standard/attributes.md | 7 +++++-- standard/conversions.md | 2 +- standard/statements.md | 2 +- tools/example-templates/additional-files/Attr1Attribute.cs | 2 ++ tools/example-templates/additional-files/Attr2Attribute.cs | 3 ++- tools/example-templates/additional-files/Attr3Attribute.cs | 2 ++ tools/example-templates/additional-files/Extensions.cs | 2 ++ .../example-templates/additional-files/SimpleAttribute.cs | 2 ++ .../code-in-class-lib-without-using/Project.csproj | 2 +- tools/example-templates/code-in-class-lib/Project.csproj | 2 +- .../code-in-main-without-using/Project.csproj | 2 +- tools/example-templates/code-in-main/Project.csproj | 2 +- .../example-templates/code-in-partial-class/Project.csproj | 2 +- tools/example-templates/extern-lib/ExampleProject.csproj | 1 + tools/example-templates/extern-lib/ExternN2.csproj | 1 + tools/example-templates/extern-lib/ExternR1.csproj | 1 + tools/example-templates/extern-lib/ExternX.csproj | 1 + tools/example-templates/extern-lib/ExternY.csproj | 1 + tools/example-templates/standalone-lib/Project.csproj | 2 +- 19 files changed, 28 insertions(+), 11 deletions(-) diff --git a/standard/attributes.md b/standard/attributes.md index 21d681e30..2a60a3a4a 100644 --- a/standard/attributes.md +++ b/standard/attributes.md @@ -20,7 +20,7 @@ A generic class declaration shall not use `System.Attribute` as a direct or indi > *Example*: > -> +> > ```csharp > public class B : Attribute {} > public class C : B {} // Error – generic cannot be an attribute @@ -617,6 +617,7 @@ It is important to understand that the inclusion or exclusion of a call to a con > > ```csharp > // File Class1.cs: +> using System; > using System.Diagnostics; > class Class1 > { @@ -659,6 +660,7 @@ The use of conditional methods in an inheritance chain can be confusing. Calls m > > ```csharp > // File Class1.cs +> using System; > using System.Diagnostics; > class Class1 > { @@ -718,6 +720,7 @@ It is important to note that the inclusion or exclusion of an attribute specific > > ```csharp > // File Test.cs: +> using System; > using System.Diagnostics; > [Conditional("DEBUG")] > public class TestAttribute : Attribute {} @@ -1009,7 +1012,7 @@ Specifies that a non-nullable return value may be null. > *Example*: Consider the following generic method: > -> +> > ```csharp > #nullable enable > public T? Find(IEnumerable sequence, Func predicate) { ... } diff --git a/standard/conversions.md b/standard/conversions.md index 3cb4557bf..0b2cf680b 100644 --- a/standard/conversions.md +++ b/standard/conversions.md @@ -21,7 +21,7 @@ Some conversions in the language are defined from expressions to types, others f > *Example*: > -> +> > ```csharp > enum Color { Red, Blue, Green } > diff --git a/standard/statements.md b/standard/statements.md index 245bb6d55..6d7ce6bb5 100644 --- a/standard/statements.md +++ b/standard/statements.md @@ -1960,7 +1960,7 @@ There are several restrictions on where a `yield` statement can appear, as descr > *Example*: The following example shows some valid and invalid uses of `yield` statements. > -> +> > ```csharp > delegate IEnumerable D(); > diff --git a/tools/example-templates/additional-files/Attr1Attribute.cs b/tools/example-templates/additional-files/Attr1Attribute.cs index 7dc9f8de3..0bafe99b0 100644 --- a/tools/example-templates/additional-files/Attr1Attribute.cs +++ b/tools/example-templates/additional-files/Attr1Attribute.cs @@ -1,3 +1,5 @@ +using System; + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] public class Attr1Attribute : Attribute { diff --git a/tools/example-templates/additional-files/Attr2Attribute.cs b/tools/example-templates/additional-files/Attr2Attribute.cs index f8e9893d6..564b7d7e0 100644 --- a/tools/example-templates/additional-files/Attr2Attribute.cs +++ b/tools/example-templates/additional-files/Attr2Attribute.cs @@ -1,3 +1,5 @@ +using System; + [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] public class Attr2Attribute : Attribute { @@ -11,4 +13,3 @@ public Attr2Attribute(string name) // get { return name; } // } } - diff --git a/tools/example-templates/additional-files/Attr3Attribute.cs b/tools/example-templates/additional-files/Attr3Attribute.cs index 94a078814..55cf6c47b 100644 --- a/tools/example-templates/additional-files/Attr3Attribute.cs +++ b/tools/example-templates/additional-files/Attr3Attribute.cs @@ -1,3 +1,5 @@ +using System; + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] public class Attr3Attribute : Attribute { diff --git a/tools/example-templates/additional-files/Extensions.cs b/tools/example-templates/additional-files/Extensions.cs index 6535f1e3b..0ff912aed 100644 --- a/tools/example-templates/additional-files/Extensions.cs +++ b/tools/example-templates/additional-files/Extensions.cs @@ -1,3 +1,5 @@ +using System; + public static class Extensions { public static int ToInt32(this string s) => Int32.Parse(s); diff --git a/tools/example-templates/additional-files/SimpleAttribute.cs b/tools/example-templates/additional-files/SimpleAttribute.cs index 3c0ea5d99..fba4e008d 100644 --- a/tools/example-templates/additional-files/SimpleAttribute.cs +++ b/tools/example-templates/additional-files/SimpleAttribute.cs @@ -1,3 +1,5 @@ +using System; + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface)] public class SimpleAttribute : Attribute { diff --git a/tools/example-templates/code-in-class-lib-without-using/Project.csproj b/tools/example-templates/code-in-class-lib-without-using/Project.csproj index 19e60edae..722c71426 100644 --- a/tools/example-templates/code-in-class-lib-without-using/Project.csproj +++ b/tools/example-templates/code-in-class-lib-without-using/Project.csproj @@ -2,10 +2,10 @@ net6.0 - enable $example-name true annotations + 8 diff --git a/tools/example-templates/code-in-class-lib/Project.csproj b/tools/example-templates/code-in-class-lib/Project.csproj index 19e60edae..722c71426 100644 --- a/tools/example-templates/code-in-class-lib/Project.csproj +++ b/tools/example-templates/code-in-class-lib/Project.csproj @@ -2,10 +2,10 @@ net6.0 - enable $example-name true annotations + 8 diff --git a/tools/example-templates/code-in-main-without-using/Project.csproj b/tools/example-templates/code-in-main-without-using/Project.csproj index b6e934c80..3b12870e9 100644 --- a/tools/example-templates/code-in-main-without-using/Project.csproj +++ b/tools/example-templates/code-in-main-without-using/Project.csproj @@ -3,10 +3,10 @@ Exe net6.0 - enable annotations $example-name true + 8 diff --git a/tools/example-templates/code-in-main/Project.csproj b/tools/example-templates/code-in-main/Project.csproj index b6e934c80..3b12870e9 100644 --- a/tools/example-templates/code-in-main/Project.csproj +++ b/tools/example-templates/code-in-main/Project.csproj @@ -3,10 +3,10 @@ Exe net6.0 - enable annotations $example-name true + 8 diff --git a/tools/example-templates/code-in-partial-class/Project.csproj b/tools/example-templates/code-in-partial-class/Project.csproj index f329dbdd9..a11586be9 100644 --- a/tools/example-templates/code-in-partial-class/Project.csproj +++ b/tools/example-templates/code-in-partial-class/Project.csproj @@ -3,10 +3,10 @@ Exe net6.0 - enable $example-name true annotations + 8 diff --git a/tools/example-templates/extern-lib/ExampleProject.csproj b/tools/example-templates/extern-lib/ExampleProject.csproj index cc9bba375..eb01f5963 100644 --- a/tools/example-templates/extern-lib/ExampleProject.csproj +++ b/tools/example-templates/extern-lib/ExampleProject.csproj @@ -5,6 +5,7 @@ false CS0169 annotations + 8 diff --git a/tools/example-templates/extern-lib/ExternN2.csproj b/tools/example-templates/extern-lib/ExternN2.csproj index c310d27de..4604791c8 100644 --- a/tools/example-templates/extern-lib/ExternN2.csproj +++ b/tools/example-templates/extern-lib/ExternN2.csproj @@ -4,6 +4,7 @@ net6.0 false annotations + 8 diff --git a/tools/example-templates/extern-lib/ExternR1.csproj b/tools/example-templates/extern-lib/ExternR1.csproj index 40ef94d27..f3524c968 100644 --- a/tools/example-templates/extern-lib/ExternR1.csproj +++ b/tools/example-templates/extern-lib/ExternR1.csproj @@ -4,6 +4,7 @@ net6.0 false annotations + 8 diff --git a/tools/example-templates/extern-lib/ExternX.csproj b/tools/example-templates/extern-lib/ExternX.csproj index 296993cc6..0e11dd005 100644 --- a/tools/example-templates/extern-lib/ExternX.csproj +++ b/tools/example-templates/extern-lib/ExternX.csproj @@ -4,6 +4,7 @@ net6.0 false annotations + 8 diff --git a/tools/example-templates/extern-lib/ExternY.csproj b/tools/example-templates/extern-lib/ExternY.csproj index e7ea5519d..351eb409b 100644 --- a/tools/example-templates/extern-lib/ExternY.csproj +++ b/tools/example-templates/extern-lib/ExternY.csproj @@ -4,6 +4,7 @@ net6.0 false annotations + 8 diff --git a/tools/example-templates/standalone-lib/Project.csproj b/tools/example-templates/standalone-lib/Project.csproj index 19e60edae..722c71426 100644 --- a/tools/example-templates/standalone-lib/Project.csproj +++ b/tools/example-templates/standalone-lib/Project.csproj @@ -2,10 +2,10 @@ net6.0 - enable $example-name true annotations + 8 From 95855d9dcc6d73c802124f61d676755b6f413fd0 Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Fri, 22 Nov 2024 15:48:04 +0000 Subject: [PATCH 3/4] Expect an error for an unconstrained use of T? Co-authored-by: Bill Wagner --- standard/attributes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/standard/attributes.md b/standard/attributes.md index 2a60a3a4a..2995471f1 100644 --- a/standard/attributes.md +++ b/standard/attributes.md @@ -1012,7 +1012,7 @@ Specifies that a non-nullable return value may be null. > *Example*: Consider the following generic method: > -> +> > ```csharp > #nullable enable > public T? Find(IEnumerable sequence, Func predicate) { ... } From bfdf15fda400032688dd65bedad15d5ca7c5ae31 Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Fri, 22 Nov 2024 16:36:29 +0000 Subject: [PATCH 4/4] Fix typo in example specification --- standard/attributes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/standard/attributes.md b/standard/attributes.md index 2995471f1..3d9d4737e 100644 --- a/standard/attributes.md +++ b/standard/attributes.md @@ -1012,7 +1012,7 @@ Specifies that a non-nullable return value may be null. > *Example*: Consider the following generic method: > -> +> > ```csharp > #nullable enable > public T? Find(IEnumerable sequence, Func predicate) { ... }