private RegionFlag DeserializeFlag(SerializableFlag flag) { try { flag.Name = RegionFlag.GetPrimaryFlagName(flag.Name); var type = RegionFlag.GetFlagType(flag.Name); var deserializedFlag = (RegionFlag)Activator.CreateInstance(type); deserializedFlag.Region = this; deserializedFlag.Name = RegionFlag.GetFlagName(type); deserializedFlag.Value = flag.Value; for (var i = 0; i < flag.GroupValues.Count; i++) { deserializedFlag.SetValue(flag.GroupValues[i].Value, GroupExtensions.GetGroup(flag.GroupValues[i].GroupName)); } deserializedFlag.GroupValues = flag.GroupValues ?? new List <GroupValue>(); _flags.Add(deserializedFlag); return(deserializedFlag); } catch (Exception) { /*ignored*/ } return(null); }
public void SetFlag(string name, object value, List <GroupValue> groupValues, bool save = true) { name = RegionFlag.GetPrimaryFlagName(name); var flagType = RegionFlag.GetFlagType(name); if (flagType == null) { throw new ArgumentException("Unknown flag: " + name); } if (Flags == null) { Flags = new List <SerializableFlag>(); } foreach (var f in Flags.Where(f => f.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase))) { Flags.Remove(f); break; } var flag = new SerializableFlag { Name = name, Value = value, GroupValues = groupValues }; Flags.Add(flag); if (save) { RegionsPlugin.Instance.Configuration.Save(); } if (_flags == null) { _flags = new List <RegionFlag>(); } foreach (RegionFlag f in ParsedFlags.Where(f => f.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase))) { f.Value = value; return; } var deserializedFlag = DeserializeFlag(flag); if (deserializedFlag != null) { deserializedFlag.Value = value; } }