Update samples for C# 9 (#5579)

* Update projects to .NET 5.0

* Update to top-level projects

* Add typing
This commit is contained in:
Rich Lander 2020-11-11 18:57:08 -08:00 committed by GitHub
parent a01a315b49
commit cbda8e6974
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 50 deletions

View file

@ -5,34 +5,26 @@ using System.Runtime.InteropServices;
using static System.Console;
using static System.IO.File;
namespace RuntimeEnvironment
{
class Program
{
static void Main(string[] args)
{
WriteLine("**.NET information");
WriteLine($"{nameof(Environment.Version)}: {Environment.Version}");
WriteLine($"{nameof(RuntimeInformation.FrameworkDescription)}: {RuntimeInformation.FrameworkDescription}");
var assemblyInformation = ((AssemblyInformationalVersionAttribute[])typeof(object).Assembly.GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false))[0];
var informationalVersionSplit = assemblyInformation.InformationalVersion.Split('+');
WriteLine($"Libraries version: {informationalVersionSplit[0]}");
WriteLine($"Libraries hash: {informationalVersionSplit[1]}");
WriteLine();
WriteLine("**Environment information");
WriteLine($"{nameof(RuntimeInformation.OSDescription)}: {RuntimeInformation.OSDescription}");
WriteLine($"{nameof(Environment.OSVersion)}: {Environment.OSVersion}");
WriteLine($"{nameof(RuntimeInformation.OSArchitecture)}: {RuntimeInformation.OSArchitecture}");
WriteLine($"{nameof(Environment.ProcessorCount)}: {Environment.ProcessorCount}");
WriteLine();
AssemblyInformationalVersionAttribute assemblyInformation = ((AssemblyInformationalVersionAttribute[])typeof(object).Assembly.GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false))[0];
string[] informationalVersionSplit = assemblyInformation.InformationalVersion.Split('+');
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && Directory.Exists("/sys/fs/cgroup"))
{
WriteLine("**CGroup info**");
WriteLine($"cfs_quota_us: {ReadAllLines("/sys/fs/cgroup/cpu/cpu.cfs_quota_us")[0]}");
WriteLine($"memory.limit_in_bytes: {ReadAllLines("/sys/fs/cgroup/memory/memory.limit_in_bytes")[0]}");
WriteLine($"memory.usage_in_bytes: {ReadAllLines("/sys/fs/cgroup/memory/memory.usage_in_bytes")[0]}");
}
}
}
WriteLine("**.NET information");
WriteLine($"{nameof(Environment.Version)}: {Environment.Version}");
WriteLine($"{nameof(RuntimeInformation.FrameworkDescription)}: {RuntimeInformation.FrameworkDescription}");
WriteLine($"Libraries version: {informationalVersionSplit[0]}");
WriteLine($"Libraries hash: {informationalVersionSplit[1]}");
WriteLine();
WriteLine("**Environment information");
WriteLine($"{nameof(RuntimeInformation.OSDescription)}: {RuntimeInformation.OSDescription}");
WriteLine($"{nameof(Environment.OSVersion)}: {Environment.OSVersion}");
WriteLine($"{nameof(RuntimeInformation.OSArchitecture)}: {RuntimeInformation.OSArchitecture}");
WriteLine($"{nameof(Environment.ProcessorCount)}: {Environment.ProcessorCount}");
WriteLine();
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && Directory.Exists("/sys/fs/cgroup"))
{
WriteLine("**CGroup info");
WriteLine($"cfs_quota_us: {ReadAllLines("/sys/fs/cgroup/cpu/cpu.cfs_quota_us")[0]}");
WriteLine($"memory.limit_in_bytes: {ReadAllLines("/sys/fs/cgroup/memory/memory.limit_in_bytes")[0]}");
WriteLine($"memory.usage_in_bytes: {ReadAllLines("/sys/fs/cgroup/memory/memory.usage_in_bytes")[0]}");
}

View file

@ -4,6 +4,8 @@
<Description>Displays .NET version and environment information.</Description>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>9</LangVersion>
<Nullable>enable</Nullable>
<RollForward>LatestMajor</RollForward>
<VersionPrefix>1.0.2</VersionPrefix>
<PackageProjectUrl>https://github.com/dotnet/core/blob/master/samples/dotnet-runtimeinfo/README.md</PackageProjectUrl>

View file

@ -1,27 +1,22 @@
using System;
public static class Program
string message = "Welcome to dotnetsay, a .NET tool!";
if (Console.IsInputRedirected)
{
public static void Main(string[] args)
{
string message = "Welcome to using a .NET Core global tool!";
message = Console.In.ReadToEnd();
}
else if (args.Length > 0)
{
message = string.Join(" ", args);
}
if (Console.IsInputRedirected)
{
message = Console.In.ReadToEnd();
}
else if (args.Length > 0)
{
message = string.Join(" ", args);
}
Console.WriteLine(GetBot());
Console.WriteLine(GetBot(message));
}
public static string GetBot(string message)
{
string bot = $"\n {message}";
bot += @"
string GetBot()
{
return @$"
{message}
__________________
\
\
@ -60,6 +55,4 @@ public static class Program
......... ..............
.....
";
return bot;
}
}

View file

@ -4,6 +4,8 @@
<Description>A simple .NET Core tool called "dotnetsay".</Description>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<LangVersion>9</LangVersion>
<Nullable>Enable</Nullable>
<RollForward>LatestMajor</RollForward>
<VersionPrefix>2.1.7</VersionPrefix>
<PackageProjectUrl>https://github.com/dotnet/core/blob/master/samples/dotnetsay/README.md</PackageProjectUrl>