mirror of
https://github.com/fadden/6502bench.git
synced 2025-02-27 04:29:04 +00:00
Fix PseudoOp Merge
Missed this in the immutability change. Instead of merging new strings in, we create a new instance with the merged data.
This commit is contained in:
parent
f87ac20f32
commit
6251edb5ed
@ -462,7 +462,7 @@ namespace SourceGen {
|
|||||||
if (!string.IsNullOrEmpty(pseudoCereal)) {
|
if (!string.IsNullOrEmpty(pseudoCereal)) {
|
||||||
PseudoOp.PseudoOpNames deser = PseudoOp.PseudoOpNames.Deserialize(pseudoCereal);
|
PseudoOp.PseudoOpNames deser = PseudoOp.PseudoOpNames.Deserialize(pseudoCereal);
|
||||||
if (deser != null) {
|
if (deser != null) {
|
||||||
mPseudoOpNames.Merge(deser);
|
mPseudoOpNames = PseudoOp.PseudoOpNames.Merge(mPseudoOpNames, deser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,19 +165,31 @@ namespace SourceGen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Merges the non-null, non-empty strings in "other" into this instance.
|
/// Merges the non-null, non-empty strings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Merge(PseudoOpNames other) {
|
public static PseudoOpNames Merge(PseudoOpNames basePon, PseudoOpNames newPon) {
|
||||||
// Lots of fields, we don't do this often... use reflection.
|
Dictionary<string, string> baseDict = PropsToDict(basePon);
|
||||||
Type type = GetType();
|
Dictionary<string, string> newDict = PropsToDict(newPon);
|
||||||
PropertyInfo[] props = type.GetProperties();
|
|
||||||
foreach (PropertyInfo pi in props) {
|
foreach (KeyValuePair<string, string> kvp in newDict) {
|
||||||
string str = (string)pi.GetValue(other);
|
if (string.IsNullOrEmpty(kvp.Value)) {
|
||||||
if (string.IsNullOrEmpty(str)) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
pi.SetValue(this, str);
|
baseDict[kvp.Key] = kvp.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return new PseudoOpNames(baseDict);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Dictionary<string, string> PropsToDict(PseudoOpNames pon) {
|
||||||
|
Dictionary<string, string> dict = new Dictionary<string, string>();
|
||||||
|
foreach (PropertyInfo prop in pon.GetType().GetProperties()) {
|
||||||
|
string value = (string)prop.GetValue(pon);
|
||||||
|
if (!string.IsNullOrEmpty(value)) {
|
||||||
|
dict[prop.Name] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dict;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Serialize() {
|
public string Serialize() {
|
||||||
@ -185,15 +197,7 @@ namespace SourceGen {
|
|||||||
// which means a lot of double-quote escaping. We could do something here
|
// which means a lot of double-quote escaping. We could do something here
|
||||||
// that stored more nicely but it doesn't seem worth the effort.
|
// that stored more nicely but it doesn't seem worth the effort.
|
||||||
JavaScriptSerializer ser = new JavaScriptSerializer();
|
JavaScriptSerializer ser = new JavaScriptSerializer();
|
||||||
|
Dictionary<string, string> dict = PropsToDict(this);
|
||||||
Dictionary<string, string> dict = new Dictionary<string, string>();
|
|
||||||
foreach (PropertyInfo prop in GetType().GetProperties()) {
|
|
||||||
string value = (string)prop.GetValue(this);
|
|
||||||
if (!string.IsNullOrEmpty(value)) {
|
|
||||||
dict[prop.Name] = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ser.Serialize(dict);
|
return ser.Serialize(dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user