Skip to content

Commit 9194f6b

Browse files
authored
Merge pull request blowfishpro#211 from blowfishpro/FixWarnings
Fix some warnings
2 parents 729e637 + f267e52 commit 9194f6b

File tree

9 files changed

+39
-60
lines changed

9 files changed

+39
-60
lines changed

B9PartSwitch/Extensions/PartExtensions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ public static PartResource AddResource(this Part part, PartResourceDefinition in
2424
resource.flowMode = PartResource.FlowMode.Both;
2525
part.Resources.dict.Add(info.name.GetHashCode(), resource);
2626

27-
PartResource simulationResource = new PartResource(resource);
28-
simulationResource.simulationResource = true;
27+
PartResource simulationResource = new PartResource(resource)
28+
{
29+
simulationResource = true
30+
};
2931
part.SimulationResources.dict.Add(info.name.GetHashCode(), simulationResource);
3032

3133
GameEvents.onPartResourceListChange.Fire(part);

B9PartSwitch/ModuleMatcher.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ public PartModule FindModule(Part part)
6464

6565
public ConfigNode FindPrefabNode(PartModule module)
6666
{
67-
if (!(module.part.partInfo is AvailablePart partInfo)) throw new InvalidOperationException($"partInfo is null on part {module.part.name}");
68-
if (!(partInfo.partConfig is ConfigNode partConfig)) throw new InvalidOperationException($"partInfo.partConfig is null on part {partInfo.name}");
67+
if (module.part.partInfo is not AvailablePart partInfo) throw new InvalidOperationException($"partInfo is null on part {module.part.name}");
68+
if (partInfo.partConfig is not ConfigNode partConfig) throw new InvalidOperationException($"partInfo.partConfig is null on part {partInfo.name}");
6969

7070
ConfigNode matchedNode = null;
7171

@@ -142,7 +142,7 @@ private bool NodeMatchesModule(PartModule module, ConfigNode node)
142142
{
143143
if (value.name == "name") continue;
144144

145-
if (!(node.GetValue(value.name) is string testValue)) return false;
145+
if (node.GetValue(value.name) is not string testValue) return false;
146146

147147
if (module.Fields[value.name] is BaseField baseField)
148148
{

B9PartSwitch/PartSwitch/ModuleB9PartSwitch.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections;
33
using System.Collections.Generic;
4-
using System.Diagnostics.CodeAnalysis;
54
using UniLinq;
65
using UnityEngine;
76
using B9PartSwitch.Fishbones;
@@ -98,7 +97,6 @@ private set
9897
#region Private Fields
9998

10099
// Tweakscale integration (set via reflection, readonly is ok)
101-
[SuppressMessage("Style", "IDE0032", Justification = "Set by Tweakscale")]
102100
private readonly float scale = 1f;
103101

104102
private readonly List<ModuleB9PartSwitch> children = new List<ModuleB9PartSwitch>(0);

B9PartSwitch/PartSwitch/ModuleModifierInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ public IEnumerable<IPartModifier> CreatePartModifiers(Part part, PartModule pare
9898

9999
if (dataNode.IsNotNull())
100100
{
101-
if (!(module.part.partInfo is AvailablePart partInfo)) throw new InvalidOperationException($"partInfo is null on part {part.name}");
102-
if (!(partInfo.partConfig is ConfigNode partConfig)) throw new InvalidOperationException($"partInfo.partConfig is null on part {partInfo.name}");
101+
if (module.part.partInfo is not AvailablePart partInfo) throw new InvalidOperationException($"partInfo is null on part {part.name}");
102+
if (partInfo.partConfig is not ConfigNode partConfig) throw new InvalidOperationException($"partInfo.partConfig is null on part {partInfo.name}");
103103

104104
ConfigNode originalNode = moduleMatcher.FindPrefabNode(module);
105105

B9PartSwitch/PartSwitch/PartModifiers/ModuleDeactivator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public ModuleDeactivator(PartModule module, PartModule parent)
1616
this.parent = parent;
1717
}
1818

19-
public override string Description => $"module {module.ToString()} activated status";
19+
public override string Description => $"module {module} activated status";
2020

2121
public override void ActivateOnStartEditor() => Activate();
2222
public override void ActivateOnStartFlight() => Activate();
@@ -38,7 +38,7 @@ protected virtual void MaybeDeactivate()
3838
foreach (PartModule otherModule in module.part.Modules)
3939
{
4040
if (otherModule == parent) continue;
41-
if (!(otherModule is ModuleB9PartSwitch switchModule)) continue;
41+
if (otherModule is not ModuleB9PartSwitch switchModule) continue;
4242
if (switchModule.ModuleShouldBeEnabled(module)) return;
4343
}
4444

B9PartSwitch/PartSwitch/PartSubtype.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ public bool ModuleShouldBeEnabled(PartModule module)
560560
{
561561
foreach (IPartModifier partModifier in partModifiers)
562562
{
563-
if (!(partModifier is ModuleDeactivator moduleDeactivator)) continue;
563+
if (partModifier is not ModuleDeactivator moduleDeactivator) continue;
564564
if (moduleDeactivator.module == module) return false;
565565
}
566566

B9PartSwitch/Utils/ColorParser.cs

Lines changed: 19 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -126,49 +126,26 @@ public static Color Parse(string colorStr)
126126

127127
private static byte ParseHex(char value)
128128
{
129-
switch (value)
129+
return value switch
130130
{
131-
case '0':
132-
return 0;
133-
case '1':
134-
return 1;
135-
case '2':
136-
return 2;
137-
case '3':
138-
return 3;
139-
case '4':
140-
return 4;
141-
case '5':
142-
return 5;
143-
case '6':
144-
return 6;
145-
case '7':
146-
return 7;
147-
case '8':
148-
return 8;
149-
case '9':
150-
return 9;
151-
case 'A':
152-
case 'a':
153-
return 10;
154-
case 'B':
155-
case 'b':
156-
return 11;
157-
case 'C':
158-
case 'c':
159-
return 12;
160-
case 'D':
161-
case 'd':
162-
return 13;
163-
case 'E':
164-
case 'e':
165-
return 14;
166-
case 'F':
167-
case 'f':
168-
return 15;
169-
default:
170-
throw new FormatException("Invalid hexadecimal character: " + value);
171-
}
131+
'0' => 0,
132+
'1' => 1,
133+
'2' => 2,
134+
'3' => 3,
135+
'4' => 4,
136+
'5' => 5,
137+
'6' => 6,
138+
'7' => 7,
139+
'8' => 8,
140+
'9' => 9,
141+
'A' or 'a' => 10,
142+
'B' or 'b' => 11,
143+
'C' or 'c' => 12,
144+
'D' or 'd' => 13,
145+
'E' or 'e' => 14,
146+
'F' or 'f' => 15,
147+
_ => throw new FormatException("Invalid hexadecimal character: " + value),
148+
};
172149
}
173150

174151
private static float ParseFloatValue(string valueStr)

B9PartSwitchTests/Fishbones/NodeDataListBuilderTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ private class NodeDataClass
2626
#pragma warning restore CS0649
2727

2828
[NodeData]
29-
public DummyClass x { get; protected set; }
29+
public DummyClass X { get; protected set; }
3030

3131
[NodeData]
32-
public DummyClass y { get { throw new NotImplementedException(); } set { } }
32+
public DummyClass Y { get { throw new NotImplementedException(); } set { } }
3333

34-
public DummyClass z { get; set; }
34+
public DummyClass Z { get; set; }
3535
}
3636

3737
#region Constructor
@@ -56,9 +56,9 @@ public void TestCreateList()
5656
FieldInfo iField = typeof(NodeDataClass).GetField("i", flags);
5757
FieldInfo jField = typeof(NodeDataClass).GetField("j", flags);
5858
FieldInfo kField = typeof(NodeDataClass).GetField("k", flags);
59-
PropertyInfo xProperty = typeof(NodeDataClass).GetProperty("x", flags);
60-
PropertyInfo yProperty = typeof(NodeDataClass).GetProperty("y", flags);
61-
PropertyInfo zProperty = typeof(NodeDataClass).GetProperty("z", flags);
59+
PropertyInfo xProperty = typeof(NodeDataClass).GetProperty("X", flags);
60+
PropertyInfo yProperty = typeof(NodeDataClass).GetProperty("Y", flags);
61+
PropertyInfo zProperty = typeof(NodeDataClass).GetProperty("Z", flags);
6262

6363
Assert.NotNull(iField);
6464
Assert.NotNull(jField);

B9PartSwitchTests/Fishbones/Parsers/NodeObjectWrapperIContextualNodeTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ public void TestSave()
117117
};
118118

119119
ConfigNode node = wrapper.Save(obj, Exemplars.SaveContext);
120+
121+
Assert.Equal("stuff", node.GetValue("value"));
120122
}
121123

122124
[Fact]

0 commit comments

Comments
 (0)