From 207090488a79119127b4d02f522790a6618372ce Mon Sep 17 00:00:00 2001 From: NATSUME Hiroaki Date: Thu, 19 Dec 2024 18:24:39 +0900 Subject: [PATCH] Clean code --- .../Operation/ConstructFishEggByCsv.cs | 19 +++++++++++-------- Tunny/Type/FishEgg.cs | 19 +++++++++++++++---- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/Tunny/Component/Operation/ConstructFishEggByCsv.cs b/Tunny/Component/Operation/ConstructFishEggByCsv.cs index 617185f..f1fd7b7 100644 --- a/Tunny/Component/Operation/ConstructFishEggByCsv.cs +++ b/Tunny/Component/Operation/ConstructFishEggByCsv.cs @@ -12,7 +12,7 @@ namespace Tunny.Component.Operation { - public partial class ConstructFishEggByCsv : GH_Component + public class ConstructFishEggByCsv : GH_Component { private readonly List _fishEggs = new List(); public override GH_Exposure Exposure => GH_Exposure.secondary; @@ -63,14 +63,17 @@ private static Dictionary GetVariableRange(List foreach (VariableBase variable in variables) { string name = variable.NickName; - switch (variable) + if (variable is NumberVariable numberVariable) { - case NumberVariable number: - variableRange.Add(name, new double[] { number.LowerBond, number.UpperBond }); - break; - case CategoricalVariable _: - variableRange.Add(name, Array.Empty()); - break; + variableRange.Add(name, new double[] { numberVariable.LowerBond, numberVariable.UpperBond }); + } + else if (variable is CategoricalVariable) + { + variableRange.Add(name, Array.Empty()); + } + else + { + throw new InvalidOperationException("Variable type is not supported."); } } return variableRange; diff --git a/Tunny/Type/FishEgg.cs b/Tunny/Type/FishEgg.cs index 26b1cfe..4088dd4 100644 --- a/Tunny/Type/FishEgg.cs +++ b/Tunny/Type/FishEgg.cs @@ -11,13 +11,24 @@ namespace Tunny.Type [Serializable] public class FishEgg { - private readonly bool _skipIfExist; - private readonly Dictionary _paramDict; - private readonly Dictionary _attrDict; + private bool _skipIfExist; + private Dictionary _paramDict; + private Dictionary _attrDict; - public FishEgg(bool skipIfExist = true) + public FishEgg() { TLog.MethodStart(); + Initialize(true); + } + + public FishEgg(bool skipIfExist) + { + TLog.MethodStart(); + Initialize(skipIfExist); + } + + private void Initialize(bool skipIfExist) + { _skipIfExist = skipIfExist; _paramDict = new Dictionary(); _attrDict = new Dictionary();