Skip to content

Commit bcae6f9

Browse files
Revert "Removing some advanced syntax for strings"
This reverts commit 175ca20.
1 parent 175ca20 commit bcae6f9

File tree

5 files changed

+15
-36
lines changed

5 files changed

+15
-36
lines changed

B9PartSwitch/CustomPartModule.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ public override void OnLoad(ConfigNode node)
8484
}
8585
catch (Exception ex)
8686
{
87-
Exception ex2 = new Exception("Fatal exception while loading fields on module " + ex);
88-
//Exception ex2 = new Exception($"Fatal exception while loading fields on module {this}", ex);
87+
Exception ex2 = new Exception($"Fatal exception while loading fields on module {this}", ex);
8988
FatalErrorHandler.HandleFatalError(ex2);
9089
throw ex2;
9190
}
@@ -115,8 +114,7 @@ public override void OnSave(ConfigNode node)
115114
}
116115
catch (Exception ex)
117116
{
118-
Exception ex2 = new Exception("Fatal exception while saving fields on module " + ex);
119-
// Exception ex2 = new Exception($"Fatal exception while saving fields on module {this}", ex);
117+
Exception ex2 = new Exception($"Fatal exception while saving fields on module {this}", ex);
120118
FatalErrorHandler.HandleFatalError(ex2);
121119
throw ex2;
122120
}

B9PartSwitch/Extensions/ObjectExtensions.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ public static void ThrowIfNullArgument(this object o, string paramName)
2121

2222
public static void EnsureArgumentType(this object o, Type type, string paramName)
2323
{
24-
if (o.IsNotNull() && !o.GetType().Implements(type))
25-
throw new ArgumentException("Expected parameter of type " + paramName + " but got {o.GetType()}");
26-
// throw new ArgumentException($"Expected parameter of type {type} but got {o.GetType()}", paramName);
24+
if (o.IsNotNull() && !o.GetType().Implements(type)) throw new ArgumentException($"Expected parameter of type {type} but got {o.GetType()}", paramName);
2725
}
2826

2927
public static void EnsureArgumentType<T>(this object o, string paramName) => o.EnsureArgumentType(typeof(T), paramName);

B9PartSwitch/Extensions/PartExtensions.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,12 @@ public static PartResource AddOrCreateResource(this Part part, PartResourceDefin
4040
{
4141
if (amount > maxAmount)
4242
{
43-
part.LogWarning("Cannot add resource '" + info.name + "' with amount > maxAmount, will use maxAmount (amount = " + amount + ", maxAmount = " + maxAmount+ ")");
44-
// part.LogWarning($"Cannot add resource '{info.name}' with amount > maxAmount, will use maxAmount (amount = {amount}, maxAmount = {maxAmount})");
43+
part.LogWarning($"Cannot add resource '{info.name}' with amount > maxAmount, will use maxAmount (amount = {amount}, maxAmount = {maxAmount})");
4544
amount = maxAmount;
4645
}
4746
else if (amount < 0f)
4847
{
49-
part.LogWarning("Cannot add resource '" + info.name + "' with amount < 0, will use 0 (amount = " + amount + ")");
50-
//part.LogWarning($"Cannot add resource '{info.name}' with amount < 0, will use 0 (amount = {amount})");
48+
part.LogWarning($"Cannot add resource '{info.name}' with amount < 0, will use 0 (amount = {amount})");
5149
amount = 0f;
5250
}
5351

@@ -147,12 +145,8 @@ public static void FixModuleJettison(this Part part)
147145
}
148146
}
149147

150-
public static void LogInfo(this Part part, object message) => Debug.Log("[Part " + part.name+ "] " +message);
151-
public static void LogWarning(this Part part, object message) => Debug.LogWarning("[WARNING] [Part " + part.name + "] " + message);
152-
public static void LogError(this Part part, object message) => Debug.LogError("[ERROR] [Part " + part.name + "] " + message);
153-
154-
// public static void LogInfo(this Part part, object message) => Debug.Log($"[Part {part.name}] {message}");
155-
// public static void LogWarning(this Part part, object message) => Debug.LogWarning($"[WARNING] [Part {part.name}] {message}");
156-
// public static void LogError(this Part part, object message) => Debug.LogError($"[ERROR] [Part {part.name}] {message}");
148+
public static void LogInfo(this Part part, object message) => Debug.Log($"[Part {part.name}] {message}");
149+
public static void LogWarning(this Part part, object message) => Debug.LogWarning($"[WARNING] [Part {part.name}] {message}");
150+
public static void LogError(this Part part, object message) => Debug.LogError($"[ERROR] [Part {part.name}] {message}");
157151
}
158152
}

B9PartSwitch/Extensions/PartModuleExtensions.cs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,18 @@ public static void SetUiGroups(this PartModule module, string uiGroupName, strin
2828

2929
#region Logging
3030

31-
32-
public static void LogInfo(this PartModule module, object message) => module.part.LogInfo(module.LogTagString()+ " " + message);
33-
public static void LogWarning(this PartModule module, object message) => module.part.LogWarning(module.LogTagString() + " " +message);
34-
public static void LogError(this PartModule module, object message) => module.part.LogError(module.LogTagString() + " " + message);
35-
36-
// public static void LogInfo(this PartModule module, object message) => module.part.LogInfo($"{module.LogTagString()} {message}");
37-
// public static void LogWarning(this PartModule module, object message) => module.part.LogWarning($"{module.LogTagString()} {message}");
38-
// public static void LogError(this PartModule module, object message) => module.part.LogError($"{module.LogTagString()} {message}");
31+
public static void LogInfo(this PartModule module, object message) => module.part.LogInfo($"{module.LogTagString()} {message}");
32+
public static void LogWarning(this PartModule module, object message) => module.part.LogWarning($"{module.LogTagString()} {message}");
33+
public static void LogError(this PartModule module, object message) => module.part.LogError($"{module.LogTagString()} {message}");
3934

4035
public static string LogTagString(this PartModule module)
4136
{
4237
string info = module.GetType().Name;
4338

4439
if (module is CustomPartModule utilModule && !utilModule.moduleID.IsNullOrEmpty())
45-
info += " '" + utilModule.moduleID + "'";
46-
// info += $" '{utilModule.moduleID}'";
40+
info += $" '{utilModule.moduleID}'";
4741

48-
return "[" + info + "]";
49-
// return $"[{info}]";
42+
return $"[{info}]";
5043
}
5144

5245
#endregion

B9PartSwitch/ModuleMatcher.cs

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

6565
public ConfigNode FindPrefabNode(PartModule module)
6666
{
67-
if (module.part.partInfo is not AvailablePart partInfo)
68-
throw new InvalidOperationException("partInfo is null on part " + module.part.name);
69-
// throw new InvalidOperationException($"partInfo is null on part {module.part.name}");
70-
if (partInfo.partConfig is not ConfigNode partConfig)
71-
throw new InvalidOperationException("partInfo.partConfig is null on part " + partInfo.name);
72-
// 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}");
7369

7470
ConfigNode matchedNode = null;
7571

0 commit comments

Comments
 (0)