using System; using System.Collections.Generic; using System.Reflection; using Newtonsoft.Json; using Supercell.Laser.Logic.Data.Reader; namespace Supercell.Laser.Logic.Data.Helper { public class LogicData { private int _dataType; private int _id; protected DataTable DataTable; protected Row Row; public LogicData(Row row, DataTable dataTable) { Row = row; DataTable = dataTable; } public void LoadData(LogicData data, Type type, Row row, int dataType = -1) { _dataType = (int)DataTables.Types[this.GetType()]; _id = GlobalId.CreateGlobalId(_dataType, DataTable.Count); Row = row; Row.LoadData(data); } public int GetDataType() { return _dataType; } public int GetGlobalId() { return _id; } public int GetInstanceId() { return GlobalId.GetInstanceId(_id); } public int GetClassId() { return GlobalId.GetClassId(_id); } public string GetName() { return Row.GetName(); } public void ApplyParentData(LogicData parent, params string[] ignoredProperties) { if (parent == null || parent.GetType() != GetType()) { return; } HashSet ignored = ignoredProperties != null ? new HashSet(ignoredProperties) : new HashSet(); foreach (PropertyInfo property in GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { if (!property.CanRead || !property.CanWrite) { continue; } if (ignored.Contains(property.Name)) { continue; } if (Row.GetValue(property.Name, 0) != string.Empty) { continue; } object parentValue = property.GetValue(parent); if (parentValue == null) { continue; } property.SetValue(this, parentValue); } } } }