Skip to content

Commit 9b74b48

Browse files
committed
Fix for class cast exception
1 parent e7994e9 commit 9b74b48

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

WzVisualizer/WzStringUtility.cs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -101,59 +101,54 @@ private void SetParsed(WzImage image) {
101101
image.ParseImage();
102102
}
103103

104+
private string GetStringValue(WzImageProperty img) {
105+
return img != null && img is WzStringProperty str ? str.Value : null;
106+
}
107+
104108
public string GetNPC(int ID) {
105109
SetParsed(NPCImage);
106-
WzImageProperty imgProperty = (WzStringProperty)NPCImage.GetFromPath($"{ID}/name");
107-
return ((WzStringProperty)imgProperty)?.Value;
110+
return GetStringValue(NPCImage.GetFromPath($"{ID}/name"));
108111
}
109112

110113
public string GetSkill(string ID) {
111114
SetParsed(SkillImage);
112-
WzImageProperty imgProperty = (WzStringProperty)SkillImage.GetFromPath($"{ID}/name");
113-
return ((WzStringProperty)imgProperty)?.Value;
115+
return GetStringValue(SkillImage.GetFromPath($"{ID}/name"));
114116
}
115117

116118
public string GetMob(int ID) {
117119
SetParsed(MobImage);
118-
WzImageProperty imgProperty = (WzStringProperty)MobImage.GetFromPath($"{ID}/name");
119-
return ((WzStringProperty)imgProperty)?.Value;
120+
return GetStringValue(MobImage.GetFromPath($"{ID}/name"));
120121
}
121122

122123
public string GetEqp(int ID) {
123124
SetParsed(EqpImage);
124125
string category = GetEqpCategory(ID);
125-
WzImageProperty imgProperty = EqpImage.GetFromPath($"Eqp/{category}/{ID}/name");
126-
return ((WzStringProperty)imgProperty)?.Value;
126+
return GetStringValue(EqpImage.GetFromPath($"Eqp/{category}/{ID}/name"));
127127
}
128128

129129
public string GetEtc(int ID) {
130130
SetParsed(EtcImage);
131-
WzImageProperty imgProperty = EtcImage.GetFromPath($"Etc/{ID}/name");
132-
return ((WzStringProperty)imgProperty)?.Value;
131+
return GetStringValue(EtcImage.GetFromPath($"Etc/{ID}/name"));
133132
}
134133

135134
public string GetCash(int ID) {
136135
SetParsed(CashImage);
137-
WzImageProperty imgProperty = CashImage.GetFromPath($"{ID}/name");
138-
return ((WzStringProperty)imgProperty)?.Value;
136+
return GetStringValue(CashImage.GetFromPath($"{ID}/name"));
139137
}
140138

141139
public string GetChair(int ID) {
142140
SetParsed(InsImage);
143-
WzImageProperty imgProperty = InsImage.GetFromPath($"{ID}/name");
144-
return ((WzStringProperty)imgProperty)?.Value;
141+
return GetStringValue(InsImage.GetFromPath($"{ID}/name"));
145142
}
146143

147144
public string GetConsume(int ID) {
148145
SetParsed(ConsumeImage);
149-
WzImageProperty imgProperty = ConsumeImage.GetFromPath($"{ID}/name");
150-
return ((WzStringProperty)imgProperty)?.Value;
146+
return GetStringValue(ConsumeImage.GetFromPath($"{ID}/name"));
151147
}
152148

153149
public string GetPet(int ID) {
154150
SetParsed(PetImage);
155-
WzImageProperty imgProperty = PetImage.GetFromPath($"{ID}/name");
156-
return ((WzStringProperty)imgProperty)?.Value;
151+
return GetStringValue(PetImage.GetFromPath($"{ID}/name"));
157152
}
158153
}
159154
}

0 commit comments

Comments
 (0)