Skip to content

Commit

Permalink
fix warning IDE0055
Browse files Browse the repository at this point in the history
  • Loading branch information
smdn committed Apr 2, 2024
1 parent f3647f7 commit bb9c8cd
Show file tree
Hide file tree
Showing 38 changed files with 348 additions and 591 deletions.
1 change: 0 additions & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ SPDX-License-Identifier: MIT

<!-- disables code style/code analysis warnings configured by Smdn.MSBuild.ProjectAssets.Common -->
<PropertyGroup>
<NoWarn>IDE0055;$(NoWarn)</NoWarn> <!-- IDE0055: 書式設定を修正 -->
<NoWarn>IDE1006;$(NoWarn)</NoWarn> <!-- IDE1006: 名前付けルール違反 -->
<NoWarn>CA1008;$(NoWarn)</NoWarn> <!-- CA1008: 提案された名前 'None' を伴う、値 0 を含む メンバーを追加します -->
<NoWarn>CA1031;$(NoWarn)</NoWarn> <!-- CA1031: 'Dispose' を変更してより具体的な許可された例外の種類をキャッチするか、例外を再スローしてください -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ public override ApplicationServiceName Read(ref Utf8JsonReader reader, Type type
if (reader.TokenType != JsonTokenType.String)
throw new JsonException($"expected {nameof(JsonTokenType)}.{nameof(JsonTokenType.String)}, but was {reader.TokenType}");

var str = reader.GetString();

if (str is null)
throw new JsonException("property value can not be null");
var str = reader.GetString() ?? throw new JsonException("property value can not be null");

return str switch {
"モバイルサービス" => ApplicationServiceName.MobileServices,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ namespace Smdn.Net.EchonetLite.Appendix;
/// <summary>
/// クラスグループ
/// </summary>
public sealed class EchonetClassGroupSpecification
{
public sealed class EchonetClassGroupSpecification {
/// <summary>
/// JSONデシリアライズ用のコンストラクタ
/// </summary>
Expand All @@ -23,8 +22,7 @@ public sealed class EchonetClassGroupSpecification
/// <exception cref="ArgumentNullException"><see langword="null"/>非許容のプロパティに<see langword="null"/>を設定しようとしました。</exception>
/// <exception cref="ArgumentException">プロパティに空の文字列を設定しようとしました。</exception>
[JsonConstructor]
public EchonetClassGroupSpecification
(
public EchonetClassGroupSpecification(
byte code,
string? name,
string? propertyName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ namespace Smdn.Net.EchonetLite.Appendix;
/// <summary>
/// クラス
/// </summary>
public sealed class EchonetClassSpecification
{
public sealed class EchonetClassSpecification {
/// <summary>
/// JSONデシリアライズ用のコンストラクタ
/// </summary>
Expand All @@ -21,8 +20,7 @@ public sealed class EchonetClassSpecification
/// <exception cref="ArgumentNullException"><see langword="null"/>非許容のプロパティに<see langword="null"/>を設定しようとしました。</exception>
/// <exception cref="ArgumentException">プロパティに空の文字列を設定しようとしました。</exception>
[JsonConstructor]
public EchonetClassSpecification
(
public EchonetClassSpecification(
bool isDefined,
byte code,
string? name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ namespace Smdn.Net.EchonetLite.Appendix;
/// <summary>
/// ECHONET Lite オブジェクト
/// </summary>
public sealed class EchonetObjectSpecification
{
public sealed class EchonetObjectSpecification {
private static readonly IReadOnlyDictionary<byte, EchonetPropertySpecification> EmptyPropertyDictionary
#if SYSTEM_COLLECTIONS_OBJECTMODEL_READONLYDICTIONARY_EMPTY
= ReadOnlyDictionary<byte, EchonetPropertySpecification>.Empty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ namespace Smdn.Net.EchonetLite.Appendix;
/// <seealso href="https://echonet.jp/spec_g/">
/// APPENDIX ECHONET 機器オブジェクト詳細規定 第2章 機器オブジェクトスーパークラス規定
/// </seealso>
public sealed class EchonetPropertySpecification
{
public sealed class EchonetPropertySpecification {
/// <summary>
/// 指定されたプロパティコードをもつ、未知のECHONET プロパティを作成します。
/// </summary>
Expand Down Expand Up @@ -72,8 +71,7 @@ internal static EchonetPropertySpecification CreateUnknown(byte code)
/// <exception cref="ArgumentNullException"><see langword="null"/>非許容のプロパティに<see langword="null"/>を設定しようとしました。</exception>
/// <exception cref="ArgumentException">プロパティに空の文字列を設定しようとしました。</exception>
[JsonConstructor]
public EchonetPropertySpecification
(
public EchonetPropertySpecification(
string? name,
byte code,
string? detail,
Expand Down Expand Up @@ -111,13 +109,11 @@ public EchonetPropertySpecification
Description = string.IsNullOrEmpty(description) ? null : description;
Unit = string.IsNullOrEmpty(unit) ? null : unit;

if (string.IsNullOrEmpty(unit) || "".Equals(Unit, StringComparison.Ordinal))
{
if (string.IsNullOrEmpty(unit) || "".Equals(Unit, StringComparison.Ordinal)) {
Unit = null;
HasUnit = false;
}
else
{
else {
HasUnit = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ internal static class JsonValidationUtils {
public static string ThrowIfValueIsNullOrEmpty(string? value, string paramName)
{
if (value is null)
throw new ArgumentNullException(paramName: paramName);
throw new ArgumentNullException(paramName: paramName);

if (value.Length == 0)
throw new ArgumentException(message: "string is empty", paramName: paramName);
throw new ArgumentException(message: "string is empty", paramName: paramName);

return value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

namespace Smdn.Net.EchonetLite.Appendix;

internal sealed class PropertyMaster
{
internal sealed class PropertyMaster {
/// <summary>
/// JSONデシリアライズ用のコンストラクタ
/// </summary>
Expand All @@ -20,8 +19,7 @@ internal sealed class PropertyMaster
/// <exception cref="ArgumentNullException"><see langword="null"/>非許容のプロパティに<see langword="null"/>を設定しようとしました。</exception>
/// <exception cref="ArgumentException">プロパティに空の文字列を設定しようとしました。</exception>
[JsonConstructor]
public PropertyMaster
(
public PropertyMaster(
string? version,
string? appendixRelease,
IReadOnlyList<EchonetPropertySpecification>? properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

namespace Smdn.Net.EchonetLite.Appendix;

internal sealed class SingleByteHexStringJsonConverter : JsonConverter<byte>
{
internal sealed class SingleByteHexStringJsonConverter : JsonConverter<byte> {
private const string SingleByteHexStringPrefix = "0x";
private const NumberStyles SingleByteHexNumberStyles = NumberStyles.AllowHexSpecifier;

Expand All @@ -20,10 +19,7 @@ public override byte Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSer
if (reader.TokenType != JsonTokenType.String)
throw new JsonException($"expected {nameof(JsonTokenType)}.{nameof(JsonTokenType.String)}, but was {reader.TokenType}");

var str = reader.GetString();

if (str is null)
throw new JsonException("property value can not be null");
var str = reader.GetString() ?? throw new JsonException("property value can not be null");

if (!str.StartsWith(SingleByteHexStringPrefix, StringComparison.Ordinal))
throw new JsonException($"property value must have a prefix '{SingleByteHexStringPrefix}'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ namespace Smdn.Net.EchonetLite.Appendix;
/// <summary>
/// ECHONETオブジェクト詳細マスタ
/// </summary>
internal sealed class SpecificationMaster
{
internal sealed class SpecificationMaster {
/// <summary>
/// シングルトンイスタンス
/// </summary>
Expand Down Expand Up @@ -56,8 +55,7 @@ private sealed class SpecificationMasterJsonObject {
/// <exception cref="ArgumentNullException"><see langword="null"/>非許容のプロパティに<see langword="null"/>を設定しようとしました。</exception>
/// <exception cref="ArgumentException">プロパティに空の文字列を設定しようとしました。</exception>
[JsonConstructor]
public SpecificationMasterJsonObject
(
public SpecificationMasterJsonObject(
string? version,
string? appendixRelease,
IReadOnlyList<EchonetClassGroupSpecification>? profiles,
Expand Down Expand Up @@ -99,12 +97,10 @@ IReadOnlyList<EchonetClassGroupSpecification> specs
/// <returns></returns>
public static SpecificationMaster GetInstance()
{
if (_Instance == null)
{
if (_Instance == null) {
const string specificationMasterJsonFileName = "SpecificationMaster.json";

using (var stream = GetSpecificationMasterDataStream(specificationMasterJsonFileName))
{
using (var stream = GetSpecificationMasterDataStream(specificationMasterJsonFileName)) {
_Instance = new(
JsonSerializer.Deserialize<SpecificationMasterJsonObject>(stream) ?? throw new InvalidOperationException($"failed to deserialize {specificationMasterJsonFileName}")
);
Expand All @@ -119,12 +115,8 @@ private static Stream GetSpecificationMasterDataStream(string file)
{
var logicalName = SpecificationMasterDataLogicalRootName + file;

var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(logicalName);

if (stream is null)
throw new InvalidOperationException($"resource not found: {logicalName}");

return stream;
return Assembly.GetExecutingAssembly().GetManifestResourceStream(logicalName)
?? throw new InvalidOperationException($"resource not found: {logicalName}");
}

private static Stream? GetSpecificationMasterDataStream(string classGroupDirectoryName, string classFileName)
Expand All @@ -148,33 +140,29 @@ byte classCode
!GetInstance().Profiles.TryGetValue(classGroupCode, out var classGroupSpec) &&
!GetInstance().DeviceClasses.TryGetValue(classGroupCode, out classGroupSpec)
) {
throw new ArgumentException($"unknown class group: 0x{classGroupCode:X2}");
throw new ArgumentException($"unknown class group: 0x{classGroupCode:X2}");
}

const int MaxNumberOfProperty = 0x80; // EPC: 0b_1XXX_XXXX (0x80~0xFF)

var properties = new List<EchonetPropertySpecification>(capacity: MaxNumberOfProperty);

//スーパークラスのプロパティを列挙
using (var stream = GetSpecificationMasterDataStream($"{classGroupSpec.SuperClassName}.json"))
{
using (var stream = GetSpecificationMasterDataStream($"{classGroupSpec.SuperClassName}.json")) {
var superClassProperties = JsonSerializer.Deserialize<PropertyMaster>(stream) ?? throw new InvalidOperationException($"{nameof(PropertyMaster)} can not be null");
properties.AddRange(superClassProperties.Properties);
}

var classSpec = classGroupSpec.Classes?.FirstOrDefault(c => c.IsDefined && c.Code == classCode)
?? throw new ArgumentException($"unknown class: 0x{classCode:X2}");

if (classSpec.IsDefined)
{
if (classSpec.IsDefined) {
var classGroupDirectoryName = $"0x{classGroupSpec.Code:X2}-{classGroupSpec.PropertyName}";
var classFileName = $"0x{classSpec.Code:X2}-{classSpec.PropertyName}.json";

//クラスのプロパティを列挙
using (var stream = GetSpecificationMasterDataStream(classGroupDirectoryName, classFileName))
{
if (stream is not null)
{
using (var stream = GetSpecificationMasterDataStream(classGroupDirectoryName, classFileName)) {
if (stream is not null) {
var classProperties = JsonSerializer.Deserialize<PropertyMaster>(stream) ?? throw new InvalidOperationException($"{nameof(PropertyMaster)} can not be null");
properties.AddRange(classProperties.Properties);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ namespace Smdn.Net.EchonetLite;
/// APPENDIX ECHONET機器オブジェクト詳細規定 Release R 第1章 本書の概要 表1アプリケーションサービスと「オプション必須」プロパティ表記記号一覧
/// </seealso>
[JsonConverter(typeof(ApplicationServiceNameJsonConverter))]
public enum ApplicationServiceName
{
public enum ApplicationServiceName {
/// <summary>
/// モバイルサービス(Mobile services)○M
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ namespace Smdn.Net.EchonetLite;
/// ECHONET Lite クラスグループ定義
/// 機器
/// </summary>
public static class DeviceClasses
{
public static class DeviceClasses {
/// <summary>
/// 指定されたクラスグループコード・クラスコードをもつECHONET Lite オブジェクトを取得します。
/// </summary>
Expand Down Expand Up @@ -232,8 +231,7 @@ bool includeProfiles
/// ECHONET Lite クラスグループ定義
/// センサ関連機器クラスグループ
/// </summary>
public static class センサ関連機器
{
public static class センサ関連機器 {
/// <summary>
/// 0x01 ガス漏れセンサ
/// </summary>
Expand Down Expand Up @@ -416,8 +414,7 @@ public static class センサ関連機器
/// ECHONET Lite クラスグループ定義
/// 空調関連機器 クラスグループ
/// </summary>
public static class 空調関連機器
{
public static class 空調関連機器 {
/// <summary>
/// 0x30 家庭用エアコン
/// </summary>
Expand Down Expand Up @@ -471,8 +468,7 @@ public static class 空調関連機器
/// ECHONET Lite クラスグループ定義
/// 住宅設備関連機器クラスグループ
/// </summary>
public static class 住宅設備関連機器
{
public static class 住宅設備関連機器 {
/// <summary>
/// 0x60 電動ブラインド・日よけ
/// </summary>
Expand Down Expand Up @@ -626,8 +622,7 @@ public static class 住宅設備関連機器
/// ECHONET Lite クラスグループ定義
/// 調理家事関連機器 クラスグループ
/// </summary>
public static class 調理家事関連機器
{
public static class 調理家事関連機器 {
/// <summary>
/// 0xB2 電気ポット
/// </summary>
Expand Down Expand Up @@ -674,8 +669,7 @@ public static class 調理家事関連機器
/// ECHONET Lite クラスグループ定義
/// 健康関連機器 クラスグループ
/// </summary>
public static class 健康関連機器
{
public static class 健康関連機器 {
/// <summary>
/// 0x01 体重計
/// </summary>
Expand All @@ -685,8 +679,7 @@ public static class 健康関連機器
/// ECHONET Lite クラスグループ定義
/// 管理操作関連機器 クラスグループ
/// </summary>
public static class 管理操作関連機器
{
public static class 管理操作関連機器 {
/// <summary>
/// 0xFA 並列処理併用型電力制御
/// </summary>
Expand All @@ -712,8 +705,7 @@ public static class 管理操作関連機器
/// ECHONET Lite クラスグループ定義
/// AV関連機器 クラスグループ
/// </summary>
public static class AV関連機器
{
public static class AV関連機器 {
/// <summary>
/// 0x01 ディスプレー
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ namespace Smdn.Net.EchonetLite;
/// ECHONET Lite クラスグループ定義
/// プロファイルクラスグループ
/// </summary>
public static class Profiles
{
public static class Profiles {
/// <summary>
/// 0xF0 ノードプロファイル
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ namespace Smdn.Net.EchonetLite.Protocol;
/// <summary>
/// 電文形式 1(規定電文形式)
/// </summary>
public sealed class EData1 : IEData
{
public sealed class EData1 : IEData {
/// <summary>
/// ECHONET Liteフレームの電文形式 1(規定電文形式)の電文を記述する<see cref="EData1"/>を作成します。
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ namespace Smdn.Net.EchonetLite.Protocol;
/// <summary>
/// 電文形式2(任意電文形式)
/// </summary>
public sealed class EData2 : IEData
{
public sealed class EData2 : IEData {
/// <summary>
/// ECHONET Liteフレームの電文形式2(任意電文形式)の電文を記述する<see cref="EData2"/>を作成します。
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
// SPDX-License-Identifier: MIT
namespace Smdn.Net.EchonetLite.Protocol;

public enum EHD1 : byte
{
public enum EHD1 : byte {
//図 3-2 EHD1 詳細規定
//プロトコル種別
//1* * * :従来のECHONET規格
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
// SPDX-License-Identifier: MIT
namespace Smdn.Net.EchonetLite.Protocol;

public enum EHD2 : byte
{
public enum EHD2 : byte {
//図 3-3 EHD2 詳細規定
/// <summary>
/// 形式1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ namespace Smdn.Net.EchonetLite.Protocol;
/// <summary>
/// ECHONET オブジェクト(EOJ)
/// </summary>
public readonly struct EOJ:IEquatable<EOJ>
{
public readonly struct EOJ : IEquatable<EOJ> {
/// <summary>
/// ECHONET オブジェクト(EOJ)を記述する<see cref="EOJ"/>を作成します。
/// </summary>
Expand Down
Loading

0 comments on commit bb9c8cd

Please sign in to comment.