internal void FixEmptyFields() { var infos = new Dictionary <Type, FieldInfo[]> { { main.GetType(), main.GetType().GetFields() }, { buttons.GetType(), buttons.GetType().GetFields() }, { tools.GetType(), tools.GetType().GetFields() }, { copier.GetType(), copier.GetType().GetFields() }, { avatarInfo.GetType(), avatarInfo.GetType().GetFields() }, { thumbnails.GetType(), thumbnails.GetType().GetFields() }, { misc.GetType(), misc.GetType().GetFields() }, { log.GetType(), log.GetType().GetFields() }, { warnings.GetType(), warnings.GetType().GetFields() }, { credits.GetType(), credits.GetType().GetFields() }, { poseEditor.GetType(), poseEditor.GetType().GetFields() }, { preset.GetType(), preset.GetType().GetFields() }, }; PumkinsTranslation def = Default; FieldInfo[] thisFields = GetType().GetFields(); foreach (var kv in infos) { Type targetType = kv.Key; FieldInfo[] targetFields = kv.Value; FieldInfo ownerObjectField = thisFields.FirstOrDefault(f => f.FieldType == targetType); if (ownerObjectField == null) { continue; } object ownerObject = ownerObjectField.GetValue(this); object defaultObject = ownerObjectField.GetValue(def); if (ownerObject == null || defaultObject == null) { continue; } for (int i = 0; i < targetFields.Length; i++) { FieldInfo field = targetFields[i]; if (field.FieldType != typeof(string)) { continue; } if (string.IsNullOrWhiteSpace(field.GetValue(ownerObject) as string)) { field.SetValue(ownerObject, field.GetValue(defaultObject)); } } } }
public static PumkinsTranslation GetOrCreateDefaultTranslation() { if (_default != null) { return(_default); } _default = CreateInstance <PumkinsTranslation>(); return(_default); }