Skip to content

Commit

Permalink
added conditional processing for C# language features based on langua…
Browse files Browse the repository at this point in the history
…geVersion / framework
  • Loading branch information
vlada-shubina committed Jul 15, 2021
1 parent 6875aa5 commit 80c10e6
Show file tree
Hide file tree
Showing 7 changed files with 367 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,36 @@
"description": "If specified, skips the automatic restore of the project on create.",
"defaultValue": "false",
"displayName": "Skip restore"
},
"csharp10orLater": {
"type": "generated",
"generator": "regexMatch",
"datatype": "bool",
"parameters": {
"pattern": "^(|10\\.0|10|preview|latest|default|latestMajor)$",
"source": "langVersion"
}
},
"csharp8orLater": {
"type": "generated",
"generator": "regexMatch",
"datatype": "bool",
"parameters": {
"pattern": "^(|8|8\\.0|9|9\\.0|10\\.0|10|preview|latest|default|latestMajor)$",
"source": "langVersion"
}
},
"csharpFeature_ImplicitUsings": {
"type": "computed",
"value": "Framework != \"netstandard2.0\" && Framework != \"netstandard2.1\" && csharp10orLater == \"true\""
},
"csharpFeature_FileScopedNamespaces": {
"type": "computed",
"value": "Framework != \"netstandard2.0\" && Framework != \"netstandard2.1\" && csharp10orLater == \"true\""
},
"csharpFeature_Nullable": {
"type": "computed",
"value": "(Framework != \"netstandard2.0\" || Framework == \"netstandard2.0\" && langVersion != \"\") && csharp8orLater == \"true\""
}
},
"primaryOutputs": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
namespace Company.ClassLibrary1
#if (!csharpFeature_ImplicitUsings)
using System;

#endif
namespace Company.ClassLibrary1
{
public class Class1
{

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<TargetFramework Condition="'$(TargetFrameworkOverride)' != ''">TargetFrameworkOverride</TargetFramework>
<RootNamespace Condition="'$(name)' != '$(name{-VALUE-FORMS-}safe_namespace)'">Company.ClassLibrary1</RootNamespace>
<LangVersion Condition="'$(langVersion)' != ''">$(ProjectLanguageVersion)</LangVersion>
<Nullable Condition="('$(Framework)' != 'netstandard2.0')">enable</Nullable>
<DisableImplicitNamespaceImports Condition="'$(csharpFeature_ImplicitUsings)' != 'true'">true</DisableImplicitNamespaceImports>
<Nullable Condition="'$(csharpFeature_Nullable)' == 'true'">enable</Nullable>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,45 @@
"description": "If specified, skips the automatic restore of the project on create.",
"defaultValue": "false",
"displayName": "Skip restore"
},
"csharp10orLater": {
"type": "generated",
"generator": "regexMatch",
"datatype": "bool",
"parameters": {
"pattern": "^(|10\\.0|10|preview|latest|default|latestMajor)$",
"source": "langVersion"
}
},
"csharp9orLater": {
"type": "generated",
"generator": "regexMatch",
"datatype": "bool",
"parameters": {
"pattern": "^(|9|9\\.0|10\\.0|10|preview|latest|default|latestMajor)$",
"source": "langVersion"
}
},
"csharp8orLater": {
"type": "generated",
"generator": "regexMatch",
"datatype": "bool",
"parameters": {
"pattern": "^(|8|8\\.0|9|9\\.0|10\\.0|10|preview|latest|default|latestMajor)$",
"source": "langVersion"
}
},
"csharpFeature_ImplicitUsings": {
"type": "computed",
"value": "csharp10orLater == \"true\""
},
"csharpFeature_Nullable": {
"type": "computed",
"value": "csharp8orLater == \"true\""
},
"csharpFeature_TopLevelProgram": {
"type": "computed",
"value": "csharp9orLater == \"true\""
}
},
"primaryOutputs": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
<OutputType>Exe</OutputType>
<TargetFramework Condition="'$(TargetFrameworkOverride)' == ''">net6.0</TargetFramework>
<TargetFramework Condition="'$(TargetFrameworkOverride)' != ''">TargetFrameworkOverride</TargetFramework>
<RootNamespace Condition="'$(name)' != '$(name{-VALUE-FORMS-}safe_namespace)'">Company.ConsoleApplication1</RootNamespace>
<LangVersion Condition="'$(langVersion)' != ''">$(ProjectLanguageVersion)</LangVersion>
<Nullable>enable</Nullable>
<DisableImplicitNamespaceImports Condition="'$(csharpFeature_ImplicitUsings)' != 'true'">true</DisableImplicitNamespaceImports>
<Nullable Condition="'$(csharpFeature_Nullable)' == 'true'">enable</Nullable>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,2 +1,21 @@
Console.WriteLine("Hello, World!");
#if (csharpFeature_TopLevelProgram)
// See https://aka.ms/new-console-template for more information
#endif
#if (!csharpFeature_ImplicitUsings)
using System;

#endif
#if (csharpFeature_TopLevelProgram)
Console.WriteLine("Hello, World!");
#else
namespace Company.ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
}
}
}
#endif
Loading

0 comments on commit 80c10e6

Please sign in to comment.