From b39c0d44d60b4fbcd54036d56e1d30e065d5accd Mon Sep 17 00:00:00 2001 From: devlights Date: Sun, 18 Apr 2021 12:24:06 +0000 Subject: [PATCH 01/38] Update .gitpod.yml --- .gitpod.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.gitpod.yml b/.gitpod.yml index 56bb9ee..03f4220 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -1 +1,6 @@ + image: gitpod/workspace-dotnet + +vscode: + extensions: + - muhammad-sammy.csharp \ No newline at end of file From bffba21e622878b5b8d309ba2d80257ea05c08d7 Mon Sep 17 00:00:00 2001 From: devlights Date: Sun, 18 Apr 2021 12:29:36 +0000 Subject: [PATCH 02/38] Fix warnings (SYSLIBxxx) --- TryCSharp.Samples/Advanced/RuntimeHelpersSamples02.cs | 9 +++++++++ TryCSharp.Samples/Advanced/RuntimeHelpersSamples03.cs | 9 +++++++++ .../Advanced/SerializationSurrogateSamples01.cs | 8 +++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/TryCSharp.Samples/Advanced/RuntimeHelpersSamples02.cs b/TryCSharp.Samples/Advanced/RuntimeHelpersSamples02.cs index b153123..ba754e4 100644 --- a/TryCSharp.Samples/Advanced/RuntimeHelpersSamples02.cs +++ b/TryCSharp.Samples/Advanced/RuntimeHelpersSamples02.cs @@ -7,6 +7,11 @@ namespace TryCSharp.Samples.Advanced /// /// RuntimeHelpersクラスのサンプルです。 /// + /// + /// 本サンプルは .NET 5.0 では使用できません。(CERが非推奨扱いになっているため) + /// 詳細については、以下に記載があります。 + /// - https://docs.microsoft.com/ja-jp/dotnet/core/compatibility/syslib-warnings/syslib0004 + /// [Sample] public class RuntimeHelpersSamples02 : IExecutable { @@ -27,7 +32,9 @@ public void Execute() // すると、try内の本処理よりも先にfinallyブロック内の静的コンストラクタが呼ばれる事になる。 // (事前コンパイルが行われると、アセンブリのロード、静的コンストラクタの実行などが発生するため) // +#if ENABLE_OLD_NET_FEATURE RuntimeHelpers.PrepareConstrainedRegions(); +#endif try { @@ -70,7 +77,9 @@ static SampleClass() // 尚、この属性はメソッドだけではなく、クラスやインターフェースにも付与できる。 // その場合、クラス全体に対して信頼性のコントラクトを付与したことになる。 // +#if ENABLE_OLD_NET_FEATURE [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] +#endif internal static void Print() { Output.WriteLine("SampleClass.Print()"); diff --git a/TryCSharp.Samples/Advanced/RuntimeHelpersSamples03.cs b/TryCSharp.Samples/Advanced/RuntimeHelpersSamples03.cs index 37606af..fd00857 100644 --- a/TryCSharp.Samples/Advanced/RuntimeHelpersSamples03.cs +++ b/TryCSharp.Samples/Advanced/RuntimeHelpersSamples03.cs @@ -7,6 +7,11 @@ namespace TryCSharp.Samples.Advanced /// /// RuntimeHelpersクラスのサンプルです。 /// + /// + /// 本サンプルは .NET 5.0 では使用できません。(CERが非推奨扱いになっているため) + /// 詳細については、以下に記載があります。 + /// - https://docs.microsoft.com/ja-jp/dotnet/core/compatibility/syslib-warnings/syslib0004 + /// [Sample] public class RuntimeHelpersSamples03 : IExecutable { @@ -27,7 +32,9 @@ public void Execute() // public delegate void CleanupCode(object userData, bool exceptionThrown) // // 前回のサンプルと同じ動作を行う. +#if ENABLE_OLD_NET_FEATURE RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(Calc, Cleanup, null); +#endif } private void Calc(object userData) @@ -58,7 +65,9 @@ static SampleClass() // ReliabilityContractAttributeおよびConsistencyやCerは // System.Runtime.ConstrainedExecution名前空間に存在する. // +#if ENABLE_OLD_NET_FEATURE [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] +#endif internal static void Print() { Output.WriteLine("SampleClass.Print()"); diff --git a/TryCSharp.Samples/Advanced/SerializationSurrogateSamples01.cs b/TryCSharp.Samples/Advanced/SerializationSurrogateSamples01.cs index 5af9afe..f540e7d 100644 --- a/TryCSharp.Samples/Advanced/SerializationSurrogateSamples01.cs +++ b/TryCSharp.Samples/Advanced/SerializationSurrogateSamples01.cs @@ -10,13 +10,18 @@ namespace TryCSharp.Samples.Advanced /// シリアライズに関するサンプルです。 /// /// - /// シリアル化サロゲートについて。 (ISerializationSurrogate) + /// シリアル化サロゲートについて。 (ISerializationSurrogate) + /// + /// 本サンプルは .NET 5.0 では使用できません。(BinaryFormatterが非推奨扱いになっているため) + /// 詳細については、以下に記載があります。 + /// - https://docs.microsoft.com/ja-jp/dotnet/standard/serialization/binaryformatter-security-guide /// [Sample] public class SerializationSurrogateSamples01 : IExecutable { public void Execute() { +#if ENABLE_OLD_NET_FEATURE // // 普通のシリアライズ処理. // @@ -96,6 +101,7 @@ public void Execute() Output.WriteLine("[ERROR]: {0}", ex.Message); } } +#endif } private IHasNameAndAge MakeSerializableObject() From acafa2733dc8a2a6b6a68e66378646db5c6ce53c Mon Sep 17 00:00:00 2001 From: devlights Date: Sun, 18 Apr 2021 14:13:32 +0000 Subject: [PATCH 03/38] Add pragma disable --- TryCSharp.Samples/Advanced/RuntimeHelpersSamples02.cs | 10 ++++------ TryCSharp.Samples/Advanced/RuntimeHelpersSamples03.cs | 10 ++++------ .../Advanced/SerializationSurrogateSamples01.cs | 8 ++++---- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/TryCSharp.Samples/Advanced/RuntimeHelpersSamples02.cs b/TryCSharp.Samples/Advanced/RuntimeHelpersSamples02.cs index ba754e4..88227ac 100644 --- a/TryCSharp.Samples/Advanced/RuntimeHelpersSamples02.cs +++ b/TryCSharp.Samples/Advanced/RuntimeHelpersSamples02.cs @@ -1,4 +1,5 @@ -using System.Runtime.CompilerServices; +#pragma warning disable SYSLIB0004 +using System.Runtime.CompilerServices; using System.Runtime.ConstrainedExecution; using TryCSharp.Common; @@ -32,9 +33,7 @@ public void Execute() // すると、try内の本処理よりも先にfinallyブロック内の静的コンストラクタが呼ばれる事になる。 // (事前コンパイルが行われると、アセンブリのロード、静的コンストラクタの実行などが発生するため) // -#if ENABLE_OLD_NET_FEATURE RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { @@ -77,13 +76,12 @@ static SampleClass() // 尚、この属性はメソッドだけではなく、クラスやインターフェースにも付与できる。 // その場合、クラス全体に対して信頼性のコントラクトを付与したことになる。 // -#if ENABLE_OLD_NET_FEATURE [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] -#endif internal static void Print() { Output.WriteLine("SampleClass.Print()"); } } } -} \ No newline at end of file +} +#pragma warning restore SYSLIB0004 diff --git a/TryCSharp.Samples/Advanced/RuntimeHelpersSamples03.cs b/TryCSharp.Samples/Advanced/RuntimeHelpersSamples03.cs index fd00857..730bd78 100644 --- a/TryCSharp.Samples/Advanced/RuntimeHelpersSamples03.cs +++ b/TryCSharp.Samples/Advanced/RuntimeHelpersSamples03.cs @@ -1,4 +1,5 @@ -using System.Runtime.CompilerServices; +#pragma warning disable SYSLIB0004 +using System.Runtime.CompilerServices; using System.Runtime.ConstrainedExecution; using TryCSharp.Common; @@ -32,9 +33,7 @@ public void Execute() // public delegate void CleanupCode(object userData, bool exceptionThrown) // // 前回のサンプルと同じ動作を行う. -#if ENABLE_OLD_NET_FEATURE RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(Calc, Cleanup, null); -#endif } private void Calc(object userData) @@ -65,13 +64,12 @@ static SampleClass() // ReliabilityContractAttributeおよびConsistencyやCerは // System.Runtime.ConstrainedExecution名前空間に存在する. // -#if ENABLE_OLD_NET_FEATURE [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] -#endif internal static void Print() { Output.WriteLine("SampleClass.Print()"); } } } -} \ No newline at end of file +} +#pragma warning restore SYSLIB0004 diff --git a/TryCSharp.Samples/Advanced/SerializationSurrogateSamples01.cs b/TryCSharp.Samples/Advanced/SerializationSurrogateSamples01.cs index f540e7d..4a89bf5 100644 --- a/TryCSharp.Samples/Advanced/SerializationSurrogateSamples01.cs +++ b/TryCSharp.Samples/Advanced/SerializationSurrogateSamples01.cs @@ -1,4 +1,5 @@ -using System; +#pragma warning disable SYSLIB0011 +using System; using System.IO; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; @@ -21,7 +22,6 @@ public class SerializationSurrogateSamples01 : IExecutable { public void Execute() { -#if ENABLE_OLD_NET_FEATURE // // 普通のシリアライズ処理. // @@ -101,7 +101,6 @@ public void Execute() Output.WriteLine("[ERROR]: {0}", ex.Message); } } -#endif } private IHasNameAndAge MakeSerializableObject() @@ -212,4 +211,5 @@ public object SetObjectData(object obj, SerializationInfo info, StreamingContext #endregion } -} \ No newline at end of file +} +#pragma warning restore SYSLIB0011 From 0666d3788984dc84e2433907fc49a2dadc8fe417 Mon Sep 17 00:00:00 2001 From: devlights Date: Sun, 21 Nov 2021 16:36:59 +0000 Subject: [PATCH 04/38] Update csproj --- TryCSharp.Common/TryCSharp.Common.csproj | 4 +++- TryCSharp.Samples/TryCSharp.Samples.csproj | 4 +++- TryCSharp.Tools.Cui/TryCSharp.Tools.Cui.csproj | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/TryCSharp.Common/TryCSharp.Common.csproj b/TryCSharp.Common/TryCSharp.Common.csproj index a6e434f..6be5b8d 100644 --- a/TryCSharp.Common/TryCSharp.Common.csproj +++ b/TryCSharp.Common/TryCSharp.Common.csproj @@ -1,10 +1,12 @@  - net5.0 + net6.0 TryCSharp.Common latest TryCSharp.Common + enable + enable diff --git a/TryCSharp.Samples/TryCSharp.Samples.csproj b/TryCSharp.Samples/TryCSharp.Samples.csproj index 84367bc..4c73325 100644 --- a/TryCSharp.Samples/TryCSharp.Samples.csproj +++ b/TryCSharp.Samples/TryCSharp.Samples.csproj @@ -1,10 +1,12 @@  - net5.0 + net6.0 TryCSharp.Samples latest TryCSharp.Samples + enable + enable diff --git a/TryCSharp.Tools.Cui/TryCSharp.Tools.Cui.csproj b/TryCSharp.Tools.Cui/TryCSharp.Tools.Cui.csproj index 09b788c..df82e53 100644 --- a/TryCSharp.Tools.Cui/TryCSharp.Tools.Cui.csproj +++ b/TryCSharp.Tools.Cui/TryCSharp.Tools.Cui.csproj @@ -2,10 +2,12 @@ Exe - net5.0 + net6.0 TryCSharp.Tools.Cui latest TryCSharp.Tools.Cui + enable + enable From e9f3f20426718d2d8971bedbfef10382fabc9d1f Mon Sep 17 00:00:00 2001 From: devlights Date: Sun, 21 Nov 2021 16:47:07 +0000 Subject: [PATCH 05/38] Update gitpod config files --- .gitpod.Dockerfile | 8 ++++++++ .gitpod.yml | 10 +++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 .gitpod.Dockerfile diff --git a/.gitpod.Dockerfile b/.gitpod.Dockerfile new file mode 100644 index 0000000..4d276c6 --- /dev/null +++ b/.gitpod.Dockerfile @@ -0,0 +1,8 @@ +FROM gitpod/workspace-full:latest + +USER gitpod + +# https://github.com/gitpod-io/gitpod/issues/5090#issuecomment-954978727 +#.NET installed via .gitpod.yml task until the following issue is fixed: https://github.com/gitpod-io/gitpod/issues/5090 +ENV DOTNET_ROOT=/tmp/dotnet +ENV PATH=$PATH:/tmp/dotnet \ No newline at end of file diff --git a/.gitpod.yml b/.gitpod.yml index 03f4220..07a3761 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -1,5 +1,13 @@ -image: gitpod/workspace-dotnet +image: + file: .gitpod.Dockerfile + +tasks: + - name: Postinstall .NET 6.0 and dev certificates + init: | + mkdir -p /tmp/dotnet && curl -fsSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel 6.0 --install-dir /tmp/dotnet + dotnet dev-certs https + dotnet restore vscode: extensions: From cb04706674d7b48e8c467eea61de3c75bfeca1b0 Mon Sep 17 00:00:00 2001 From: devlights Date: Sun, 21 Nov 2021 17:17:25 +0000 Subject: [PATCH 06/38] Add devcontainer --- .devcontainer/Dockerfile | 16 ++++++++++ .devcontainer/devcontainer.json | 56 +++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..70c1b66 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,16 @@ +# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.203.0/containers/dotnet/.devcontainer/base.Dockerfile + +# [Choice] .NET version: 6.0, 5.0, 3.1, 6.0-bullseye, 5.0-bullseye, 3.1-bullseye, 6.0-focal, 5.0-focal, 3.1-focal +ARG VARIANT="6.0-bullseye" +FROM mcr.microsoft.com/vscode/devcontainers/dotnet:0-${VARIANT} + +# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10 +ARG NODE_VERSION="none" +RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi + +# [Optional] Uncomment this section to install additional OS packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends + +# [Optional] Uncomment this line to install global node packages. +# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g " 2>&1 \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..238becd --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,56 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: +// https://github.com/microsoft/vscode-dev-containers/tree/v0.203.0/containers/dotnet +{ + "name": "C# (.NET)", + "runArgs": ["--init"], + "build": { + "dockerfile": "Dockerfile", + "args": { + // Update 'VARIANT' to pick a .NET Core version: 3.1, 5.0, 6.0 + // Append -bullseye or -focal to pin to an OS version. + "VARIANT": "6.0", + // Options + "NODE_VERSION": "lts/*" + } + }, + + // Set *default* container specific settings.json values on container create. + "settings": {}, + + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "ms-dotnettools.csharp" + ], + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [5000, 5001], + + // [Optional] To reuse of your local HTTPS dev cert: + // + // 1. Export it locally using this command: + // * Windows PowerShell: + // dotnet dev-certs https --trust; dotnet dev-certs https -ep "$env:USERPROFILE/.aspnet/https/aspnetapp.pfx" -p "SecurePwdGoesHere" + // * macOS/Linux terminal: + // dotnet dev-certs https --trust; dotnet dev-certs https -ep "${HOME}/.aspnet/https/aspnetapp.pfx" -p "SecurePwdGoesHere" + // + // 2. Uncomment these 'remoteEnv' lines: + // "remoteEnv": { + // "ASPNETCORE_Kestrel__Certificates__Default__Password": "SecurePwdGoesHere", + // "ASPNETCORE_Kestrel__Certificates__Default__Path": "/home/vscode/.aspnet/https/aspnetapp.pfx", + // }, + // + // 3. Do one of the following depending on your scenario: + // * When using GitHub Codespaces and/or Remote - Containers: + // 1. Start the container + // 2. Drag ~/.aspnet/https/aspnetapp.pfx into the root of the file explorer + // 3. Open a terminal in VS Code and run "mkdir -p /home/vscode/.aspnet/https && mv aspnetapp.pfx /home/vscode/.aspnet/https" + // + // * If only using Remote - Containers with a local container, uncomment this line instead: + // "mounts": [ "source=${env:HOME}${env:USERPROFILE}/.aspnet/https,target=/home/vscode/.aspnet/https,type=bind" ], + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "dotnet restore", + + // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. + "remoteUser": "vscode" +} From 54cc9525cd888c217027ba8ec0bdcb0fd3cd13df Mon Sep 17 00:00:00 2001 From: devlights Date: Mon, 22 Nov 2021 02:16:38 +0000 Subject: [PATCH 07/38] Update gitpod config files --- .gitpod.Dockerfile | 1 + .gitpod.yml | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitpod.Dockerfile b/.gitpod.Dockerfile index 4d276c6..e0d8db4 100644 --- a/.gitpod.Dockerfile +++ b/.gitpod.Dockerfile @@ -4,5 +4,6 @@ USER gitpod # https://github.com/gitpod-io/gitpod/issues/5090#issuecomment-954978727 #.NET installed via .gitpod.yml task until the following issue is fixed: https://github.com/gitpod-io/gitpod/issues/5090 +RUN mkdir -p /tmp/dotnet && curl -fsSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel 6.0 --install-dir /tmp/dotnet ENV DOTNET_ROOT=/tmp/dotnet ENV PATH=$PATH:/tmp/dotnet \ No newline at end of file diff --git a/.gitpod.yml b/.gitpod.yml index 07a3761..3f06b42 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -5,7 +5,6 @@ image: tasks: - name: Postinstall .NET 6.0 and dev certificates init: | - mkdir -p /tmp/dotnet && curl -fsSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel 6.0 --install-dir /tmp/dotnet dotnet dev-certs https dotnet restore From 7166007ce20369ba80a4710c30ac9ebbafdc404c Mon Sep 17 00:00:00 2001 From: devlights Date: Mon, 22 Nov 2021 02:26:14 +0000 Subject: [PATCH 08/38] Update --- .gitpod.Dockerfile | 3 +-- .gitpod.yml | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitpod.Dockerfile b/.gitpod.Dockerfile index e0d8db4..ec7d864 100644 --- a/.gitpod.Dockerfile +++ b/.gitpod.Dockerfile @@ -3,7 +3,6 @@ FROM gitpod/workspace-full:latest USER gitpod # https://github.com/gitpod-io/gitpod/issues/5090#issuecomment-954978727 -#.NET installed via .gitpod.yml task until the following issue is fixed: https://github.com/gitpod-io/gitpod/issues/5090 -RUN mkdir -p /tmp/dotnet && curl -fsSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel 6.0 --install-dir /tmp/dotnet +#.NET installed via .gitpod.yml task until the following issue is fixed: https://github.com/gitpod-io/gitpod/issues/5090 ENV DOTNET_ROOT=/tmp/dotnet ENV PATH=$PATH:/tmp/dotnet \ No newline at end of file diff --git a/.gitpod.yml b/.gitpod.yml index 3f06b42..07a3761 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -5,6 +5,7 @@ image: tasks: - name: Postinstall .NET 6.0 and dev certificates init: | + mkdir -p /tmp/dotnet && curl -fsSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel 6.0 --install-dir /tmp/dotnet dotnet dev-certs https dotnet restore From 69941e50ed8d6636f2fa6f0b51d6fd80b85feeba Mon Sep 17 00:00:00 2001 From: devlights Date: Mon, 22 Nov 2021 02:36:28 +0000 Subject: [PATCH 09/38] Update --- .gitpod.Dockerfile | 12 ++++++++++-- .gitpod.yml | 1 - 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.gitpod.Dockerfile b/.gitpod.Dockerfile index ec7d864..c7ea6bb 100644 --- a/.gitpod.Dockerfile +++ b/.gitpod.Dockerfile @@ -2,7 +2,15 @@ FROM gitpod/workspace-full:latest USER gitpod +RUN wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb \ + && sudo dpkg -i packages-microsoft-prod.deb \ + && rm packages-microsoft-prod.deb \ + && sudo apt-get update \ + && sudo apt-get install -y apt-transport-https \ + && sudo apt-get update \ + && sudo apt-get install -y dotnet-sdk-6.0 + # https://github.com/gitpod-io/gitpod/issues/5090#issuecomment-954978727 #.NET installed via .gitpod.yml task until the following issue is fixed: https://github.com/gitpod-io/gitpod/issues/5090 -ENV DOTNET_ROOT=/tmp/dotnet -ENV PATH=$PATH:/tmp/dotnet \ No newline at end of file +ENV DOTNET_ROOT= +#ENV PATH=$PATH:/tmp/dotnet \ No newline at end of file diff --git a/.gitpod.yml b/.gitpod.yml index 07a3761..3f06b42 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -5,7 +5,6 @@ image: tasks: - name: Postinstall .NET 6.0 and dev certificates init: | - mkdir -p /tmp/dotnet && curl -fsSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel 6.0 --install-dir /tmp/dotnet dotnet dev-certs https dotnet restore From c480b77d2f06b7e41d5a38140a2d5d6055827944 Mon Sep 17 00:00:00 2001 From: devlights Date: Mon, 22 Nov 2021 02:44:32 +0000 Subject: [PATCH 10/38] Update --- .gitpod.Dockerfile | 12 ++---------- .gitpod.yml | 1 + 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/.gitpod.Dockerfile b/.gitpod.Dockerfile index c7ea6bb..ec7d864 100644 --- a/.gitpod.Dockerfile +++ b/.gitpod.Dockerfile @@ -2,15 +2,7 @@ FROM gitpod/workspace-full:latest USER gitpod -RUN wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb \ - && sudo dpkg -i packages-microsoft-prod.deb \ - && rm packages-microsoft-prod.deb \ - && sudo apt-get update \ - && sudo apt-get install -y apt-transport-https \ - && sudo apt-get update \ - && sudo apt-get install -y dotnet-sdk-6.0 - # https://github.com/gitpod-io/gitpod/issues/5090#issuecomment-954978727 #.NET installed via .gitpod.yml task until the following issue is fixed: https://github.com/gitpod-io/gitpod/issues/5090 -ENV DOTNET_ROOT= -#ENV PATH=$PATH:/tmp/dotnet \ No newline at end of file +ENV DOTNET_ROOT=/tmp/dotnet +ENV PATH=$PATH:/tmp/dotnet \ No newline at end of file diff --git a/.gitpod.yml b/.gitpod.yml index 3f06b42..07a3761 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -5,6 +5,7 @@ image: tasks: - name: Postinstall .NET 6.0 and dev certificates init: | + mkdir -p /tmp/dotnet && curl -fsSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel 6.0 --install-dir /tmp/dotnet dotnet dev-certs https dotnet restore From e116806527c3702212c5254cad24dc19e23968a4 Mon Sep 17 00:00:00 2001 From: devlights Date: Mon, 22 Nov 2021 06:50:13 +0000 Subject: [PATCH 11/38] Update devcontainer files --- .devcontainer/Dockerfile | 2 -- .devcontainer/devcontainer.json | 22 +++++++--------------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 70c1b66..1d2a093 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,5 +1,3 @@ -# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.203.0/containers/dotnet/.devcontainer/base.Dockerfile - # [Choice] .NET version: 6.0, 5.0, 3.1, 6.0-bullseye, 5.0-bullseye, 3.1-bullseye, 6.0-focal, 5.0-focal, 3.1-focal ARG VARIANT="6.0-bullseye" FROM mcr.microsoft.com/vscode/devcontainers/dotnet:0-${VARIANT} diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 238becd..e6d1a02 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,28 +1,17 @@ -// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: -// https://github.com/microsoft/vscode-dev-containers/tree/v0.203.0/containers/dotnet { "name": "C# (.NET)", "runArgs": ["--init"], "build": { "dockerfile": "Dockerfile", "args": { - // Update 'VARIANT' to pick a .NET Core version: 3.1, 5.0, 6.0 - // Append -bullseye or -focal to pin to an OS version. "VARIANT": "6.0", - // Options "NODE_VERSION": "lts/*" } }, - - // Set *default* container specific settings.json values on container create. "settings": {}, - - // Add the IDs of extensions you want installed when the container is created. "extensions": [ "ms-dotnettools.csharp" ], - - // Use 'forwardPorts' to make a list of ports inside the container available locally. // "forwardPorts": [5000, 5001], // [Optional] To reuse of your local HTTPS dev cert: @@ -47,10 +36,13 @@ // // * If only using Remote - Containers with a local container, uncomment this line instead: // "mounts": [ "source=${env:HOME}${env:USERPROFILE}/.aspnet/https,target=/home/vscode/.aspnet/https,type=bind" ], - // Use 'postCreateCommand' to run commands after the container is created. - // "postCreateCommand": "dotnet restore", - // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. - "remoteUser": "vscode" + // "postCreateCommand": "dotnet restore", + + "remoteUser": "vscode", + "features": { + "docker-from-docker": "20.10", + "golang": "1.17" + } } From 25a4df68d257cfea008f258c1c6420dcea0a61c0 Mon Sep 17 00:00:00 2001 From: devlights Date: Mon, 22 Nov 2021 07:24:36 +0000 Subject: [PATCH 12/38] Update Makefile --- Makefile | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index fdee7eb..ce48555 100644 --- a/Makefile +++ b/Makefile @@ -17,20 +17,21 @@ CUI_PROJ_PATH=$(CUI_PROJ_NAME)$(SEP)$(CUI_PROJ_NAME).csproj all: clean build test .PHONY: build -build: - $(DOTNETCMD) restore -v q +build: restore $(DOTNETBUILD) --nologo -v q .PHONY: test -test: +test: restore $(DOTNETTEST) .PHONY: clean -clean: +clean: restore $(DOTNETCLEAN) --nologo -v q .PHONY: run run: clean - $(DOTNETCMD) restore -v q $(DOTNETRUN) --project $(CUI_PROJ_PATH) --onetime +.PHONY: restore +restore: + $(DOTNETCMD) restore -v q From 43a74afeb79e41b1080b3bfb0e5c1f788c24e218 Mon Sep 17 00:00:00 2001 From: devlights Date: Mon, 22 Nov 2021 07:24:45 +0000 Subject: [PATCH 13/38] Update devcontainer.json --- .devcontainer/devcontainer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index e6d1a02..4a1bfa3 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -10,7 +10,8 @@ }, "settings": {}, "extensions": [ - "ms-dotnettools.csharp" + "ms-dotnettools.csharp", + "dracula-theme.theme-dracula" ], // "forwardPorts": [5000, 5001], From dcfaae95d9b99acb6e3a558f2c85e0edfc197698 Mon Sep 17 00:00:00 2001 From: devlights Date: Mon, 22 Nov 2021 15:10:00 +0000 Subject: [PATCH 14/38] Update devcontainer config files --- .devcontainer/Dockerfile | 5 +++-- .devcontainer/devcontainer.json | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 1d2a093..9d73f57 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -7,8 +7,9 @@ ARG NODE_VERSION="none" RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi # [Optional] Uncomment this section to install additional OS packages. -# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ -# && apt-get -y install --no-install-recommends +RUN apt-get update -q && export DEBIAN_FRONTEND=noninteractive \ + && apt-get -yq install --no-install-recommends bash-completion +RUN su vscode -c "source /etc/bash_completion" # [Optional] Uncomment this line to install global node packages. # RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g " 2>&1 \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 4a1bfa3..173c0bb 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -39,7 +39,7 @@ // "mounts": [ "source=${env:HOME}${env:USERPROFILE}/.aspnet/https,target=/home/vscode/.aspnet/https,type=bind" ], // Use 'postCreateCommand' to run commands after the container is created. - // "postCreateCommand": "dotnet restore", + "postCreateCommand": "make restore", "remoteUser": "vscode", "features": { From b33c3b8c8efed1f7b3d25ddfa0864b2257d2c0db Mon Sep 17 00:00:00 2001 From: devlights Date: Wed, 24 Nov 2021 06:32:32 +0000 Subject: [PATCH 15/38] Update devcontainer config file --- .devcontainer/devcontainer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 173c0bb..8504e97 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -10,8 +10,7 @@ }, "settings": {}, "extensions": [ - "ms-dotnettools.csharp", - "dracula-theme.theme-dracula" + "ms-dotnettools.csharp" ], // "forwardPorts": [5000, 5001], @@ -43,7 +42,8 @@ "remoteUser": "vscode", "features": { - "docker-from-docker": "20.10", + // https://github.com/microsoft/vscode-dev-containers/tree/main/containers/docker-from-docker#using-bind-mounts-when-working-with-docker-inside-the-container + "docker-in-docker": "20.10", "golang": "1.17" } } From dc2f1bef24a2c0479fe9fccbf427a577e004ef60 Mon Sep 17 00:00:00 2001 From: devlights Date: Tue, 15 Feb 2022 06:53:14 +0000 Subject: [PATCH 16/38] Update gitpod config files --- .gitpod.Dockerfile | 7 +------ .gitpod.yml | 6 ++---- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/.gitpod.Dockerfile b/.gitpod.Dockerfile index ec7d864..9d506b1 100644 --- a/.gitpod.Dockerfile +++ b/.gitpod.Dockerfile @@ -1,8 +1,3 @@ -FROM gitpod/workspace-full:latest +FROM gitpod/workspace-dotnet-lts:latest USER gitpod - -# https://github.com/gitpod-io/gitpod/issues/5090#issuecomment-954978727 -#.NET installed via .gitpod.yml task until the following issue is fixed: https://github.com/gitpod-io/gitpod/issues/5090 -ENV DOTNET_ROOT=/tmp/dotnet -ENV PATH=$PATH:/tmp/dotnet \ No newline at end of file diff --git a/.gitpod.yml b/.gitpod.yml index 07a3761..090c4d2 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -3,11 +3,9 @@ image: file: .gitpod.Dockerfile tasks: - - name: Postinstall .NET 6.0 and dev certificates + - name: dotnet version init: | - mkdir -p /tmp/dotnet && curl -fsSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel 6.0 --install-dir /tmp/dotnet - dotnet dev-certs https - dotnet restore + dotnet --info vscode: extensions: From 12a52d7aeaad824c9cbf29f8d04db7f94c69494c Mon Sep 17 00:00:00 2001 From: devlights Date: Wed, 16 Feb 2022 01:02:08 +0000 Subject: [PATCH 17/38] Remove .gitpod.Dockerfile --- .gitpod.Dockerfile | 3 --- .gitpod.yml | 5 +++-- 2 files changed, 3 insertions(+), 5 deletions(-) delete mode 100644 .gitpod.Dockerfile diff --git a/.gitpod.Dockerfile b/.gitpod.Dockerfile deleted file mode 100644 index 9d506b1..0000000 --- a/.gitpod.Dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM gitpod/workspace-dotnet-lts:latest - -USER gitpod diff --git a/.gitpod.yml b/.gitpod.yml index 090c4d2..03a7a10 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -1,11 +1,12 @@ -image: - file: .gitpod.Dockerfile +image: gitpod/workspace-dotnet-lts:latest tasks: - name: dotnet version init: | dotnet --info + - name: dotnet restore + command: make restore vscode: extensions: From 06bf66b54e5f47de6d0d34663112667fafb1562b Mon Sep 17 00:00:00 2001 From: devlights Date: Mon, 7 Mar 2022 05:31:32 +0000 Subject: [PATCH 18/38] Update try-csharp.sln --- try-csharp.sln | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/try-csharp.sln b/try-csharp.sln index 5467b8e..ec866db 100644 --- a/try-csharp.sln +++ b/try-csharp.sln @@ -1,8 +1,8 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.0.0 -MinimumVisualStudioVersion = 10.0.0.1 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30114.105 +MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TryCSharp.Common", "TryCSharp.Common\TryCSharp.Common.csproj", "{9A53DD5F-57A3-4C4D-A61F-2FEC01C11AD8}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TryCSharp.Tools.Cui", "TryCSharp.Tools.Cui\TryCSharp.Tools.Cui.csproj", "{7060350F-296D-44FE-BF9F-D95BA5FD5602}" From d49eb900a7e2e9b2e99d6145f08f6aaaad094c9c Mon Sep 17 00:00:00 2001 From: devlights Date: Mon, 7 Mar 2022 05:51:01 +0000 Subject: [PATCH 19/38] Update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index da348f4..4d3431a 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # try-csharp This is my TUTORIAL project for csharp. (dotnet core) -![try-csharp - DotNet Version](https://img.shields.io/badge/dotnet-5.0-blue.svg) +![try-csharp - DotNet Version](https://img.shields.io/badge/dotnet-6.0-blue.svg) [![CodeFactor](https://www.codefactor.io/repository/github/devlights/try-csharp/badge)](https://www.codefactor.io/repository/github/devlights/try-csharp) [![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/devlights/try-csharp) From 990310fafd2f074dce78788cc100e5d0c3264d9a Mon Sep 17 00:00:00 2001 From: devlights Date: Mon, 7 Mar 2022 05:57:19 +0000 Subject: [PATCH 20/38] Fix warnings TryCSharp.Common --- TryCSharp.Common/Input.cs | 17 ++++++----------- TryCSharp.Common/Output.cs | 36 ++++++++++++++++++++++-------------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/TryCSharp.Common/Input.cs b/TryCSharp.Common/Input.cs index 4198b8f..9c016d2 100644 --- a/TryCSharp.Common/Input.cs +++ b/TryCSharp.Common/Input.cs @@ -10,7 +10,7 @@ public static class Input /// /// 入力管理オブジェクトを取得・設定します。 /// - public static IInputManager InputManager { get; set; } + public static IInputManager? InputManager { get; set; } /// /// 1データを読み込みます。 @@ -18,7 +18,10 @@ public static class Input /// 読み込まれたデータ public static object Read() { - Defence(); + if (InputManager == null) + { + throw new InvalidOperationException("No InputManager was found."); + } return InputManager.Read(); } @@ -27,20 +30,12 @@ public static object Read() /// /// 一行分のデータ public static object ReadLine() - { - Defence(); - return InputManager.ReadLine(); - } - - /// - /// 現在のオブジェクトの状態をチェックします。 - /// - private static void Defence() { if (InputManager == null) { throw new InvalidOperationException("No InputManager was found."); } + return InputManager.ReadLine(); } } } \ No newline at end of file diff --git a/TryCSharp.Common/Output.cs b/TryCSharp.Common/Output.cs index 9f198ab..94351f5 100644 --- a/TryCSharp.Common/Output.cs +++ b/TryCSharp.Common/Output.cs @@ -11,14 +11,21 @@ public static class Output /// /// 出力管理オブジェクトを取得・設定します。 /// - public static IOutputManager OutputManager { get; set; } + public static IOutputManager? OutputManager { get; set; } /// /// 出力ストリーム /// public static Stream OutStream { - get { return OutputManager.OutStream; } + get + { + if (OutputManager == null) + { + throw new InvalidOperationException("No OutputManager was found. "); + } + return OutputManager.OutStream; + } } /// @@ -27,7 +34,10 @@ public static Stream OutStream /// データ public static void Write(object data) { - Defence(); + if (OutputManager == null) + { + throw new InvalidOperationException("No OutputManager was found. "); + } OutputManager.Write(data); } @@ -38,7 +48,10 @@ public static void Write(object data) /// フォーマット引数 public static void Write(string format, params object[] args) { - Defence(); + if (OutputManager == null) + { + throw new InvalidOperationException("No OutputManager was found. "); + } OutputManager.Write(string.Format(format, args)); } @@ -56,7 +69,10 @@ public static void WriteLine() /// データ public static void WriteLine(object data) { - Defence(); + if (OutputManager == null) + { + throw new InvalidOperationException("No OutputManager was found. "); + } OutputManager.WriteLine(data); } @@ -66,20 +82,12 @@ public static void WriteLine(object data) /// フォーマット /// フォーマット引数 public static void WriteLine(string format, params object[] arg) - { - Defence(); - OutputManager.WriteLine(string.Format(format, arg)); - } - - /// - /// 現在のオブジェクトの状態をチェックします。 - /// - private static void Defence() { if (OutputManager == null) { throw new InvalidOperationException("No OutputManager was found. "); } + OutputManager.WriteLine(string.Format(format, arg)); } } } \ No newline at end of file From cddfebacee541ac607c40b69fb5c0b3806a9599a Mon Sep 17 00:00:00 2001 From: devlights Date: Mon, 7 Mar 2022 06:02:29 +0000 Subject: [PATCH 21/38] Fix warnings TryCSharp.Tools.Cui --- TryCSharp.Tools.Cui/CuiInputManager.cs | 2 +- TryCSharp.Tools.Cui/Program.cs | 44 ++++++++++++++++---------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/TryCSharp.Tools.Cui/CuiInputManager.cs b/TryCSharp.Tools.Cui/CuiInputManager.cs index 8a1e252..33d0fbf 100644 --- a/TryCSharp.Tools.Cui/CuiInputManager.cs +++ b/TryCSharp.Tools.Cui/CuiInputManager.cs @@ -24,6 +24,6 @@ public class CuiInputManager : IInputManager /// /// コンソールから文字列を読み込んでいるので、戻り値の型はstringになります。 /// - public object ReadLine() => Console.ReadLine(); + public object ReadLine() => Console.ReadLine()!; } } \ No newline at end of file diff --git a/TryCSharp.Tools.Cui/Program.cs b/TryCSharp.Tools.Cui/Program.cs index bf4a5eb..0c7ed7c 100644 --- a/TryCSharp.Tools.Cui/Program.cs +++ b/TryCSharp.Tools.Cui/Program.cs @@ -31,20 +31,20 @@ private static async Task Main(string[] args) var emptyValidator = new EmptyInputValidator(); var exitValidator = new ExitPhaseValidator(); - var typeFullNameList = GetAssembly().GetExportedTypes().Select(x => x.FullName).ToList(); - for (;;) + var typeFullNameList = GetAssembly().GetExportedTypes().Select(x => x.FullName!).ToList(); + for (; ; ) { - if (await Execute(emptyValidator, exitValidator, typeFullNameList, onetime)) + if (await Execute(emptyValidator, exitValidator, typeFullNameList!, onetime)) { - break; + break; } } } private static async Task Execute( - IHasValidation emptyValidator, + IHasValidation emptyValidator, IHasValidation exitValidator, - IEnumerable typeFullNameList, + IEnumerable typeFullNameList, bool onetime) { try @@ -56,7 +56,7 @@ private static async Task Execute( { return false; } - + if (emptyValidator.Validate(userInput)) { return false; @@ -116,16 +116,16 @@ private static async Task Execute( switch (clazz) { case IExecutable target: - { - executor.Execute(target); - break; - } + { + executor.Execute(target); + break; + } case IAsyncExecutable asyncTarget: - { - await executor.Execute(asyncTarget); - break; - } + { + await executor.Execute(asyncTarget); + break; + } default: Output.WriteLine($"**** INVALID SAMPLE TYPE **** [{clazz.GetType().FullName}]"); @@ -156,7 +156,19 @@ private static Assembly GetAssembly() private static object GetInstance(string target) { - return GetAssembly().CreateInstance(target); + var asm = GetAssembly(); + if (asm == null) + { + throw new NullReferenceException("GetAssembly() is null"); + } + + var obj = asm.CreateInstance(target); + if (obj == null) + { + throw new NullReferenceException("CreateInstance() is null"); + } + + return obj; } } } From cd0ae57efaa8aa5ba7182e9a364baa8fc2a53524 Mon Sep 17 00:00:00 2001 From: devlights Date: Tue, 8 Mar 2022 04:51:30 +0000 Subject: [PATCH 22/38] Fix warnings (AdoNet) --- TryCSharp.Common/Output.cs | 3 ++- TryCSharp.Samples/AdoNet/DataTableSamples01.cs | 5 +++-- TryCSharp.Samples/AdoNet/DbCommandTimeoutSample01.cs | 2 +- TryCSharp.Samples/AdoNet/ExcelConnectSamples01.cs | 4 ++-- TryCSharp.Samples/AdoNet/TextConnectSamples01.cs | 4 ++-- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/TryCSharp.Common/Output.cs b/TryCSharp.Common/Output.cs index 94351f5..94e8c3b 100644 --- a/TryCSharp.Common/Output.cs +++ b/TryCSharp.Common/Output.cs @@ -81,12 +81,13 @@ public static void WriteLine(object data) /// /// フォーマット /// フォーマット引数 - public static void WriteLine(string format, params object[] arg) + public static void WriteLine(string format, params object?[] arg) { if (OutputManager == null) { throw new InvalidOperationException("No OutputManager was found. "); } + OutputManager.WriteLine(string.Format(format, arg)); } } diff --git a/TryCSharp.Samples/AdoNet/DataTableSamples01.cs b/TryCSharp.Samples/AdoNet/DataTableSamples01.cs index 6b4e8f7..fc5b6db 100644 --- a/TryCSharp.Samples/AdoNet/DataTableSamples01.cs +++ b/TryCSharp.Samples/AdoNet/DataTableSamples01.cs @@ -12,8 +12,9 @@ public class DataTableSamples01 : IExecutable public void Execute() { var table = new DataTable(); - - table.Columns.Add("Val", typeof(decimal)); + { + table.Columns.Add("Val", typeof(decimal)); + } for (var i = 0; i < 10; i++) { diff --git a/TryCSharp.Samples/AdoNet/DbCommandTimeoutSample01.cs b/TryCSharp.Samples/AdoNet/DbCommandTimeoutSample01.cs index 329a243..3ea3eb1 100644 --- a/TryCSharp.Samples/AdoNet/DbCommandTimeoutSample01.cs +++ b/TryCSharp.Samples/AdoNet/DbCommandTimeoutSample01.cs @@ -14,7 +14,7 @@ public class DbCommandTimeoutSample01 : IExecutable public void Execute() { var factory = DbProviderFactories.GetFactory("System.Data.SqlClient"); - using (var conn = factory.CreateConnection()) + using (var conn = factory.CreateConnection()!) { conn.ConnectionString = @"User Id=medal;Password=medal;Initial Catalog=Medal;Data Source=.\SQLEXPRESS"; conn.Open(); diff --git a/TryCSharp.Samples/AdoNet/ExcelConnectSamples01.cs b/TryCSharp.Samples/AdoNet/ExcelConnectSamples01.cs index 3bfb895..a6e53a5 100644 --- a/TryCSharp.Samples/AdoNet/ExcelConnectSamples01.cs +++ b/TryCSharp.Samples/AdoNet/ExcelConnectSamples01.cs @@ -18,7 +18,7 @@ public void Execute() // プロバイダー名は、「System.Data.OleDb」となる。 // var factory = DbProviderFactories.GetFactory("System.Data.OleDb"); - using (var conn = factory.CreateConnection()) + using (var conn = factory.CreateConnection()!) { // // Excel用の接続文字列を構築. @@ -34,7 +34,7 @@ public void Execute() // HDR=NOと指定した場合、カラム名はシステム側で自動的に割り振られる。 // (F1, F2, F3.....となる) // - var builder = factory.CreateConnectionStringBuilder(); + var builder = factory.CreateConnectionStringBuilder()!; builder["Provider"] = "Microsoft.ACE.OLEDB.12.0"; builder["Data Source"] = @"C:\Users\gsf\Tmp\Sample.xlsx"; diff --git a/TryCSharp.Samples/AdoNet/TextConnectSamples01.cs b/TryCSharp.Samples/AdoNet/TextConnectSamples01.cs index c6a491a..e003cb2 100644 --- a/TryCSharp.Samples/AdoNet/TextConnectSamples01.cs +++ b/TryCSharp.Samples/AdoNet/TextConnectSamples01.cs @@ -20,7 +20,7 @@ public void Execute() // OleDbプロバイダを利用してテキストファイル(CSV)に接続する. // var factory = DbProviderFactories.GetFactory("System.Data.OleDb"); - using (var conn = factory.CreateConnection()) + using (var conn = factory.CreateConnection()!) { // // テキストファイルに接続する為の接続文字列を構築. @@ -33,7 +33,7 @@ public void Execute() // 尚、該当ファイルの構造については別途schema.iniファイルを同じディレクトリに // 用意する必要がある。 // - var builder = factory.CreateConnectionStringBuilder(); + var builder = factory.CreateConnectionStringBuilder()!; builder["Provider"] = "Microsoft.ACE.OLEDB.12.0"; builder["Data Source"] = @"."; From d3e4b96c0e27b60a64f210f9606cc04bb6bd3db8 Mon Sep 17 00:00:00 2001 From: devlights Date: Tue, 8 Mar 2022 05:14:29 +0000 Subject: [PATCH 23/38] Fix warnings (Advanced) --- TryCSharp.Common/IOutputManager.cs | 4 +-- TryCSharp.Common/Output.cs | 2 +- .../Advanced/AppDomainSamples01.cs | 4 +-- .../Advanced/AppDomainSamples02.cs | 27 ++++++++++++------- .../Advanced/AssemblySamples01.cs | 2 +- .../DebuggerDisplayAttributeSamples01.cs | 8 +++--- .../Advanced/DisposableSamples01.cs | 12 ++++----- .../Advanced/RuntimeHelpersSamples03.cs | 4 +-- .../SerializationSurrogateSamples01.cs | 15 ++++++----- 9 files changed, 43 insertions(+), 35 deletions(-) diff --git a/TryCSharp.Common/IOutputManager.cs b/TryCSharp.Common/IOutputManager.cs index 6085035..e4998f4 100644 --- a/TryCSharp.Common/IOutputManager.cs +++ b/TryCSharp.Common/IOutputManager.cs @@ -16,12 +16,12 @@ public interface IOutputManager /// 指定されたデータを出力します。(改行付与無し) /// /// データ - void Write(object data); + void Write(object? data); /// /// 指定されたデータを出力します。(改行付与有り) /// /// データ - void WriteLine(object data); + void WriteLine(object? data); } } \ No newline at end of file diff --git a/TryCSharp.Common/Output.cs b/TryCSharp.Common/Output.cs index 94e8c3b..9de1995 100644 --- a/TryCSharp.Common/Output.cs +++ b/TryCSharp.Common/Output.cs @@ -67,7 +67,7 @@ public static void WriteLine() /// 指定されたデータを出力します。(改行付与有り) /// /// データ - public static void WriteLine(object data) + public static void WriteLine(object? data) { if (OutputManager == null) { diff --git a/TryCSharp.Samples/Advanced/AppDomainSamples01.cs b/TryCSharp.Samples/Advanced/AppDomainSamples01.cs index ef96299..d7ef4b7 100644 --- a/TryCSharp.Samples/Advanced/AppDomainSamples01.cs +++ b/TryCSharp.Samples/Advanced/AppDomainSamples01.cs @@ -46,9 +46,9 @@ public void Execute() } // イベントハンドラ. - void FirstChanceExHandler(object sender, System.Runtime.ExceptionServices.FirstChanceExceptionEventArgs e) + void FirstChanceExHandler(object? sender, System.Runtime.ExceptionServices.FirstChanceExceptionEventArgs? e) { - Output.WriteLine("FirstChanceException: {0}", e.Exception.Message); + Output.WriteLine("FirstChanceException: {0}", e!.Exception.Message); } } } \ No newline at end of file diff --git a/TryCSharp.Samples/Advanced/AppDomainSamples02.cs b/TryCSharp.Samples/Advanced/AppDomainSamples02.cs index e7de05d..ec3fec8 100644 --- a/TryCSharp.Samples/Advanced/AppDomainSamples02.cs +++ b/TryCSharp.Samples/Advanced/AppDomainSamples02.cs @@ -11,6 +11,12 @@ public class AppDomainSamples02 : MarshalByRefObject, IExecutable { public void Execute() { + throw new NotSupportedException("AppDomain.CreateDomain(string) が非推奨になったため"); + // AppDomain.CreateDomain(string) は非推奨となったのでこのサンプル自体を無効にする + // - https://stackoverflow.com/questions/27266907/no-appdomains-in-net-core-why + // - https://devblogs.microsoft.com/dotnet/porting-to-net-core/ + // 以下のサンプルは .NET Framework 時代では動いていたけど、今現在 (.NET 6) では使えない. + /* var defaultDomain = AppDomain.CurrentDomain; var anotherDomain = AppDomain.CreateDomain("AnotherAppDomain"); @@ -41,16 +47,17 @@ public void Execute() // 以下をコメントアウトすると、ProcessExitイベントが発生する. // //AppDomain.Unload(anotherDomain); + */ } - private void AppDomain_Unload(object sender, EventArgs e) - { - var domain = sender as AppDomain; - Output.WriteLine("AppDomain.Unload: {0}", domain?.FriendlyName); - } + // private void AppDomain_Unload(object sender, EventArgs e) + // { + // var domain = sender as AppDomain; + // Output.WriteLine("AppDomain.Unload: {0}", domain?.FriendlyName); + // } - private void AppDomain_ProcessExit(object sender, EventArgs e) - { + // private void AppDomain_ProcessExit(object sender, EventArgs e) + // { // // ProcessExitイベントには、タイムアウトが存在する。(既定は2秒) // 以下、MSDNの記述. @@ -66,8 +73,8 @@ private void AppDomain_ProcessExit(object sender, EventArgs e) //Output.WriteLine("AppDomain.ProcessExit Thread.Sleep()"); //Thread.Sleep(TimeSpan.FromSeconds(3)); - var domain = sender as AppDomain; - Output.WriteLine("AppDomain.ProcessExit: {0}", domain?.FriendlyName); - } + // var domain = sender as AppDomain; + // Output.WriteLine("AppDomain.ProcessExit: {0}", domain?.FriendlyName); + // } } } \ No newline at end of file diff --git a/TryCSharp.Samples/Advanced/AssemblySamples01.cs b/TryCSharp.Samples/Advanced/AssemblySamples01.cs index fa35c45..4ef2387 100644 --- a/TryCSharp.Samples/Advanced/AssemblySamples01.cs +++ b/TryCSharp.Samples/Advanced/AssemblySamples01.cs @@ -23,7 +23,7 @@ public void Execute() // これが、そのままVisualStudioで設定するバージョン番号に対応する。 // var asm = GetType().Assembly; - var ver = asm.GetName().Version; + var ver = asm.GetName().Version!; Output.WriteLine(ver); diff --git a/TryCSharp.Samples/Advanced/DebuggerDisplayAttributeSamples01.cs b/TryCSharp.Samples/Advanced/DebuggerDisplayAttributeSamples01.cs index 83d4bae..bcf5487 100644 --- a/TryCSharp.Samples/Advanced/DebuggerDisplayAttributeSamples01.cs +++ b/TryCSharp.Samples/Advanced/DebuggerDisplayAttributeSamples01.cs @@ -49,8 +49,8 @@ public void Execute() private class WithDebuggerDisplayAttr { public int Id { get; set; } - public string Name { get; set; } - public string Value { get; set; } + public string? Name { get; set; } + public string? Value { get; set; } } /// @@ -59,8 +59,8 @@ private class WithDebuggerDisplayAttr private class WithoutDebuggerDisplayAttr { public int Id { get; set; } - public string Name { get; set; } - public string Value { get; set; } + public string? Name { get; set; } + public string? Value { get; set; } } } } \ No newline at end of file diff --git a/TryCSharp.Samples/Advanced/DisposableSamples01.cs b/TryCSharp.Samples/Advanced/DisposableSamples01.cs index 67dd3eb..a2f5f77 100644 --- a/TryCSharp.Samples/Advanced/DisposableSamples01.cs +++ b/TryCSharp.Samples/Advanced/DisposableSamples01.cs @@ -46,9 +46,9 @@ public void Execute() // // 条件が存在し、作成されないオブジェクトが存在する可能性がある場合. // - Disposable1 dispose1 = null; - Disposable2 dispose2 = null; - Disposable3 dispose3 = null; + Disposable1? dispose1 = null; + Disposable2? dispose2 = null; + Disposable3? dispose3 = null; var isDispose2Create = false; try @@ -93,14 +93,14 @@ public void Execute() } } - private void DisposeIfNotNull(IDisposable disposableObject) + private void DisposeIfNotNull(IDisposable? disposableObject) { if (disposableObject == null) { return; } - disposableObject.Dispose(); + disposableObject?.Dispose(); } private class DisposableManager : IDisposable @@ -122,7 +122,7 @@ public void Dispose() _isDisposed = true; } - public T Add(T disposableObject) where T : IDisposable + public T? Add(T? disposableObject) where T : IDisposable { Defence(); diff --git a/TryCSharp.Samples/Advanced/RuntimeHelpersSamples03.cs b/TryCSharp.Samples/Advanced/RuntimeHelpersSamples03.cs index 730bd78..1665606 100644 --- a/TryCSharp.Samples/Advanced/RuntimeHelpersSamples03.cs +++ b/TryCSharp.Samples/Advanced/RuntimeHelpersSamples03.cs @@ -36,7 +36,7 @@ public void Execute() RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(Calc, Cleanup, null); } - private void Calc(object userData) + private void Calc(object? userData) { for (var i = 0; i < 10; i++) { @@ -46,7 +46,7 @@ private void Calc(object userData) Output.WriteLine(""); } - private void Cleanup(object userData, bool exceptionThrown) + private void Cleanup(object? userData, bool exceptionThrown) { SampleClass.Print(); } diff --git a/TryCSharp.Samples/Advanced/SerializationSurrogateSamples01.cs b/TryCSharp.Samples/Advanced/SerializationSurrogateSamples01.cs index 4a89bf5..463795b 100644 --- a/TryCSharp.Samples/Advanced/SerializationSurrogateSamples01.cs +++ b/TryCSharp.Samples/Advanced/SerializationSurrogateSamples01.cs @@ -127,7 +127,7 @@ private IHasNameAndAge MakeNotSerializableObject() private interface IHasNameAndAge { - string Name { get; set; } + string? Name { get; set; } int Age { get; set; } } @@ -136,9 +136,9 @@ private interface IHasNameAndAge private class CanSerialize : IHasNameAndAge { private int _age; - private string _name; + private string? _name; - public string Name + public string? Name { get { return _name; } set { _name = value; } @@ -159,7 +159,7 @@ public override string ToString() // シリアライズ不可なクラス private class CanNotSerialize : IHasNameAndAge { - public string Name { get; set; } + public string? Name { get; set; } public int Age { get; set; } @@ -190,12 +190,12 @@ public void GetObjectData(object obj, SerializationInfo info, StreamingContext c // デシリアライズ時に呼び出されるメソッド. public object SetObjectData(object obj, SerializationInfo info, StreamingContext context, - ISurrogateSelector selector) + ISurrogateSelector? selector) { var targetObj = obj as CanNotSerialize; if (targetObj == null) { - return null; + return new object(); } // @@ -205,7 +205,8 @@ public object SetObjectData(object obj, SerializationInfo info, StreamingContext targetObj.Age = info.GetInt32("Age"); // Formatterは, この戻り値を無視するので戻り値はnullで良い. - return null; + // C# 8.0 からの Nullable Reference Types の仕様によりnullを返却できないので object を返しておく. + return new object(); } } From 2e86bd44dd8dcb71c305b96ac51bbfa0d6fe6867 Mon Sep 17 00:00:00 2001 From: devlights Date: Wed, 9 Mar 2022 04:44:46 +0000 Subject: [PATCH 24/38] Fix warnings --- TryCSharp.Tools.Cui/CuiOutputManager.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TryCSharp.Tools.Cui/CuiOutputManager.cs b/TryCSharp.Tools.Cui/CuiOutputManager.cs index 2e10a0d..a943b20 100644 --- a/TryCSharp.Tools.Cui/CuiOutputManager.cs +++ b/TryCSharp.Tools.Cui/CuiOutputManager.cs @@ -13,13 +13,13 @@ public class CuiOutputManager : IOutputManager /// 指定されたデータを出力します。(改行付与無し) /// /// データ - public void Write(object data) => Console.Write(data); + public void Write(object? data) => Console.Write(data); /// /// 指定されたデータを出力します。(改行付与有り) /// /// データ - public void WriteLine(object data) => Console.WriteLine(data); + public void WriteLine(object? data) => Console.WriteLine(data); /// /// 出力ストリーム From 734680ea3005ed895a6b52f59ac61aa914804340 Mon Sep 17 00:00:00 2001 From: devlights Date: Wed, 9 Mar 2022 04:50:47 +0000 Subject: [PATCH 25/38] Fix warnings --- TryCSharp.Samples/Async/Channels/ChannelIntroduction.cs | 2 +- TryCSharp.Samples/Collections/QueueSynchronizedSamples01.cs | 3 +-- TryCSharp.Samples/NetWorking/PingSamples01.cs | 5 +++++ TryCSharp.Samples/Serialization/XmlSerializerSamples01.cs | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/TryCSharp.Samples/Async/Channels/ChannelIntroduction.cs b/TryCSharp.Samples/Async/Channels/ChannelIntroduction.cs index d9b9558..5ea8c36 100644 --- a/TryCSharp.Samples/Async/Channels/ChannelIntroduction.cs +++ b/TryCSharp.Samples/Async/Channels/ChannelIntroduction.cs @@ -399,7 +399,7 @@ public async ValueTask ReadAsync(CancellationToken token = default) { await this._semaphore.WaitAsync(token).ConfigureAwait(false); this._queue.TryDequeue(out var item); - return item; + return item!; } } } diff --git a/TryCSharp.Samples/Collections/QueueSynchronizedSamples01.cs b/TryCSharp.Samples/Collections/QueueSynchronizedSamples01.cs index 311f54f..3985381 100644 --- a/TryCSharp.Samples/Collections/QueueSynchronizedSamples01.cs +++ b/TryCSharp.Samples/Collections/QueueSynchronizedSamples01.cs @@ -11,11 +11,10 @@ namespace TryCSharp.Samples.Collections [Sample] public class QueueSynchronizedSamples01 : IExecutable { - private Queue _queue; + private Queue _queue = Queue.Synchronized(new Queue()); public void Execute() { - _queue = Queue.Synchronized(new Queue()); Output.WriteLine("Queue.IsSyncronized == {0}", _queue.IsSynchronized); for (var i = 0; i < 1000; i++) diff --git a/TryCSharp.Samples/NetWorking/PingSamples01.cs b/TryCSharp.Samples/NetWorking/PingSamples01.cs index 4ebb706..a572ff7 100644 --- a/TryCSharp.Samples/NetWorking/PingSamples01.cs +++ b/TryCSharp.Samples/NetWorking/PingSamples01.cs @@ -50,6 +50,11 @@ public void Execute() return; } + if (e.Reply == null) + { + return; + } + if (e.Reply.Status != IPStatus.Success) { Output.WriteLine("Ping.SendAsync() Failed"); diff --git a/TryCSharp.Samples/Serialization/XmlSerializerSamples01.cs b/TryCSharp.Samples/Serialization/XmlSerializerSamples01.cs index ff236f6..f39d54d 100644 --- a/TryCSharp.Samples/Serialization/XmlSerializerSamples01.cs +++ b/TryCSharp.Samples/Serialization/XmlSerializerSamples01.cs @@ -37,7 +37,7 @@ public void Execute() [XmlRoot(ElementName = "Data")] public class XmlSerializerSamples01_Data { - internal string _stringProperty1; + internal string _stringProperty1 = string.Empty; public XmlSerializerSamples01_Data() { From b5441b17b2689c36af4b9da62a1456378961d3a3 Mon Sep 17 00:00:00 2001 From: devlights Date: Wed, 9 Mar 2022 07:24:38 +0000 Subject: [PATCH 26/38] Update README --- README.md | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4d3431a..0867553 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,38 @@ This is my TUTORIAL project for csharp. (dotnet core) [![CodeFactor](https://www.codefactor.io/repository/github/devlights/try-csharp/badge)](https://www.codefactor.io/repository/github/devlights/try-csharp) [![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/devlights/try-csharp) -# Run (IDE) +## Version + +```sh +$ dotnet --info +.NET SDK (reflecting any global.json): + Version: 6.0.100 + Commit: 9e8b04bbff + +Runtime Environment: + OS Name: ubuntu + OS Version: 20.04 + OS Platform: Linux + RID: ubuntu.20.04-x64 + Base Path: /home/gitpod/dotnet/sdk/6.0.100/ + +Host (useful for support): + Version: 6.0.0 + Commit: 4822e3c3aa + +.NET SDKs installed: + 6.0.100 [/home/gitpod/dotnet/sdk] + +.NET runtimes installed: + Microsoft.AspNetCore.App 6.0.0 [/home/gitpod/dotnet/shared/Microsoft.AspNetCore.App] + Microsoft.NETCore.App 6.0.0 [/home/gitpod/dotnet/shared/Microsoft.NETCore.App] +``` + +## Run (IDE) + set TryCSharp.Tools.Cui project as 'startup project' + run onto IDE -# Run (CLI) +## Run (CLI) ```sh $ cd TryCSharp.Tools.Cui From d03e002ee8f3bf2ee5fe534711f56f49800e7af2 Mon Sep 17 00:00:00 2001 From: devlights Date: Wed, 9 Mar 2022 07:24:44 +0000 Subject: [PATCH 27/38] Update Gitpod config files --- .gitpod.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.gitpod.yml b/.gitpod.yml index 03a7a10..da358e3 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -2,11 +2,8 @@ image: gitpod/workspace-dotnet-lts:latest tasks: - - name: dotnet version - init: | - dotnet --info - name: dotnet restore - command: make restore + init: make restore vscode: extensions: From 2db62a2c90347dede0b7cac9b860304b92fcc839 Mon Sep 17 00:00:00 2001 From: devlights Date: Thu, 10 Mar 2022 01:48:49 +0000 Subject: [PATCH 28/38] Update comments --- TryCSharp.Samples/Async/Channels/ChannelBasicReadWrite.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TryCSharp.Samples/Async/Channels/ChannelBasicReadWrite.cs b/TryCSharp.Samples/Async/Channels/ChannelBasicReadWrite.cs index 00afb13..f28c7c2 100644 --- a/TryCSharp.Samples/Async/Channels/ChannelBasicReadWrite.cs +++ b/TryCSharp.Samples/Async/Channels/ChannelBasicReadWrite.cs @@ -24,8 +24,8 @@ public async Task Execute() // System.Threading.Channels は、標準ライブラリとしては // 搭載されていないライブラリ。インストールにはNuGetを利用する。 // - // 2020-04-19 時点での最新安定版は v4.7.0 - // prerelease として、v5.0.0 が出ている。 + // 2020-04-19 時点での最新安定版は v4.7.0prerelease として、v5.0.0 が出ている。 + // (2022-03-10現在 .NET 6 には標準搭載されている。.NET Core 3から標準ライブラリに入った) // // System.Threading.Channels を利用すると // Goの チャネル のような使い勝手で非同期データ処理が行える。 From 3aa37ea8272f9dc2b9cded7b77734d9207c72ff8 Mon Sep 17 00:00:00 2001 From: devlights Date: Thu, 10 Mar 2022 01:54:53 +0000 Subject: [PATCH 29/38] Fix warnings --- TryCSharp.Common/Output.cs | 7 ++++++- TryCSharp.Samples/Basic/ArraySamples01.cs | 6 +++--- TryCSharp.Samples/Basic/ArraySegmentSamples01.cs | 4 ++-- TryCSharp.Samples/Basic/CallerInformationSamples01.cs | 4 ++-- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/TryCSharp.Common/Output.cs b/TryCSharp.Common/Output.cs index 9de1995..f9e9523 100644 --- a/TryCSharp.Common/Output.cs +++ b/TryCSharp.Common/Output.cs @@ -81,13 +81,18 @@ public static void WriteLine(object? data) /// /// フォーマット /// フォーマット引数 - public static void WriteLine(string format, params object?[] arg) + public static void WriteLine(string? format, params object?[] arg) { if (OutputManager == null) { throw new InvalidOperationException("No OutputManager was found. "); } + if (format == null) + { + throw new ArgumentNullException("format"); + } + OutputManager.WriteLine(string.Format(format, arg)); } } diff --git a/TryCSharp.Samples/Basic/ArraySamples01.cs b/TryCSharp.Samples/Basic/ArraySamples01.cs index 9fd56d2..1a29ed9 100644 --- a/TryCSharp.Samples/Basic/ArraySamples01.cs +++ b/TryCSharp.Samples/Basic/ArraySamples01.cs @@ -25,7 +25,7 @@ public class ArraySamples01 : IExecutable { public void Execute() { - string[] ary = {"hoge", "hehe", "fuga"}; + string?[] ary = {"hoge", "hehe", "fuga"}; /////////////////////////////////////////////////////// // @@ -85,7 +85,7 @@ public void Execute() Array.ForEach( Array.FindAll( ary, - element => int.Parse(element)%2 != 0 + element => int.Parse(element!)%2 != 0 ), element => Output.WriteLine(element)); @@ -106,7 +106,7 @@ public void Execute() Array.ForEach( Array.ConvertAll( ary, - element => int.Parse(element) + element => int.Parse(element!) ), element => Output.WriteLine("Type={0}, Value={1}", element.GetType().FullName, element) ); diff --git a/TryCSharp.Samples/Basic/ArraySegmentSamples01.cs b/TryCSharp.Samples/Basic/ArraySegmentSamples01.cs index 5b5403f..debe808 100644 --- a/TryCSharp.Samples/Basic/ArraySegmentSamples01.cs +++ b/TryCSharp.Samples/Basic/ArraySegmentSamples01.cs @@ -41,12 +41,12 @@ public void Execute() // for (var i = 0; i < segment1.Count; i++) { - Output.WriteLine(segment1.Array[segment1.Offset + i]); + Output.WriteLine(segment1.Array![segment1.Offset + i]); } for (var i = segment2.Offset; i < segment2.Offset + segment2.Count; i++) { - Output.WriteLine(segment2.Array[i]); + Output.WriteLine(segment2.Array![i]); } // diff --git a/TryCSharp.Samples/Basic/CallerInformationSamples01.cs b/TryCSharp.Samples/Basic/CallerInformationSamples01.cs index bf7fffd..e56d255 100644 --- a/TryCSharp.Samples/Basic/CallerInformationSamples01.cs +++ b/TryCSharp.Samples/Basic/CallerInformationSamples01.cs @@ -69,7 +69,7 @@ internal class CallerInfoManager /// /// ファイルパス /// - public string FilePath { get; private set; } + public string? FilePath { get; private set; } /// /// 行番号 @@ -79,7 +79,7 @@ internal class CallerInfoManager /// /// メンバー名 /// - public string MemberName { get; private set; } + public string? MemberName { get; private set; } /// /// 現在のコンテキストでのCaller Informationをスナップします。 From 07c51cd47e65798b01021cc5b852102816cb38d1 Mon Sep 17 00:00:00 2001 From: devlights Date: Fri, 11 Mar 2022 01:30:45 +0000 Subject: [PATCH 30/38] Update csproj --- TryCSharp.Samples/TryCSharp.Samples.csproj | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/TryCSharp.Samples/TryCSharp.Samples.csproj b/TryCSharp.Samples/TryCSharp.Samples.csproj index 4c73325..5536738 100644 --- a/TryCSharp.Samples/TryCSharp.Samples.csproj +++ b/TryCSharp.Samples/TryCSharp.Samples.csproj @@ -27,10 +27,5 @@ - - - - - - + From dfd781284cb7fc20d84afd470231ce9b8dcdbeba Mon Sep 17 00:00:00 2001 From: devlights Date: Fri, 11 Mar 2022 02:14:47 +0000 Subject: [PATCH 31/38] Fix warnings --- .../Basic/CallerInformationSamples02.cs | 6 +++--- TryCSharp.Samples/Basic/ComparerSamples01.cs | 13 +++++++++---- TryCSharp.Samples/Basic/DynamicObjectSamples01.cs | 9 +++++++-- .../Basic/EqualityComparerSamples01.cs | 6 +++--- TryCSharp.Samples/Basic/EventSettingSamples01.cs | 2 +- TryCSharp.Samples/Basic/ExpandoObjectSamples03.cs | 2 +- TryCSharp.Samples/Basic/ExpandoObjectSamples04.cs | 4 ++-- TryCSharp.Samples/Basic/ExtensionMethodSample01.cs | 4 ++-- TryCSharp.Samples/Basic/IComparableSamples01.cs | 7 ++++++- TryCSharp.Samples/Basic/IEquatableSamples01.cs | 4 ++-- TryCSharp.Samples/Basic/LazyInitializerSamples01.cs | 2 +- .../Basic/StringIsNullOrWhiteSpaceSamples01.cs | 2 +- .../CSharp7/MoreExpressionBodiedMembers.cs | 2 +- .../CSharp7/PatternVariableWithIsOperator.cs | 10 +++++----- .../CSharp7/PatternVariableWithSwitchStatement.cs | 2 +- TryCSharp.Samples/IO/ZipFileSamples02.cs | 5 +++++ TryCSharp.Samples/IO/ZipFileSamples03.cs | 5 +++++ 17 files changed, 55 insertions(+), 30 deletions(-) diff --git a/TryCSharp.Samples/Basic/CallerInformationSamples02.cs b/TryCSharp.Samples/Basic/CallerInformationSamples02.cs index d3a5f0f..aac964b 100644 --- a/TryCSharp.Samples/Basic/CallerInformationSamples02.cs +++ b/TryCSharp.Samples/Basic/CallerInformationSamples02.cs @@ -13,7 +13,7 @@ public void Execute() // var notifyObj = new NotityPropertyChangedImpl(); - notifyObj.PropertyChanged += (s, e) => { Output.WriteLine("[{0}] changed to [{1}]", e.PropertyName, (s as dynamic).Name); }; + notifyObj.PropertyChanged += (s, e) => { Output.WriteLine("[{0}] changed to [{1}]", e.PropertyName, (s as dynamic)!.Name); }; notifyObj.Name = "hello world"; notifyObj.Name = "goobye world"; @@ -22,7 +22,7 @@ public void Execute() // INotifyPropertyChangedインターフェースの実装 private class NotityPropertyChangedImpl : INotifyPropertyChanged { - private string _name; + private string _name = string.Empty; public string Name { @@ -41,7 +41,7 @@ public string Name } } - public event PropertyChangedEventHandler PropertyChanged; + public event PropertyChangedEventHandler? PropertyChanged; #region OnPropertyChanged diff --git a/TryCSharp.Samples/Basic/ComparerSamples01.cs b/TryCSharp.Samples/Basic/ComparerSamples01.cs index d6afeb4..70ab06f 100644 --- a/TryCSharp.Samples/Basic/ComparerSamples01.cs +++ b/TryCSharp.Samples/Basic/ComparerSamples01.cs @@ -56,6 +56,11 @@ private enum CompareResult private class Person { + public Person() + { + Name = string.Empty; + } + public int Id { get; set; } public string Name { get; set; } @@ -76,15 +81,15 @@ public override string ToString() // private class PersonIdComparer : Comparer { - public override int Compare(Person x, Person y) + public override int Compare(Person? x, Person? y) { if (Equals(x, y)) { return (int) CompareResult.EQUAL; } - var xId = x.Id; - var yId = y.Id; + var xId = x!.Id; + var yId = y!.Id; return xId.CompareTo(yId); } @@ -92,7 +97,7 @@ public override int Compare(Person x, Person y) private class PersonNameComparer : Comparer { - public override int Compare(Person x, Person y) + public override int Compare(Person? x, Person? y) { if (Equals(x, y)) { diff --git a/TryCSharp.Samples/Basic/DynamicObjectSamples01.cs b/TryCSharp.Samples/Basic/DynamicObjectSamples01.cs index 240269c..1932724 100644 --- a/TryCSharp.Samples/Basic/DynamicObjectSamples01.cs +++ b/TryCSharp.Samples/Basic/DynamicObjectSamples01.cs @@ -40,7 +40,7 @@ public MyDynamicObject() _memberMappings = new Dictionary(); } - public override bool TryGetMember(GetMemberBinder binder, out object result) + public override bool TryGetMember(GetMemberBinder binder, out object? result) { result = null; @@ -54,8 +54,13 @@ public override bool TryGetMember(GetMemberBinder binder, out object result) return false; } - public override bool TrySetMember(SetMemberBinder binder, object value) + public override bool TrySetMember(SetMemberBinder binder, object? value) { + if (value == null) + { + return true; + } + var name = binder.Name.ToUpper(); if (_memberMappings.ContainsKey(name)) { diff --git a/TryCSharp.Samples/Basic/EqualityComparerSamples01.cs b/TryCSharp.Samples/Basic/EqualityComparerSamples01.cs index 96e9a4d..63fa059 100644 --- a/TryCSharp.Samples/Basic/EqualityComparerSamples01.cs +++ b/TryCSharp.Samples/Basic/EqualityComparerSamples01.cs @@ -168,7 +168,7 @@ public override string ToString() private class DataEqualityComparer : EqualityComparer { - public override bool Equals(Data x, Data y) + public override bool Equals(Data? x, Data? y) { if (x == null && y == null) { @@ -206,7 +206,7 @@ public Data2(string name, string value) public string Value { get; private set; } - public bool Equals(Data2 other) + public bool Equals(Data2? other) { if (other == null) { @@ -216,7 +216,7 @@ public bool Equals(Data2 other) return other.Name == Name; } - public override bool Equals(object other) + public override bool Equals(object? other) { var data = other as Data2; if (data == null) diff --git a/TryCSharp.Samples/Basic/EventSettingSamples01.cs b/TryCSharp.Samples/Basic/EventSettingSamples01.cs index 02b5350..5897f79 100644 --- a/TryCSharp.Samples/Basic/EventSettingSamples01.cs +++ b/TryCSharp.Samples/Basic/EventSettingSamples01.cs @@ -33,7 +33,7 @@ public Sample() public EventHandlerList Events { get; set; } - public event EventHandler TestEvent; + public event EventHandler? TestEvent; public void FireEvents() { diff --git a/TryCSharp.Samples/Basic/ExpandoObjectSamples03.cs b/TryCSharp.Samples/Basic/ExpandoObjectSamples03.cs index 95fbe8a..978d816 100644 --- a/TryCSharp.Samples/Basic/ExpandoObjectSamples03.cs +++ b/TryCSharp.Samples/Basic/ExpandoObjectSamples03.cs @@ -28,7 +28,7 @@ public void Execute() // // 定義されているメンバーを列挙. // - var map = obj as IDictionary; + var map = (IDictionary) obj; foreach (var pair in map) { Output.WriteLine("{0}={1}", pair.Key, pair.Value); diff --git a/TryCSharp.Samples/Basic/ExpandoObjectSamples04.cs b/TryCSharp.Samples/Basic/ExpandoObjectSamples04.cs index 2e5d0a1..59cdbcb 100644 --- a/TryCSharp.Samples/Basic/ExpandoObjectSamples04.cs +++ b/TryCSharp.Samples/Basic/ExpandoObjectSamples04.cs @@ -25,7 +25,7 @@ public void Execute() // // イベントハンドラ設定. // - (obj as INotifyPropertyChanged).PropertyChanged += (sender, e) => { Output.WriteLine("Property Changed:{0}", e.PropertyName); }; + (obj as INotifyPropertyChanged)!.PropertyChanged += (sender, e) => { Output.WriteLine("Property Changed:{0}", e.PropertyName); }; // // メンバー定義. @@ -36,7 +36,7 @@ public void Execute() // // メンバー削除. // - (obj as IDictionary).Remove("Age"); + (obj as IDictionary)!.Remove("Age"); // // 値変更. diff --git a/TryCSharp.Samples/Basic/ExtensionMethodSample01.cs b/TryCSharp.Samples/Basic/ExtensionMethodSample01.cs index d390dd1..9dc4d29 100644 --- a/TryCSharp.Samples/Basic/ExtensionMethodSample01.cs +++ b/TryCSharp.Samples/Basic/ExtensionMethodSample01.cs @@ -12,7 +12,7 @@ public class ExtensionMethodSample01 : IExecutable [SuppressMessage("ReSharper", "ExpressionIsAlwaysNull")] public void Execute() { - string s = null; + string? s = null; s.PrintMyName(); } } @@ -20,7 +20,7 @@ public void Execute() // ReSharper disable once InconsistentNaming internal static class ExtensionMethodSample01_ExtClass { - public static void PrintMyName(this string self) + public static void PrintMyName(this string? self) { Output.WriteLine(self == null); Output.WriteLine("GSF-ZERO1."); diff --git a/TryCSharp.Samples/Basic/IComparableSamples01.cs b/TryCSharp.Samples/Basic/IComparableSamples01.cs index b09a970..5a50b5e 100644 --- a/TryCSharp.Samples/Basic/IComparableSamples01.cs +++ b/TryCSharp.Samples/Basic/IComparableSamples01.cs @@ -65,10 +65,15 @@ private enum CompareResult private class Person : IComparable { + public Person() + { + Name = string.Empty; + } + public int Id { get; set; } public string Name { get; set; } - public int CompareTo(Person other) + public int CompareTo(Person? other) { if (other == null) { diff --git a/TryCSharp.Samples/Basic/IEquatableSamples01.cs b/TryCSharp.Samples/Basic/IEquatableSamples01.cs index 2072c33..e4f2fa0 100644 --- a/TryCSharp.Samples/Basic/IEquatableSamples01.cs +++ b/TryCSharp.Samples/Basic/IEquatableSamples01.cs @@ -70,7 +70,7 @@ public Data(int id, string name) public string Name { get; private set; } // IEquatableの実装. - public bool Equals(Data other) + public bool Equals(Data? other) { Output.WriteLine("\t→→Call IEquatable.Equals"); @@ -78,7 +78,7 @@ public bool Equals(Data other) } // object.Equals - public override bool Equals(object other) + public override bool Equals(object? other) { Output.WriteLine("\t→→Call object.Equals"); diff --git a/TryCSharp.Samples/Basic/LazyInitializerSamples01.cs b/TryCSharp.Samples/Basic/LazyInitializerSamples01.cs index 53d1302..59c2e8d 100644 --- a/TryCSharp.Samples/Basic/LazyInitializerSamples01.cs +++ b/TryCSharp.Samples/Basic/LazyInitializerSamples01.cs @@ -40,7 +40,7 @@ public void Execute() private class HasHeavyData { - private HeavyObject _heavy; + private HeavyObject? _heavy; public HeavyObject Heavy { diff --git a/TryCSharp.Samples/Basic/StringIsNullOrWhiteSpaceSamples01.cs b/TryCSharp.Samples/Basic/StringIsNullOrWhiteSpaceSamples01.cs index ef93448..099756b 100644 --- a/TryCSharp.Samples/Basic/StringIsNullOrWhiteSpaceSamples01.cs +++ b/TryCSharp.Samples/Basic/StringIsNullOrWhiteSpaceSamples01.cs @@ -17,7 +17,7 @@ public void Execute() // String::IsNullOrWhiteSpaceメソッドは、IsNullOrEmptyメソッドの動作に // 加え、更に空白文字のみの場合もチェックしてくれる。 // - string nullStr = null; + string? nullStr = null; var emptyStr = string.Empty; var spaceStr = " "; var normalStr = "hello world"; diff --git a/TryCSharp.Samples/CSharp7/MoreExpressionBodiedMembers.cs b/TryCSharp.Samples/CSharp7/MoreExpressionBodiedMembers.cs index 406cc3a..f9af469 100644 --- a/TryCSharp.Samples/CSharp7/MoreExpressionBodiedMembers.cs +++ b/TryCSharp.Samples/CSharp7/MoreExpressionBodiedMembers.cs @@ -9,7 +9,7 @@ class Data { private string _value; - public Data(string val) => this.Value = val; + public Data(string val) => this._value = val; public string UpperCaseValue => this.Value.ToUpper(); diff --git a/TryCSharp.Samples/CSharp7/PatternVariableWithIsOperator.cs b/TryCSharp.Samples/CSharp7/PatternVariableWithIsOperator.cs index a31659e..e2b6f8c 100644 --- a/TryCSharp.Samples/CSharp7/PatternVariableWithIsOperator.cs +++ b/TryCSharp.Samples/CSharp7/PatternVariableWithIsOperator.cs @@ -9,12 +9,12 @@ public class PatternVariableWithIsOperator : IExecutable { private class MyInnerClass { - public MyInnerClass(MyInnerClass2 inner) + public MyInnerClass(MyInnerClass2? inner) { this.Inner = inner; } - public MyInnerClass2 Inner { get; } + public MyInnerClass2? Inner { get; } } private class MyInnerClass2 @@ -36,7 +36,7 @@ public void Execute() if (x is string) { // ReSharper disable once TryCastAlwaysSucceeds - var cs6 = x as string; + var cs6 = (string) x; Output.WriteLine($"C# 6.0 val:{cs6}, length:{cs6.Length}"); } @@ -48,7 +48,7 @@ public void Execute() // - var pattern // // constant pattern - object y = null; + object? y = null; if (y is null) { Output.WriteLine("y is null."); @@ -97,7 +97,7 @@ public void Execute() // var pattern はちょっと特殊。 // これは、null のときも含めて is 演算子の評価が常にTrueとなって、var で宣言した変数に入る - if (innerB.Inner is var j) + if (innerB?.Inner is var j) { Output.WriteLine($"j is null [{j == null}]"); } diff --git a/TryCSharp.Samples/CSharp7/PatternVariableWithSwitchStatement.cs b/TryCSharp.Samples/CSharp7/PatternVariableWithSwitchStatement.cs index dfd0f6d..77bf806 100644 --- a/TryCSharp.Samples/CSharp7/PatternVariableWithSwitchStatement.cs +++ b/TryCSharp.Samples/CSharp7/PatternVariableWithSwitchStatement.cs @@ -18,7 +18,7 @@ public void Execute() [SuppressMessage("ReSharper", "RedundantBoolCompare")] [SuppressMessage("ReSharper", "RedundantStringInterpolation")] - private void SwitchWithPattern(object x) + private void SwitchWithPattern(object? x) { // 型で振り分け switch (x) diff --git a/TryCSharp.Samples/IO/ZipFileSamples02.cs b/TryCSharp.Samples/IO/ZipFileSamples02.cs index be58b91..647553e 100644 --- a/TryCSharp.Samples/IO/ZipFileSamples02.cs +++ b/TryCSharp.Samples/IO/ZipFileSamples02.cs @@ -24,6 +24,11 @@ public class ZipFileSamples02 : IExecutable private string DesktopPath => Environment.GetFolderPath(Environment.SpecialFolder.Desktop); + public ZipFileSamples02() + { + _zipFilePath = string.Empty; + } + public void Execute() { // diff --git a/TryCSharp.Samples/IO/ZipFileSamples03.cs b/TryCSharp.Samples/IO/ZipFileSamples03.cs index 5a1f791..2033bee 100644 --- a/TryCSharp.Samples/IO/ZipFileSamples03.cs +++ b/TryCSharp.Samples/IO/ZipFileSamples03.cs @@ -25,6 +25,11 @@ public class ZipFileSamples03 : IExecutable private string DesktopPath => Environment.GetFolderPath(Environment.SpecialFolder.Desktop); + public ZipFileSamples03() + { + _zipFilePath = string.Empty; + } + public void Execute() { // From b61cdfd9c8187bdf2c9c9b1216d781ded6be0038 Mon Sep 17 00:00:00 2001 From: devlights Date: Fri, 11 Mar 2022 08:17:34 +0000 Subject: [PATCH 32/38] Fix warnings --- .../Reflection/Emit/EmitSample01.cs | 8 ++++---- .../Reflection/Emit/EmitSample02.cs | 4 ++-- .../Reflection/Emit/EmitSample03.cs | 6 +++--- .../HasByRefParameterMethodReflectionSample.cs | 2 +- .../Reflection/ReflectionSample01.cs | 4 ++-- .../Reflection/ReflectionSample02.cs | 8 ++++---- .../Reflection/ReflectionSample03.cs | 4 ++++ TryCSharp.Samples/Threading/BarrierSamples02.cs | 5 ++--- .../Threading/CancellationTokenSamples01.cs | 6 ++++-- .../Threading/CountdownEventSamples02.cs | 2 +- .../Threading/CountdownEventSamples04.cs | 2 +- .../Threading/ManualResetEventSlimSamples01.cs | 2 +- TryCSharp.Samples/Threading/ThreadPoolSample.cs | 7 ++++++- TryCSharp.Samples/Threading/ThreadSample.cs | 7 ++++++- .../Threading/ThreadStaticAttributeSamples01.cs | 4 ++-- .../Threading/ThreadingNamespaceSamples01.cs | 17 ++++++++++------- .../Threading/ThreadingNamespaceSamples02.cs | 4 ++-- .../Threading/ThreadingNamespaceSamples04.cs | 4 ++-- .../Threading/ThreadingNamespaceSamples05.cs | 2 +- 19 files changed, 58 insertions(+), 40 deletions(-) diff --git a/TryCSharp.Samples/Reflection/Emit/EmitSample01.cs b/TryCSharp.Samples/Reflection/Emit/EmitSample01.cs index 2d93dcc..f40c733 100644 --- a/TryCSharp.Samples/Reflection/Emit/EmitSample01.cs +++ b/TryCSharp.Samples/Reflection/Emit/EmitSample01.cs @@ -42,13 +42,13 @@ public void Execute() // var methodAttr = MethodAttributes.Public | MethodAttributes.Virtual; var methodBuilder = typeBuilder.DefineMethod("SayHello", methodAttr, typeof(void), new Type[] {}); - typeBuilder.DefineMethodOverride(methodBuilder, typeof(ISayHello).GetMethod("SayHello")); + typeBuilder.DefineMethodOverride(methodBuilder, typeof(ISayHello).GetMethod("SayHello")!); // // 5.ILGeneratorを生成し、ILコードを設定. // var il = methodBuilder.GetILGenerator(); il.Emit(OpCodes.Ldstr, "Hello World"); - il.Emit(OpCodes.Call, typeof(Console).GetMethod("WriteLine", new[] {typeof(string)})); + il.Emit(OpCodes.Call, typeof(Console).GetMethod("WriteLine", new[] {typeof(string)})!); il.Emit(OpCodes.Ret); // // 6.作成した型を取得. @@ -57,11 +57,11 @@ public void Execute() // // 7.型を具現化. // - var hello = (ISayHello) Activator.CreateInstance(type); + var hello = (ISayHello?) Activator.CreateInstance(type!); // // 8.実行. // - hello.SayHello(); + hello?.SayHello(); } public interface ISayHello diff --git a/TryCSharp.Samples/Reflection/Emit/EmitSample02.cs b/TryCSharp.Samples/Reflection/Emit/EmitSample02.cs index db6795a..5cd5aac 100644 --- a/TryCSharp.Samples/Reflection/Emit/EmitSample02.cs +++ b/TryCSharp.Samples/Reflection/Emit/EmitSample02.cs @@ -89,11 +89,11 @@ public void Execute() // // 13.型を具現化. // - var withPropObj = Activator.CreateInstance(type); + var withPropObj = Activator.CreateInstance(type!); // // 14.実行. // - var propInfo = type.GetProperty("Message"); + var propInfo = type!.GetProperty("Message"); propInfo?.SetValue(withPropObj, "HelloWorld", null); Output.WriteLine(propInfo?.GetValue(withPropObj, null)); } diff --git a/TryCSharp.Samples/Reflection/Emit/EmitSample03.cs b/TryCSharp.Samples/Reflection/Emit/EmitSample03.cs index d5a2012..b5653a4 100644 --- a/TryCSharp.Samples/Reflection/Emit/EmitSample03.cs +++ b/TryCSharp.Samples/Reflection/Emit/EmitSample03.cs @@ -38,9 +38,9 @@ public void Execute() AddAttribute(typeBuilder, typeof(CreatorAttribute), new[] {typeof(string)}, new object[] {"gsf.zero1"}); var type = typeBuilder.CreateType(); - Activator.CreateInstance(type); + Activator.CreateInstance(type!); - var attrs = type.GetCustomAttributes(true); + var attrs = type!.GetCustomAttributes(true); if (attrs.Length > 0) { foreach (var attr in attrs) @@ -49,7 +49,7 @@ public void Execute() if (attr is CreatorAttribute) { - Output.WriteLine("\tName={0}", (attr as CreatorAttribute).CreatorName); + Output.WriteLine("\tName={0}", ((CreatorAttribute)attr).CreatorName); } } } diff --git a/TryCSharp.Samples/Reflection/HasByRefParameterMethodReflectionSample.cs b/TryCSharp.Samples/Reflection/HasByRefParameterMethodReflectionSample.cs index 9cd1dd0..2e06e8b 100644 --- a/TryCSharp.Samples/Reflection/HasByRefParameterMethodReflectionSample.cs +++ b/TryCSharp.Samples/Reflection/HasByRefParameterMethodReflectionSample.cs @@ -14,7 +14,7 @@ public void Execute() { var type = typeof(HasByRefParameterMethodReflectionSample); var flags = BindingFlags.NonPublic | BindingFlags.Instance; - Type[] paramTypes = {typeof(string), Type.GetType("System.Int32&"), typeof(int)}; + Type[] paramTypes = {typeof(string), Type.GetType("System.Int32&")!, typeof(int)}; var methodInfo = type.GetMethod("SetPropertyValue", flags, null, paramTypes, null); Output.WriteLine(methodInfo); diff --git a/TryCSharp.Samples/Reflection/ReflectionSample01.cs b/TryCSharp.Samples/Reflection/ReflectionSample01.cs index 998de05..e890645 100644 --- a/TryCSharp.Samples/Reflection/ReflectionSample01.cs +++ b/TryCSharp.Samples/Reflection/ReflectionSample01.cs @@ -48,8 +48,8 @@ public void Execute() typeName = "System.Collections.Generic.List`1"; var type6 = Type.GetType(typeName); - Type type7 = null; - if (type6.IsGenericType && type6.IsGenericTypeDefinition) + Type? type7 = null; + if (type6!.IsGenericType && type6.IsGenericTypeDefinition) { type7 = type6.MakeGenericType(typeof(string)); } diff --git a/TryCSharp.Samples/Reflection/ReflectionSample02.cs b/TryCSharp.Samples/Reflection/ReflectionSample02.cs index 848fdfe..bf6b89a 100644 --- a/TryCSharp.Samples/Reflection/ReflectionSample02.cs +++ b/TryCSharp.Samples/Reflection/ReflectionSample02.cs @@ -19,21 +19,21 @@ public void Execute() // Activatorを利用してインスタンス化.(Typeのみの指定) // var obj = Activator.CreateInstance(type); - Output.WriteLine(obj.GetType()); + Output.WriteLine(obj!.GetType()); // // Activatorを利用してインスタンス化.(Assembly名と型名) // この場合、戻り値はSystem.Runtime.Remoting.ObjectHandleになります。 // - obj = Activator.CreateInstance(Assembly.GetAssembly(type).GetType(), type.FullName); - Output.WriteLine(obj.GetType()); + obj = Activator.CreateInstance(Assembly.GetAssembly(type)!.GetType(), type.FullName); + Output.WriteLine(obj!.GetType()); // // Assemblyを利用してインスタンス化. // 以下が使えるのは、対象となるクラスが既に読み込み済みのアセンブリの場合です。 // まだ読み込まれていないアセンブリに含まれるクラスの場合は先にLoadしてから使います。 // - obj = Assembly.GetAssembly(type).CreateInstance(type.FullName); + obj = Assembly.GetAssembly(type)!.CreateInstance(type.FullName!); Output.WriteLine(obj?.GetType()); } } diff --git a/TryCSharp.Samples/Reflection/ReflectionSample03.cs b/TryCSharp.Samples/Reflection/ReflectionSample03.cs index 7ce9012..d6bf54f 100644 --- a/TryCSharp.Samples/Reflection/ReflectionSample03.cs +++ b/TryCSharp.Samples/Reflection/ReflectionSample03.cs @@ -32,6 +32,10 @@ public void Execute() // MethodInfo.Invokeを利用するパターン. // var mi = typeof(string).GetMethod("Trim", new Type[0]); + if (mi == null) + { + return; + } var watch = Stopwatch.StartNew(); for (var i = 0; i < 3000000; i++) diff --git a/TryCSharp.Samples/Threading/BarrierSamples02.cs b/TryCSharp.Samples/Threading/BarrierSamples02.cs index 6829a56..6c42a6b 100644 --- a/TryCSharp.Samples/Threading/BarrierSamples02.cs +++ b/TryCSharp.Samples/Threading/BarrierSamples02.cs @@ -20,11 +20,10 @@ public class BarrierSamples02 : IExecutable // キャンセルトークン. private CancellationToken _token; // キャンセルトークンソース. - private CancellationTokenSource _tokenSource; + private CancellationTokenSource _tokenSource = new CancellationTokenSource(); public void Execute() { - _tokenSource = new CancellationTokenSource(); _token = _tokenSource.Token; // @@ -183,7 +182,7 @@ private bool HandleAggregateException(Exception ex) { if (ex is OperationCanceledException) { - var cancelEx = ex as OperationCanceledException; + var cancelEx = (OperationCanceledException)ex; if (_token == cancelEx.CancellationToken) { Output.WriteLine("***Barrier内の処理がキャンセルされた MESSAGE={0} ***", cancelEx.Message); diff --git a/TryCSharp.Samples/Threading/CancellationTokenSamples01.cs b/TryCSharp.Samples/Threading/CancellationTokenSamples01.cs index ff8ca59..67279ca 100644 --- a/TryCSharp.Samples/Threading/CancellationTokenSamples01.cs +++ b/TryCSharp.Samples/Threading/CancellationTokenSamples01.cs @@ -1,4 +1,5 @@ -using System; +#pragma warning disable SYSLIB0014 +using System; using System.Net; using System.Threading; using System.Threading.Tasks; @@ -291,4 +292,5 @@ private void Work3(CancellationToken cancelToken, ManualResetEventSlim waitHandl } } } -} \ No newline at end of file +} +#pragma warning restore SYSLIB0014 \ No newline at end of file diff --git a/TryCSharp.Samples/Threading/CountdownEventSamples02.cs b/TryCSharp.Samples/Threading/CountdownEventSamples02.cs index 7ed4f7d..078004f 100644 --- a/TryCSharp.Samples/Threading/CountdownEventSamples02.cs +++ b/TryCSharp.Samples/Threading/CountdownEventSamples02.cs @@ -69,7 +69,7 @@ public void Execute() } } - private void TaskProc(object data) + private void TaskProc(object? data) { Output.WriteLine("Task ID={0} 開始", Task.CurrentId); Thread.Sleep(TimeSpan.FromSeconds(new Random().Next(10))); diff --git a/TryCSharp.Samples/Threading/CountdownEventSamples04.cs b/TryCSharp.Samples/Threading/CountdownEventSamples04.cs index 5f57efd..c4e0e4a 100644 --- a/TryCSharp.Samples/Threading/CountdownEventSamples04.cs +++ b/TryCSharp.Samples/Threading/CountdownEventSamples04.cs @@ -123,7 +123,7 @@ private void PrintCurrentCountdownEvent(CountdownEvent cde, string prefix = "") Output.WriteLine("{0}IsSet={1}", prefix, cde.IsSet); } - private void TaskProc(object data) + private void TaskProc(object? data) { // // 処理開始と共に、CountdownEventの内部カウントをインクリメント. diff --git a/TryCSharp.Samples/Threading/ManualResetEventSlimSamples01.cs b/TryCSharp.Samples/Threading/ManualResetEventSlimSamples01.cs index 975d52a..22c923b 100644 --- a/TryCSharp.Samples/Threading/ManualResetEventSlimSamples01.cs +++ b/TryCSharp.Samples/Threading/ManualResetEventSlimSamples01.cs @@ -73,7 +73,7 @@ public void Execute() Output.WriteLine("終了"); } - private void DoProc(object stateObj) + private void DoProc(object? stateObj) { Thread.Sleep(TimeSpan.FromSeconds(1)); Output.Write("*** シグナル状態に設定 *** "); diff --git a/TryCSharp.Samples/Threading/ThreadPoolSample.cs b/TryCSharp.Samples/Threading/ThreadPoolSample.cs index e22eac0..29ae9a0 100644 --- a/TryCSharp.Samples/Threading/ThreadPoolSample.cs +++ b/TryCSharp.Samples/Threading/ThreadPoolSample.cs @@ -20,7 +20,12 @@ public void Execute() { ThreadPool.QueueUserWorkItem(stateInfo => { - var p = stateInfo as StateInfo; + if (stateInfo == null) + { + return; + } + + var p = (StateInfo)stateInfo; Thread.Sleep(150); Output.WriteLine("Thread Count:{0}, Time:{1}", p.Count, p.Time.ToString("hh:mm:ss.fff")); }, diff --git a/TryCSharp.Samples/Threading/ThreadSample.cs b/TryCSharp.Samples/Threading/ThreadSample.cs index 769c9cf..6caf6ed 100644 --- a/TryCSharp.Samples/Threading/ThreadSample.cs +++ b/TryCSharp.Samples/Threading/ThreadSample.cs @@ -61,7 +61,12 @@ public void Execute() // ParameterizedThreadStart pts = data => { - var p = data as ThreadParameter; + if (data == null) + { + return; + } + + var p = (ThreadParameter)data; Thread.Sleep(150); Output.WriteLine("Thread Count:{0}, Time:{1}", p.Count, p.Time.ToString("hh:mm:ss.fff")); }; diff --git a/TryCSharp.Samples/Threading/ThreadStaticAttributeSamples01.cs b/TryCSharp.Samples/Threading/ThreadStaticAttributeSamples01.cs index c6a895c..8123cf9 100644 --- a/TryCSharp.Samples/Threading/ThreadStaticAttributeSamples01.cs +++ b/TryCSharp.Samples/Threading/ThreadStaticAttributeSamples01.cs @@ -48,8 +48,8 @@ public static void DoThreadProcess() // // ThreadStatic属性が付加されたフィールドと共有されたフィールドの両方に値を設定. // - NameAndId = new KeyValuePair(thread.Name, thread.ManagedThreadId); - SharedNameAndId = new KeyValuePair(thread.Name, thread.ManagedThreadId); + NameAndId = new KeyValuePair(thread.Name!, thread.ManagedThreadId); + SharedNameAndId = new KeyValuePair(thread.Name!, thread.ManagedThreadId); Output.WriteLine("[BEFORE] ThreadStatic={0} Shared={1}", NameAndId, SharedNameAndId); diff --git a/TryCSharp.Samples/Threading/ThreadingNamespaceSamples01.cs b/TryCSharp.Samples/Threading/ThreadingNamespaceSamples01.cs index f1d402d..42b9ef3 100644 --- a/TryCSharp.Samples/Threading/ThreadingNamespaceSamples01.cs +++ b/TryCSharp.Samples/Threading/ThreadingNamespaceSamples01.cs @@ -56,7 +56,7 @@ public void Execute() // 設定されていない状態で結果が出力されるはずです。(結果がセットされる前にメイン処理が // 結果確認処理へと進むため)) // - states.ForEach(state => { state.TargetThread.Join(); }); + states.ForEach(state => { state.TargetThread!.Join(); }); // 結果確認. states.ForEach(Output.WriteLine); @@ -83,17 +83,17 @@ public void Execute() thread.Start($"{i}番目のスレッド"); } - states.ForEach(state => { state.TargetThread.Join(); }); + states.ForEach(state => { state.TargetThread!.Join(); }); states.ForEach(Output.WriteLine); } private class ThreadStartDelegateState { - public Thread TargetThread { get; set; } + public Thread? TargetThread { get; set; } - public string ArgumentData { get; set; } + public string? ArgumentData { get; set; } - public string ReturnData { get; set; } + public string? ReturnData { get; set; } public void ThreadStartHandlerMethod() { @@ -101,9 +101,12 @@ public void ThreadStartHandlerMethod() ReturnData = Thread.CurrentThread.ManagedThreadId.ToString(); } - public void ParameterizedThreadStartHandlerMethod(object threadArgument) + public void ParameterizedThreadStartHandlerMethod(object? threadArgument) { - ArgumentData = threadArgument as string; + if (threadArgument != null) + { + ArgumentData = (string)threadArgument; + } ThreadStartHandlerMethod(); } diff --git a/TryCSharp.Samples/Threading/ThreadingNamespaceSamples02.cs b/TryCSharp.Samples/Threading/ThreadingNamespaceSamples02.cs index f10da94..5a8f5ff 100644 --- a/TryCSharp.Samples/Threading/ThreadingNamespaceSamples02.cs +++ b/TryCSharp.Samples/Threading/ThreadingNamespaceSamples02.cs @@ -66,7 +66,7 @@ public void Execute() Thread.FreeNamedDataSlot("SampleSlot"); } - private void DoAnonymousDataSlotProcess(object stateObj) + private void DoAnonymousDataSlotProcess(object? stateObj) { var slot = stateObj as LocalDataStoreSlot; if (slot == null) @@ -95,7 +95,7 @@ private void DoAnonymousDataSlotProcess(object stateObj) Output.WriteLine("[AFTER ] Thread:{0} DataSlot:{1}", Thread.CurrentThread.Name, Thread.GetData(slot)); } - private void DoNamedDataSlotProcess(object stateObj) + private void DoNamedDataSlotProcess(object? stateObj) { // // スロットにデータを設定 diff --git a/TryCSharp.Samples/Threading/ThreadingNamespaceSamples04.cs b/TryCSharp.Samples/Threading/ThreadingNamespaceSamples04.cs index 4603668..0af21d9 100644 --- a/TryCSharp.Samples/Threading/ThreadingNamespaceSamples04.cs +++ b/TryCSharp.Samples/Threading/ThreadingNamespaceSamples04.cs @@ -32,9 +32,9 @@ public void Execute() t2.Join(); } - private void ThreadProc(object stateObj) + private void ThreadProc(object? stateObj) { - var threadName = stateObj.ToString(); + var threadName = stateObj!.ToString(); Output.WriteLine("{0} Start", threadName); // diff --git a/TryCSharp.Samples/Threading/ThreadingNamespaceSamples05.cs b/TryCSharp.Samples/Threading/ThreadingNamespaceSamples05.cs index 513c13d..42dc6bc 100644 --- a/TryCSharp.Samples/Threading/ThreadingNamespaceSamples05.cs +++ b/TryCSharp.Samples/Threading/ThreadingNamespaceSamples05.cs @@ -19,7 +19,7 @@ public void Execute() Thread.Sleep(10000); } - private void TimerCallback(object state) + private void TimerCallback(object? state) { Output.WriteLine("Timer Callback!!"); From fc38822712e4a078d1f0b2d933375b783cea31f7 Mon Sep 17 00:00:00 2001 From: devlights Date: Fri, 11 Mar 2022 08:26:25 +0000 Subject: [PATCH 33/38] Fix warnings --- TryCSharp.Samples/Linq/LinqSamples01.cs | 18 +++++++-------- TryCSharp.Samples/Linq/LinqSamples02.cs | 20 ++++++++--------- TryCSharp.Samples/Linq/LinqSamples03.cs | 18 +++++++-------- TryCSharp.Samples/Linq/LinqSamples04.cs | 26 ++++++++++----------- TryCSharp.Samples/Linq/LinqSamples05.cs | 20 ++++++++--------- TryCSharp.Samples/Linq/LinqSamples06.cs | 30 ++++++++++++------------- TryCSharp.Samples/Linq/LinqSamples07.cs | 16 ++++++------- TryCSharp.Samples/Linq/LinqSamples08.cs | 16 ++++++------- TryCSharp.Samples/Linq/LinqSamples09.cs | 22 +++++++++--------- TryCSharp.Samples/Linq/LinqSamples10.cs | 22 +++++++++--------- TryCSharp.Samples/Linq/LinqSamples11.cs | 20 ++++++++--------- 11 files changed, 114 insertions(+), 114 deletions(-) diff --git a/TryCSharp.Samples/Linq/LinqSamples01.cs b/TryCSharp.Samples/Linq/LinqSamples01.cs index 8ea95e8..47f59a1 100644 --- a/TryCSharp.Samples/Linq/LinqSamples01.cs +++ b/TryCSharp.Samples/Linq/LinqSamples01.cs @@ -16,7 +16,7 @@ public void Execute() var persons = CreateSampleData(); var query = from person in persons - where int.Parse(person.Id) >= 2 + where int.Parse(person.Id!) >= 2 select person; try @@ -93,24 +93,24 @@ private IEnumerable CreateSampleData() private class Person { - public string Id { get; set; } + public string? Id { get; set; } - public string Name { get; set; } + public string? Name { get; set; } - public AddressInfo Address { get; set; } + public AddressInfo? Address { get; set; } } private class AddressInfo { - public string PostCode { get; set; } + public string? PostCode { get; set; } - public string Prefecture { get; set; } + public string? Prefecture { get; set; } - public string Municipality { get; set; } + public string? Municipality { get; set; } - public string HouseNumber { get; set; } + public string? HouseNumber { get; set; } - public string Tel { get; set; } + public string? Tel { get; set; } } } } \ No newline at end of file diff --git a/TryCSharp.Samples/Linq/LinqSamples02.cs b/TryCSharp.Samples/Linq/LinqSamples02.cs index 64d4de6..a92dc9c 100644 --- a/TryCSharp.Samples/Linq/LinqSamples02.cs +++ b/TryCSharp.Samples/Linq/LinqSamples02.cs @@ -32,7 +32,7 @@ public void Execute() // 複数のfrom. // var query2 = from person in persons - from tel in person.Address.Tel + from tel in person.Address!.Tel! select new { person.Id, @@ -123,26 +123,26 @@ private IEnumerable CreateSampleData() private class Person { - public string Id { get; set; } + public string? Id { get; set; } - public string Name { get; set; } + public string? Name { get; set; } - public AddressInfo Address { get; set; } + public AddressInfo? Address { get; set; } } private class AddressInfo { - public string PostCode { get; set; } + public string? PostCode { get; set; } - public string Prefecture { get; set; } + public string? Prefecture { get; set; } - public string Municipality { get; set; } + public string? Municipality { get; set; } - public string HouseNumber { get; set; } + public string? HouseNumber { get; set; } - public string[] Tel { get; set; } + public string[]? Tel { get; set; } - public string[] Frends { get; set; } + public string[]? Frends { get; set; } } } } \ No newline at end of file diff --git a/TryCSharp.Samples/Linq/LinqSamples03.cs b/TryCSharp.Samples/Linq/LinqSamples03.cs index 436323d..51963af 100644 --- a/TryCSharp.Samples/Linq/LinqSamples03.cs +++ b/TryCSharp.Samples/Linq/LinqSamples03.cs @@ -105,26 +105,26 @@ private IEnumerable CreateSampleData() private class Person { - public string Id { get; set; } + public string? Id { get; set; } - public string Name { get; set; } + public string? Name { get; set; } - public AddressInfo Address { get; set; } + public AddressInfo? Address { get; set; } } private class AddressInfo { - public string PostCode { get; set; } + public string? PostCode { get; set; } - public string Prefecture { get; set; } + public string? Prefecture { get; set; } - public string Municipality { get; set; } + public string? Municipality { get; set; } - public string HouseNumber { get; set; } + public string? HouseNumber { get; set; } - public string[] Tel { get; set; } + public string[]? Tel { get; set; } - public string[] Frends { get; set; } + public string[]? Frends { get; set; } } } } \ No newline at end of file diff --git a/TryCSharp.Samples/Linq/LinqSamples04.cs b/TryCSharp.Samples/Linq/LinqSamples04.cs index 7f596a8..c41ab59 100644 --- a/TryCSharp.Samples/Linq/LinqSamples04.cs +++ b/TryCSharp.Samples/Linq/LinqSamples04.cs @@ -18,7 +18,7 @@ public void Execute() // 普通に絞り込み. // var query1 = from person in persons - where person.Name.EndsWith("4") + where person.Name!.EndsWith("4") select person; foreach (var person in query1) @@ -30,7 +30,7 @@ where person.Name.EndsWith("4") // 複数の条件. // var query2 = from person in persons - where person.Name.EndsWith("4") || (person.Address.Prefecture == "京都府") + where person.Name!.EndsWith("4") || (person.Address!.Prefecture == "京都府") select person; foreach (var person in query2) @@ -42,8 +42,8 @@ where person.Name.EndsWith("4") || (person.Address.Prefecture == "京都府") // 複数のwhereを指定 // var query3 = from person in persons - where person.Name.Contains("gsf") - where person.Address.Prefecture == "京都府" + where person.Name!.Contains("gsf") + where person.Address!.Prefecture == "京都府" select person; foreach (var person in query3) @@ -117,26 +117,26 @@ private IEnumerable CreateSampleData() private class Person { - public string Id { get; set; } + public string? Id { get; set; } - public string Name { get; set; } + public string? Name { get; set; } - public AddressInfo Address { get; set; } + public AddressInfo? Address { get; set; } } private class AddressInfo { - public string PostCode { get; set; } + public string? PostCode { get; set; } - public string Prefecture { get; set; } + public string? Prefecture { get; set; } - public string Municipality { get; set; } + public string? Municipality { get; set; } - public string HouseNumber { get; set; } + public string? HouseNumber { get; set; } - public string[] Tel { get; set; } + public string[]? Tel { get; set; } - public string[] Frends { get; set; } + public string[]? Frends { get; set; } } } } \ No newline at end of file diff --git a/TryCSharp.Samples/Linq/LinqSamples05.cs b/TryCSharp.Samples/Linq/LinqSamples05.cs index 07ddfec..51808d6 100644 --- a/TryCSharp.Samples/Linq/LinqSamples05.cs +++ b/TryCSharp.Samples/Linq/LinqSamples05.cs @@ -132,28 +132,28 @@ private enum Country private class Person { - public string Id { get; set; } + public string? Id { get; set; } - public string Name { get; set; } + public string? Name { get; set; } - public AddressInfo Address { get; set; } + public AddressInfo? Address { get; set; } - public Country Country { get; set; } + public Country? Country { get; set; } } private class AddressInfo { - public string PostCode { get; set; } + public string? PostCode { get; set; } - public string Prefecture { get; set; } + public string? Prefecture { get; set; } - public string Municipality { get; set; } + public string? Municipality { get; set; } - public string HouseNumber { get; set; } + public string? HouseNumber { get; set; } - public string[] Tel { get; set; } + public string[]? Tel { get; set; } - public string[] Frends { get; set; } + public string[]? Frends { get; set; } } } } \ No newline at end of file diff --git a/TryCSharp.Samples/Linq/LinqSamples06.cs b/TryCSharp.Samples/Linq/LinqSamples06.cs index 296c0b1..846cb73 100644 --- a/TryCSharp.Samples/Linq/LinqSamples06.cs +++ b/TryCSharp.Samples/Linq/LinqSamples06.cs @@ -20,7 +20,7 @@ public void Execute() // (昇順の場合のascendingは付けても付けなくても良い) // var query1 = from person in persons - orderby person.Id.ToInt() ascending + orderby person.Id!.ToInt() ascending select person; Output.WriteLine("============================================"); @@ -33,7 +33,7 @@ orderby person.Id.ToInt() ascending // 降順. // var query2 = from person in persons - orderby person.Id.ToInt() descending + orderby person.Id!.ToInt() descending select person; Output.WriteLine("============================================"); @@ -46,7 +46,7 @@ orderby person.Id.ToInt() descending // 複数の条件でソート. // var query3 = from person in persons - orderby person.Address.PostCode, person.Id.ToInt() + orderby person.Address!.PostCode, person.Id!.ToInt() select person; Output.WriteLine("============================================"); @@ -67,8 +67,8 @@ orderby person.Id.ToInt() descending // され直されてしまう。 // var query4 = from person in persons - orderby person.Address.PostCode - orderby person.Id.ToInt() + orderby person.Address!.PostCode + orderby person.Id!.ToInt() select person; Output.WriteLine("============================================"); @@ -155,28 +155,28 @@ private enum Country private class Person { - public string Id { get; set; } + public string? Id { get; set; } - public string Name { get; set; } + public string? Name { get; set; } - public AddressInfo Address { get; set; } + public AddressInfo? Address { get; set; } - public Country Country { get; set; } + public Country? Country { get; set; } } private class AddressInfo { - public string PostCode { get; set; } + public string? PostCode { get; set; } - public string Prefecture { get; set; } + public string? Prefecture { get; set; } - public string Municipality { get; set; } + public string? Municipality { get; set; } - public string HouseNumber { get; set; } + public string? HouseNumber { get; set; } - public string[] Tel { get; set; } + public string[]? Tel { get; set; } - public string[] Frends { get; set; } + public string[]? Frends { get; set; } } } } \ No newline at end of file diff --git a/TryCSharp.Samples/Linq/LinqSamples07.cs b/TryCSharp.Samples/Linq/LinqSamples07.cs index 09c875a..84287db 100644 --- a/TryCSharp.Samples/Linq/LinqSamples07.cs +++ b/TryCSharp.Samples/Linq/LinqSamples07.cs @@ -168,9 +168,9 @@ orderby personByAge.Key ascending public class Person { - public string Id { get; set; } + public string? Id { get; set; } - public string Name { get; set; } + public string? Name { get; set; } public int Age { get; set; } @@ -179,20 +179,20 @@ public class Person public class Team { - public string Id { get; set; } + public string? Id { get; set; } - public string Name { get; set; } + public string? Name { get; set; } - public IEnumerable Members { get; set; } + public IEnumerable? Members { get; set; } } public class Project { - public string Id { get; set; } + public string? Id { get; set; } - public string Name { get; set; } + public string? Name { get; set; } - public IEnumerable Members { get; set; } + public IEnumerable? Members { get; set; } public DateTime From { get; set; } diff --git a/TryCSharp.Samples/Linq/LinqSamples08.cs b/TryCSharp.Samples/Linq/LinqSamples08.cs index 81a1542..16e2627 100644 --- a/TryCSharp.Samples/Linq/LinqSamples08.cs +++ b/TryCSharp.Samples/Linq/LinqSamples08.cs @@ -146,9 +146,9 @@ orderby personByAge.Key ascending public class Person { - public string Id { get; set; } + public string? Id { get; set; } - public string Name { get; set; } + public string? Name { get; set; } public int Age { get; set; } @@ -157,20 +157,20 @@ public class Person public class Team { - public string Id { get; set; } + public string? Id { get; set; } - public string Name { get; set; } + public string? Name { get; set; } - public IEnumerable Members { get; set; } + public IEnumerable? Members { get; set; } } public class Project { - public string Id { get; set; } + public string? Id { get; set; } - public string Name { get; set; } + public string? Name { get; set; } - public IEnumerable Members { get; set; } + public IEnumerable? Members { get; set; } public DateTime From { get; set; } diff --git a/TryCSharp.Samples/Linq/LinqSamples09.cs b/TryCSharp.Samples/Linq/LinqSamples09.cs index 27e73e2..ff8ae18 100644 --- a/TryCSharp.Samples/Linq/LinqSamples09.cs +++ b/TryCSharp.Samples/Linq/LinqSamples09.cs @@ -132,7 +132,7 @@ public void Execute() //==================================================================================== // Teamから辿るパターン var query1 = from team in teams - from personId in team.Members + from personId in team.Members! join person in persons on personId equals person.Id orderby team.Id ascending, person.Id ascending select new @@ -164,7 +164,7 @@ join person in persons on personId equals person.Id // var query2 = from person in persons from team in teams - where team.Members.Contains(person.Id) + where team.Members!.Contains(person.Id) orderby team.Id ascending, person.Id ascending select new { @@ -189,7 +189,7 @@ where team.Members.Contains(person.Id) join team in ( from team in teams - from member in team.Members + from member in team.Members! select new { team.Id, @@ -233,9 +233,9 @@ from team in teams public class Person { - public string Id { get; set; } + public string? Id { get; set; } - public string Name { get; set; } + public string? Name { get; set; } public int Age { get; set; } @@ -244,20 +244,20 @@ public class Person public class Team { - public string Id { get; set; } + public string? Id { get; set; } - public string Name { get; set; } + public string? Name { get; set; } - public IEnumerable Members { get; set; } + public IEnumerable? Members { get; set; } } public class Project { - public string Id { get; set; } + public string? Id { get; set; } - public string Name { get; set; } + public string? Name { get; set; } - public IEnumerable Members { get; set; } + public IEnumerable? Members { get; set; } public DateTime From { get; set; } diff --git a/TryCSharp.Samples/Linq/LinqSamples10.cs b/TryCSharp.Samples/Linq/LinqSamples10.cs index 5cad8c9..094dfab 100644 --- a/TryCSharp.Samples/Linq/LinqSamples10.cs +++ b/TryCSharp.Samples/Linq/LinqSamples10.cs @@ -139,7 +139,7 @@ public void Execute() join prj in ( from project in projects - from member in project.Members + from member in project.Members! select new { project.Id, @@ -178,7 +178,7 @@ from member in project.Members ( // 1の処理. from project in projects - from member in project.Members + from member in project.Members! select new { project.Id, project.Name, @@ -220,7 +220,7 @@ into selectResult // var query3 = from person in persons from project in projects - where project.Members.Contains(person.Id) + where project.Members!.Contains(person.Id) select new { Person = person, @@ -246,9 +246,9 @@ orderby groupByResult.Key ascending public class Person { - public string Id { get; set; } + public string? Id { get; set; } - public string Name { get; set; } + public string? Name { get; set; } public int Age { get; set; } @@ -257,20 +257,20 @@ public class Person public class Team { - public string Id { get; set; } + public string? Id { get; set; } - public string Name { get; set; } + public string? Name { get; set; } - public IEnumerable Members { get; set; } + public IEnumerable? Members { get; set; } } public class Project { - public string Id { get; set; } + public string? Id { get; set; } - public string Name { get; set; } + public string? Name { get; set; } - public IEnumerable Members { get; set; } + public IEnumerable? Members { get; set; } public DateTime From { get; set; } diff --git a/TryCSharp.Samples/Linq/LinqSamples11.cs b/TryCSharp.Samples/Linq/LinqSamples11.cs index 2652788..844786f 100644 --- a/TryCSharp.Samples/Linq/LinqSamples11.cs +++ b/TryCSharp.Samples/Linq/LinqSamples11.cs @@ -137,7 +137,7 @@ public void Execute() join prj in ( from project in projects - from member in project.Members + from member in project.Members! select new {project.Id, project.Name, Member = member} ) on person.Id equals prj.Member into personProjects from personProject in personProjects @@ -157,7 +157,7 @@ from personProject in personProjects join prj in ( from project in projects - from member in project.Members + from member in project.Members! select new {project.Id, project.Name, Member = member} ) on person.Id equals prj.Member into personProjects // 外部結合するためにDefaultIfEmptyを使用. @@ -177,9 +177,9 @@ from personProject in personProjects.DefaultIfEmpty() public class Person { - public string Id { get; set; } + public string? Id { get; set; } - public string Name { get; set; } + public string? Name { get; set; } public int Age { get; set; } @@ -188,20 +188,20 @@ public class Person public class Team { - public string Id { get; set; } + public string? Id { get; set; } - public string Name { get; set; } + public string? Name { get; set; } - public IEnumerable Members { get; set; } + public IEnumerable? Members { get; set; } } public class Project { - public string Id { get; set; } + public string? Id { get; set; } - public string Name { get; set; } + public string? Name { get; set; } - public IEnumerable Members { get; set; } + public IEnumerable? Members { get; set; } public DateTime From { get; set; } From e549c02f5ddbde4fbd0ec8b30fb18042ce96cc34 Mon Sep 17 00:00:00 2001 From: devlights Date: Fri, 11 Mar 2022 08:30:48 +0000 Subject: [PATCH 34/38] Fix warnings --- TryCSharp.Samples/Linq/LinqSamples12.cs | 2 +- TryCSharp.Samples/Linq/LinqSamples13.cs | 2 +- TryCSharp.Samples/Linq/LinqSamples14.cs | 2 +- TryCSharp.Samples/Linq/LinqSamples15.cs | 4 ++-- TryCSharp.Samples/Linq/LinqSamples16.cs | 4 ++-- TryCSharp.Samples/Linq/LinqSamples17.cs | 4 ++-- TryCSharp.Samples/Linq/LinqSamples19.cs | 2 +- TryCSharp.Samples/Linq/LinqSamples20.cs | 2 +- TryCSharp.Samples/Linq/LinqSamples21.cs | 4 ++-- 9 files changed, 13 insertions(+), 13 deletions(-) diff --git a/TryCSharp.Samples/Linq/LinqSamples12.cs b/TryCSharp.Samples/Linq/LinqSamples12.cs index fff4f26..78c1f95 100644 --- a/TryCSharp.Samples/Linq/LinqSamples12.cs +++ b/TryCSharp.Samples/Linq/LinqSamples12.cs @@ -67,7 +67,7 @@ public void Execute() private class Person { public int Id { get; set; } - public string Name { get; set; } + public string? Name { get; set; } } } } \ No newline at end of file diff --git a/TryCSharp.Samples/Linq/LinqSamples13.cs b/TryCSharp.Samples/Linq/LinqSamples13.cs index 2618d3b..dff944a 100644 --- a/TryCSharp.Samples/Linq/LinqSamples13.cs +++ b/TryCSharp.Samples/Linq/LinqSamples13.cs @@ -68,7 +68,7 @@ public void Execute() private class Person { public int Id { get; set; } - public string Name { get; set; } + public string? Name { get; set; } } } } \ No newline at end of file diff --git a/TryCSharp.Samples/Linq/LinqSamples14.cs b/TryCSharp.Samples/Linq/LinqSamples14.cs index 2ffa569..48eabe8 100644 --- a/TryCSharp.Samples/Linq/LinqSamples14.cs +++ b/TryCSharp.Samples/Linq/LinqSamples14.cs @@ -84,7 +84,7 @@ public void Execute() private class Person { public int Id { get; set; } - public string Name { get; set; } + public string? Name { get; set; } public override string ToString() { diff --git a/TryCSharp.Samples/Linq/LinqSamples15.cs b/TryCSharp.Samples/Linq/LinqSamples15.cs index d86462e..afd08c3 100644 --- a/TryCSharp.Samples/Linq/LinqSamples15.cs +++ b/TryCSharp.Samples/Linq/LinqSamples15.cs @@ -84,8 +84,8 @@ public void Execute() private class Person { public int Id { get; set; } - public string Name { get; set; } - public string Team { get; set; } + public string? Name { get; set; } + public string? Team { get; set; } } } } \ No newline at end of file diff --git a/TryCSharp.Samples/Linq/LinqSamples16.cs b/TryCSharp.Samples/Linq/LinqSamples16.cs index 970b00a..2b173af 100644 --- a/TryCSharp.Samples/Linq/LinqSamples16.cs +++ b/TryCSharp.Samples/Linq/LinqSamples16.cs @@ -83,12 +83,12 @@ public void Execute() private class Person { public int Id { get; set; } - public string Name { get; set; } + public string? Name { get; set; } } private class Customer : Person { - public IEnumerable Orders { get; set; } + public IEnumerable? Orders { get; set; } } private class Order diff --git a/TryCSharp.Samples/Linq/LinqSamples17.cs b/TryCSharp.Samples/Linq/LinqSamples17.cs index e87fdb8..8dc422e 100644 --- a/TryCSharp.Samples/Linq/LinqSamples17.cs +++ b/TryCSharp.Samples/Linq/LinqSamples17.cs @@ -100,12 +100,12 @@ public void Execute() private class Person { public int Id { get; set; } - public string Name { get; set; } + public string? Name { get; set; } } private class Customer : Person { - public IEnumerable Orders { get; set; } + public IEnumerable? Orders { get; set; } } private class Order diff --git a/TryCSharp.Samples/Linq/LinqSamples19.cs b/TryCSharp.Samples/Linq/LinqSamples19.cs index 6e55036..ca22edd 100644 --- a/TryCSharp.Samples/Linq/LinqSamples19.cs +++ b/TryCSharp.Samples/Linq/LinqSamples19.cs @@ -43,7 +43,7 @@ public void Execute() private class Person { public int Id { get; set; } - public string Name { get; set; } + public string? Name { get; set; } } } } \ No newline at end of file diff --git a/TryCSharp.Samples/Linq/LinqSamples20.cs b/TryCSharp.Samples/Linq/LinqSamples20.cs index 67421d1..88e45b8 100644 --- a/TryCSharp.Samples/Linq/LinqSamples20.cs +++ b/TryCSharp.Samples/Linq/LinqSamples20.cs @@ -43,7 +43,7 @@ public void Execute() private class Person { public int Id { get; set; } - public string Name { get; set; } + public string? Name { get; set; } } } } \ No newline at end of file diff --git a/TryCSharp.Samples/Linq/LinqSamples21.cs b/TryCSharp.Samples/Linq/LinqSamples21.cs index fe45e74..3c2dbec 100644 --- a/TryCSharp.Samples/Linq/LinqSamples21.cs +++ b/TryCSharp.Samples/Linq/LinqSamples21.cs @@ -87,8 +87,8 @@ public void Execute() private class Team { - public string Name { get; set; } - public IEnumerable Members { get; set; } + public string? Name { get; set; } + public IEnumerable? Members { get; set; } } } } \ No newline at end of file From 287d66df4dffc4af830f596691182b6e2615c0ca Mon Sep 17 00:00:00 2001 From: devlights Date: Fri, 11 Mar 2022 08:42:12 +0000 Subject: [PATCH 35/38] Fix warnings --- TryCSharp.Samples/Linq/LinqSamples21.cs | 8 ++++---- TryCSharp.Samples/Linq/LinqSamples22.cs | 2 +- TryCSharp.Samples/Linq/LinqSamples23.cs | 6 +++--- TryCSharp.Samples/Linq/LinqSamples24.cs | 2 +- TryCSharp.Samples/Linq/LinqSamples25.cs | 10 +++++----- TryCSharp.Samples/Linq/LinqSamples26.cs | 6 +++--- TryCSharp.Samples/Linq/LinqSamples27.cs | 6 +++--- TryCSharp.Samples/Linq/LinqSamples28.cs | 8 ++++---- TryCSharp.Samples/Linq/LinqSamples29.cs | 6 +++--- TryCSharp.Samples/Linq/LinqSamples30.cs | 6 +++--- TryCSharp.Samples/Linq/LinqSamples31.cs | 6 +++--- TryCSharp.Samples/Linq/LinqSamples32.cs | 6 +++--- 12 files changed, 36 insertions(+), 36 deletions(-) diff --git a/TryCSharp.Samples/Linq/LinqSamples21.cs b/TryCSharp.Samples/Linq/LinqSamples21.cs index 3c2dbec..2fedeb4 100644 --- a/TryCSharp.Samples/Linq/LinqSamples21.cs +++ b/TryCSharp.Samples/Linq/LinqSamples21.cs @@ -49,13 +49,13 @@ public void Execute() // 実行時には、最後のselectの部分がSelectManyに置換される。 // Output.WriteLine("===== Func>のサンプル ====="); - foreach (var member in teams.SelectMany(team => team.Members)) + foreach (var member in teams.SelectMany(team => team.Members!)) { Output.WriteLine(member); } Output.WriteLine("===== Func>のサンプル ====="); - foreach (var member in teams.SelectMany((team, index) => index%2 == 0 ? team.Members : new List())) + foreach (var member in teams.SelectMany((team, index) => index%2 == 0 ? team.Members! : new List())) { Output.WriteLine(member); } @@ -63,7 +63,7 @@ public void Execute() Output.WriteLine("===== collectionSelectorとresultSelectorを利用しているサンプル (1) ====="); var query = teams.SelectMany ( - team => team.Members, // collectionSelector + team => team.Members!, // collectionSelector (team, member) => new {Team = team.Name, Name = member} // resultSelector ); @@ -75,7 +75,7 @@ public void Execute() Output.WriteLine("===== collectionSelectorとresultSelectorを利用しているサンプル (2) ====="); var query2 = teams.SelectMany ( - (team, index) => index%2 != 0 ? team.Members : new List(), // collectionSelector + (team, index) => index%2 != 0 ? team.Members! : new List(), // collectionSelector (team, member) => new {Team = team.Name, Name = member} // resultSelector ); diff --git a/TryCSharp.Samples/Linq/LinqSamples22.cs b/TryCSharp.Samples/Linq/LinqSamples22.cs index ce1d989..7d3c9a6 100644 --- a/TryCSharp.Samples/Linq/LinqSamples22.cs +++ b/TryCSharp.Samples/Linq/LinqSamples22.cs @@ -71,7 +71,7 @@ public void Execute() private class Person { public int Id { get; set; } - public string Name { get; set; } + public string? Name { get; set; } public override string ToString() { diff --git a/TryCSharp.Samples/Linq/LinqSamples23.cs b/TryCSharp.Samples/Linq/LinqSamples23.cs index b473db7..cd7d1fb 100644 --- a/TryCSharp.Samples/Linq/LinqSamples23.cs +++ b/TryCSharp.Samples/Linq/LinqSamples23.cs @@ -54,7 +54,7 @@ public void Execute() // var sortByIdAndNameAsc = persons .OrderBy(aPerson => aPerson.Id) - .ThenBy(aPerson => aPerson.Name.Last().ToString().ToInt()); + .ThenBy(aPerson => aPerson.Name!.Last().ToString().ToInt()); Output.WriteLine("================= IDの昇順で、且つ、Nameの数字部分の昇順でソート. ================="); Output.WriteLine(string.Join(Environment.NewLine, sortByIdAndNameAsc)); @@ -69,7 +69,7 @@ public void Execute() // var sortByIdAndNameDesc = persons .OrderBy(aPerson => aPerson.Id) - .ThenByDescending(aPerson => aPerson.Name.Last().ToString().ToInt()); + .ThenByDescending(aPerson => aPerson.Name!.Last().ToString().ToInt()); Output.WriteLine("================= IDの昇順で、且つ、Nameの数字部分の降順でソート. ================="); Output.WriteLine(string.Join(Environment.NewLine, sortByIdAndNameDesc)); @@ -78,7 +78,7 @@ public void Execute() private class Person { public int Id { get; set; } - public string Name { get; set; } + public string? Name { get; set; } public override string ToString() { diff --git a/TryCSharp.Samples/Linq/LinqSamples24.cs b/TryCSharp.Samples/Linq/LinqSamples24.cs index 6ab6166..b3390fa 100644 --- a/TryCSharp.Samples/Linq/LinqSamples24.cs +++ b/TryCSharp.Samples/Linq/LinqSamples24.cs @@ -39,7 +39,7 @@ public void Execute() private class Person { public int Id { get; set; } - public string Name { get; set; } + public string? Name { get; set; } public override string ToString() { diff --git a/TryCSharp.Samples/Linq/LinqSamples25.cs b/TryCSharp.Samples/Linq/LinqSamples25.cs index 7591261..2ca5041 100644 --- a/TryCSharp.Samples/Linq/LinqSamples25.cs +++ b/TryCSharp.Samples/Linq/LinqSamples25.cs @@ -98,7 +98,7 @@ public void Execute() // group thePerson by new { thePerson.Project, thePerson.Team } // Output.WriteLine("\n============ 複合キーを指定したGroupBy =============="); - var query3 = persons.GroupBy(thePerson => new {thePerson.Project, thePerson.Team}); + var query3 = persons.GroupBy(thePerson => new {Project = thePerson.Project!, Team = thePerson.Team!}); foreach (var group in query3) { Output.WriteLine("=== {0}", group.Key); @@ -117,7 +117,7 @@ public void Execute() // Output.WriteLine("\n============ 複合キーとorderbyを指定したGroupBy =============="); var query4 = persons - .GroupBy(thePerson => new {thePerson.Project, thePerson.Team}) + .GroupBy(thePerson => new {Project = thePerson.Project!, Team = thePerson.Team!}) .OrderByDescending(group => group.Key.Project) .ThenByDescending(group => group.Key.Team); @@ -134,9 +134,9 @@ public void Execute() private class Person { public int Id { get; set; } - public string Name { get; set; } - public string Team { get; set; } - public string Project { get; set; } + public string? Name { get; set; } + public string? Team { get; set; } + public string? Project { get; set; } public override string ToString() { diff --git a/TryCSharp.Samples/Linq/LinqSamples26.cs b/TryCSharp.Samples/Linq/LinqSamples26.cs index c1a2892..01b7f04 100644 --- a/TryCSharp.Samples/Linq/LinqSamples26.cs +++ b/TryCSharp.Samples/Linq/LinqSamples26.cs @@ -49,13 +49,13 @@ public void Execute() private class Person { - public string Name { get; set; } - public Team Team { get; set; } + public string? Name { get; set; } + public Team? Team { get; set; } } private class Team { - public string Name { get; set; } + public string? Name { get; set; } } } } \ No newline at end of file diff --git a/TryCSharp.Samples/Linq/LinqSamples27.cs b/TryCSharp.Samples/Linq/LinqSamples27.cs index bc3ce6e..599aaeb 100644 --- a/TryCSharp.Samples/Linq/LinqSamples27.cs +++ b/TryCSharp.Samples/Linq/LinqSamples27.cs @@ -55,13 +55,13 @@ public void Execute() private class Person { - public string Name { get; set; } - public Team Team { get; set; } + public string? Name { get; set; } + public Team? Team { get; set; } } private class Team { - public string Name { get; set; } + public string? Name { get; set; } } } } \ No newline at end of file diff --git a/TryCSharp.Samples/Linq/LinqSamples28.cs b/TryCSharp.Samples/Linq/LinqSamples28.cs index 07addc2..221b77b 100644 --- a/TryCSharp.Samples/Linq/LinqSamples28.cs +++ b/TryCSharp.Samples/Linq/LinqSamples28.cs @@ -42,12 +42,12 @@ public void Execute() private string JoinElements(IEnumerable elements) { - return string.Join(",", elements.Select(item => item.ToString())); + return string.Join(",", elements.Select(item => item!.ToString())); } private class Person { - public string Name { get; set; } + public string? Name { get; set; } public override string ToString() { @@ -57,7 +57,7 @@ public override string ToString() private class PersonComparer : EqualityComparer { - public override bool Equals(Person p1, Person p2) + public override bool Equals(Person? p1, Person? p2) { if (object.Equals(p1, p2)) { @@ -74,7 +74,7 @@ public override bool Equals(Person p1, Person p2) public override int GetHashCode(Person p) { - return p.Name.GetHashCode(); + return p.Name!.GetHashCode(); } } } diff --git a/TryCSharp.Samples/Linq/LinqSamples29.cs b/TryCSharp.Samples/Linq/LinqSamples29.cs index 321a78e..9d2ee75 100644 --- a/TryCSharp.Samples/Linq/LinqSamples29.cs +++ b/TryCSharp.Samples/Linq/LinqSamples29.cs @@ -61,12 +61,12 @@ public void Execute() private string JoinElements(IEnumerable elements) { - return string.Join(",", elements.Select(item => item.ToString())); + return string.Join(",", elements.Select(item => item!.ToString())); } private class Person { - public string Name { get; set; } + public string? Name { get; set; } public override string ToString() { @@ -76,7 +76,7 @@ public override string ToString() private class PersonComparer : EqualityComparer { - public override bool Equals(Person p1, Person p2) + public override bool Equals(Person? p1, Person? p2) { if (object.Equals(p1, p2)) { diff --git a/TryCSharp.Samples/Linq/LinqSamples30.cs b/TryCSharp.Samples/Linq/LinqSamples30.cs index 2713844..26df745 100644 --- a/TryCSharp.Samples/Linq/LinqSamples30.cs +++ b/TryCSharp.Samples/Linq/LinqSamples30.cs @@ -57,12 +57,12 @@ public void Execute() private string JoinElements(IEnumerable elements) { - return string.Join(",", elements.Select(item => item.ToString())); + return string.Join(",", elements.Select(item => item!.ToString())); } private class Person { - public string Name { get; set; } + public string? Name { get; set; } public override string ToString() { @@ -72,7 +72,7 @@ public override string ToString() private class PersonComparer : EqualityComparer { - public override bool Equals(Person p1, Person p2) + public override bool Equals(Person? p1, Person? p2) { if (object.Equals(p1, p2)) { diff --git a/TryCSharp.Samples/Linq/LinqSamples31.cs b/TryCSharp.Samples/Linq/LinqSamples31.cs index 3990b16..1855e1e 100644 --- a/TryCSharp.Samples/Linq/LinqSamples31.cs +++ b/TryCSharp.Samples/Linq/LinqSamples31.cs @@ -63,12 +63,12 @@ public void Execute() private string JoinElements(IEnumerable elements) { - return string.Join(",", elements.Select(item => item.ToString())); + return string.Join(",", elements.Select(item => item!.ToString())); } private class Person { - public string Name { get; set; } + public string? Name { get; set; } public override string ToString() { @@ -78,7 +78,7 @@ public override string ToString() private class PersonComparer : EqualityComparer { - public override bool Equals(Person p1, Person p2) + public override bool Equals(Person? p1, Person? p2) { if (object.Equals(p1, p2)) { diff --git a/TryCSharp.Samples/Linq/LinqSamples32.cs b/TryCSharp.Samples/Linq/LinqSamples32.cs index ab05ea5..6b3cf09 100644 --- a/TryCSharp.Samples/Linq/LinqSamples32.cs +++ b/TryCSharp.Samples/Linq/LinqSamples32.cs @@ -37,7 +37,7 @@ public void Execute() // // predicate有りで実行. // - Output.WriteLine("COUNT = {0}", people.Count(person => int.Parse(person.Name.Last().ToString())%2 == 0)); + Output.WriteLine("COUNT = {0}", people.Count(person => int.Parse(person.Name!.Last().ToString())%2 == 0)); // // predicate無しで実行.(LongCount) @@ -47,12 +47,12 @@ public void Execute() // // predicate有りで実行.(LongCount) // - Output.WriteLine("COUNT = {0}", people.LongCount(person => int.Parse(person.Name.Last().ToString())%2 == 0)); + Output.WriteLine("COUNT = {0}", people.LongCount(person => int.Parse(person.Name!.Last().ToString())%2 == 0)); } private class Person { - public string Name { get; set; } + public string? Name { get; set; } public override string ToString() { From 6a61a31a870c847204f5425d582bd83e51550585 Mon Sep 17 00:00:00 2001 From: devlights Date: Fri, 11 Mar 2022 08:52:31 +0000 Subject: [PATCH 36/38] Fix warnings --- TryCSharp.Samples/Linq/LinqSamples37.cs | 2 +- TryCSharp.Samples/Linq/LinqSamples42.cs | 6 +++--- TryCSharp.Samples/Linq/LinqSamples48.cs | 6 +++--- TryCSharp.Samples/Linq/LinqSamples54.cs | 2 +- TryCSharp.Samples/Linq/LinqSamples61.cs | 8 ++++++-- TryCSharp.Samples/Linq/LinqSamples64.cs | 2 +- TryCSharp.Samples/Linq/LinqSamples66.cs | 2 +- TryCSharp.Samples/Linq/LinqSamples83.cs | 10 +++++++--- TryCSharp.Samples/Linq/LinqSamples84.cs | 12 ++++++------ TryCSharp.Samples/Linq/LinqSamples85.cs | 12 ++++++------ TryCSharp.Samples/Linq/LinqSamples86.cs | 2 +- 11 files changed, 36 insertions(+), 28 deletions(-) diff --git a/TryCSharp.Samples/Linq/LinqSamples37.cs b/TryCSharp.Samples/Linq/LinqSamples37.cs index 917c550..ab42780 100644 --- a/TryCSharp.Samples/Linq/LinqSamples37.cs +++ b/TryCSharp.Samples/Linq/LinqSamples37.cs @@ -95,7 +95,7 @@ public void Execute() private class Order { - public string Name { get; set; } + public string? Name { get; set; } public int Amount { get; set; } public int Month { get; set; } } diff --git a/TryCSharp.Samples/Linq/LinqSamples42.cs b/TryCSharp.Samples/Linq/LinqSamples42.cs index c0fb6bd..0ad8127 100644 --- a/TryCSharp.Samples/Linq/LinqSamples42.cs +++ b/TryCSharp.Samples/Linq/LinqSamples42.cs @@ -41,7 +41,7 @@ public void Execute() private class Language { - public string Name { get; set; } + public string? Name { get; set; } public static Language Create(string name) { @@ -51,9 +51,9 @@ public static Language Create(string name) private class LanguageNameComparer : EqualityComparer { - public override bool Equals(Language l1, Language l2) + public override bool Equals(Language? l1, Language? l2) { - return l1.Name == l2.Name; + return l1!.Name == l2!.Name; } public override int GetHashCode(Language l) diff --git a/TryCSharp.Samples/Linq/LinqSamples48.cs b/TryCSharp.Samples/Linq/LinqSamples48.cs index f5e25c0..d9dd5eb 100644 --- a/TryCSharp.Samples/Linq/LinqSamples48.cs +++ b/TryCSharp.Samples/Linq/LinqSamples48.cs @@ -67,7 +67,7 @@ public void Execute() private class Language { - public string Name { get; set; } + public string? Name { get; set; } public static Language Create(string name) { @@ -77,9 +77,9 @@ public static Language Create(string name) private class LanguageNameComparer : EqualityComparer { - public override bool Equals(Language l1, Language l2) + public override bool Equals(Language? l1, Language? l2) { - return l1.Name == l2.Name; + return l1!.Name == l2!.Name; } public override int GetHashCode(Language l) diff --git a/TryCSharp.Samples/Linq/LinqSamples54.cs b/TryCSharp.Samples/Linq/LinqSamples54.cs index bf0d392..4d2dc29 100644 --- a/TryCSharp.Samples/Linq/LinqSamples54.cs +++ b/TryCSharp.Samples/Linq/LinqSamples54.cs @@ -35,7 +35,7 @@ public void Execute() // -- File.OpenReadで返るのはFileStream // FileStreamはStreamのサブクラス. // - XElement element = null; + XElement? element = null; using (var stream = File.OpenRead("xml/Books.xml")) { element = XElement.Load(stream); diff --git a/TryCSharp.Samples/Linq/LinqSamples61.cs b/TryCSharp.Samples/Linq/LinqSamples61.cs index 0eefb45..a5d033e 100644 --- a/TryCSharp.Samples/Linq/LinqSamples61.cs +++ b/TryCSharp.Samples/Linq/LinqSamples61.cs @@ -32,7 +32,9 @@ public void Execute() try { - elem.Value = null; + // C# 8.0 から追加された Nullable Reference Type によって以下は警告が + // 必ず発生するようになったので意味がなくなった。 + // elem.Value = null; } catch (ArgumentNullException argNullEx) { @@ -63,7 +65,9 @@ public void Execute() try { - elem.SetValue(null); + // C# 8.0 から追加された Nullable Reference Type によって以下は警告が + // 必ず発生するようになったので意味がなくなった。 + //elem.SetValue(null); } catch (ArgumentNullException argNullEx) { diff --git a/TryCSharp.Samples/Linq/LinqSamples64.cs b/TryCSharp.Samples/Linq/LinqSamples64.cs index 914f75b..0f24145 100644 --- a/TryCSharp.Samples/Linq/LinqSamples64.cs +++ b/TryCSharp.Samples/Linq/LinqSamples64.cs @@ -25,7 +25,7 @@ public void Execute() var attr = elem.FirstAttribute; Output.WriteLine(attr); - Output.WriteLine("{0}=\"{1}\"", attr.Name, attr.Value); + Output.WriteLine("{0}=\"{1}\"", attr!.Name, attr.Value); Output.WriteLine("====================================="); // diff --git a/TryCSharp.Samples/Linq/LinqSamples66.cs b/TryCSharp.Samples/Linq/LinqSamples66.cs index 51dcf09..2465380 100644 --- a/TryCSharp.Samples/Linq/LinqSamples66.cs +++ b/TryCSharp.Samples/Linq/LinqSamples66.cs @@ -29,7 +29,7 @@ public void Execute() var elem = root.Elements("Child").First(); var attr = elem.Attribute("Id"); - attr.Value = 500.ToString(); + attr!.Value = 500.ToString(); Output.WriteLine(root); Output.WriteLine("====================================="); diff --git a/TryCSharp.Samples/Linq/LinqSamples83.cs b/TryCSharp.Samples/Linq/LinqSamples83.cs index aceacbf..9b909ce 100644 --- a/TryCSharp.Samples/Linq/LinqSamples83.cs +++ b/TryCSharp.Samples/Linq/LinqSamples83.cs @@ -34,10 +34,14 @@ public void Execute() // GUID,GUID? // var root = BuildSampleXml(); + if (root == null) + { + return; + } - var title = (string) root.Descendants("Title").FirstOrDefault() ?? "Nothing"; - var attr = (string) root.Elements("Book").First().Attribute("id") ?? "Nothing"; - var noElem = (string) root.Descendants("NoElem").FirstOrDefault() ?? "Nothing"; + var title = (string) root.Descendants("Title").FirstOrDefault()! ?? "Nothing"; + var attr = (string) root.Elements("Book").First().Attribute("id")! ?? "Nothing"; + var noElem = (string) root.Descendants("NoElem").FirstOrDefault()! ?? "Nothing"; Output.WriteLine(title); Output.WriteLine(attr); diff --git a/TryCSharp.Samples/Linq/LinqSamples84.cs b/TryCSharp.Samples/Linq/LinqSamples84.cs index 078fc24..c0a10a3 100644 --- a/TryCSharp.Samples/Linq/LinqSamples84.cs +++ b/TryCSharp.Samples/Linq/LinqSamples84.cs @@ -36,7 +36,7 @@ public void Execute() // 属性値を変更 // Changingイベントなので、イベントハンドラ内にて見えるsenderの値は*更新前*の値となる。 (Change) - book.Attribute("id").Value = "updated"; + book.Attribute("id")!.Value = "updated"; // 要素の値を変更 // Title要素は内部にXTextを持っているので、まずそれが削除される (Remove) // その後、更新後の値を持つXTextが設定される. (Add) @@ -64,7 +64,7 @@ public void Execute() // 属性値を変更 // Changedイベントなので、イベントハンドラ内にて見えるsenderの値は*更新後*の値となる。 (Change) - book.Attribute("id").Value = "updated"; + book.Attribute("id")!.Value = "updated"; title.Value = "updated"; title.Remove(); book.Add(new XElement("newelem", "hogehoge")); @@ -73,15 +73,15 @@ public void Execute() } // Changingイベントハンドラ - private void OnNodeChanging(object sender, XObjectChangeEventArgs e) + private void OnNodeChanging(object? sender, XObjectChangeEventArgs e) { - Output.WriteLine("Changing: sender--{0}:{1}, ObjectChange--{2}", sender.GetType().Name, sender, e.ObjectChange); + Output.WriteLine("Changing: sender--{0}:{1}, ObjectChange--{2}", sender!.GetType().Name, sender, e.ObjectChange); } // Changedイベントハンドラ - private void OnNodeChanged(object sender, XObjectChangeEventArgs e) + private void OnNodeChanged(object? sender, XObjectChangeEventArgs e) { - Output.WriteLine("Changed: sender--{0}:{1}, ObjectChange--{2}", sender.GetType().Name, sender, e.ObjectChange); + Output.WriteLine("Changed: sender--{0}:{1}, ObjectChange--{2}", sender!.GetType().Name, sender, e.ObjectChange); } private XElement BuildSampleXml() diff --git a/TryCSharp.Samples/Linq/LinqSamples85.cs b/TryCSharp.Samples/Linq/LinqSamples85.cs index a50e982..1665875 100644 --- a/TryCSharp.Samples/Linq/LinqSamples85.cs +++ b/TryCSharp.Samples/Linq/LinqSamples85.cs @@ -141,8 +141,8 @@ from elem in original.Elements() select new XElement ( "newdata", - new XAttribute("code", elem.Element("code").Value), - new XAttribute("name", elem.Element("name").Value) + new XAttribute("code", elem.Element("code")!.Value), + new XAttribute("name", elem.Element("name")!.Value) ) ); @@ -158,8 +158,8 @@ from elem in original.Elements() select new XElement ( "newdata", - new XAttribute("code", elem.Element("code").Value), - new XAttribute("name", elem.Element("name").Value) + new XAttribute("code", elem.Element("code")!.Value), + new XAttribute("name", elem.Element("name")!.Value) ) ); @@ -177,8 +177,8 @@ from elem in StreamTooBigXml(filePath) select new XElement ( "newdata", - new XAttribute("code", elem.Element("code").Value), - new XAttribute("name", elem.Element("name").Value) + new XAttribute("code", elem.Element("code")!.Value), + new XAttribute("name", elem.Element("name")!.Value) ) ); diff --git a/TryCSharp.Samples/Linq/LinqSamples86.cs b/TryCSharp.Samples/Linq/LinqSamples86.cs index 7b7fbf7..2cbd423 100644 --- a/TryCSharp.Samples/Linq/LinqSamples86.cs +++ b/TryCSharp.Samples/Linq/LinqSamples86.cs @@ -48,7 +48,7 @@ public void Execute() foreach (var item in QueryHasAnnotation(root)) { Output.WriteLine(item); - Output.WriteLine(item.Annotation().Value); + Output.WriteLine(item.Annotation()!.Value); } // From 5a25bb32d9f918a8775bd4369068a841ae870dc4 Mon Sep 17 00:00:00 2001 From: devlights Date: Fri, 11 Mar 2022 08:54:24 +0000 Subject: [PATCH 37/38] Format .gitpod.yml --- .gitpod.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.gitpod.yml b/.gitpod.yml index da358e3..d17cbdf 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -1,10 +1,7 @@ - image: gitpod/workspace-dotnet-lts:latest - -tasks: +tasks: - name: dotnet restore init: make restore - vscode: extensions: - - muhammad-sammy.csharp \ No newline at end of file + - muhammad-sammy.csharp From 9c2d90deb911aa598c2fbb5b90082b608c2dc697 Mon Sep 17 00:00:00 2001 From: devlights Date: Fri, 11 Mar 2022 08:56:58 +0000 Subject: [PATCH 38/38] Fix warnings --- .devcontainer/Dockerfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 9d73f57..9a60615 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -8,8 +8,10 @@ RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/ # [Optional] Uncomment this section to install additional OS packages. RUN apt-get update -q && export DEBIAN_FRONTEND=noninteractive \ - && apt-get -yq install --no-install-recommends bash-completion -RUN su vscode -c "source /etc/bash_completion" + && apt-get -yq install --no-install-recommends bash-completion \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* \ + && su vscode -c "source /etc/bash_completion" # [Optional] Uncomment this line to install global node packages. # RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g " 2>&1 \ No newline at end of file