public string ToJson(bool skipDefault = true) { CItem original = Globals.Managers.item.GetItemByID(id, true); JObject jsonObject = new JObject(); if (skipDefault) { jsonObject["id"] = id; FieldInfo[] propertiesA = original.GetType().GetFields(); // @todo dodać filtr żeby zwracał tylko pola przedmiotu a nie wszystkie FieldInfo[] propertiesB = this.GetType().GetFields(); object objA, objB; foreach (FieldInfo field in propertiesA) { objA = field.GetValue(original); objB = field.GetValue(this); if (objA != null && objB != null) { if (!objA.Equals(objB) || field.Name == "position") { jsonObject[field.Name] = JsonConvert.SerializeObject(objB); } } } } else { FieldInfo[] properties = GetType().GetFields(); foreach (FieldInfo field in properties) { jsonObject[field.Name] = JsonConvert.SerializeObject(field.GetValue(this)); } } return(jsonObject.ToString(Formatting.None)); }
public static bool IsSimillar(CItem itemA, CItem itemB) { if (itemA.GetType() != itemB.GetType()) { return(false); } FieldInfo[] propertiesA = itemA.GetType().GetFields(); // @todo dodać filtr żeby zwracał tylko pola przedmiotu a nie wszystkie FieldInfo[] propertiesB = itemB.GetType().GetFields(); object objA, objB; foreach (FieldInfo fieldA in propertiesA) { foreach (FieldInfo fieldB in propertiesB) { if (fieldA.Name == fieldB.Name) { objA = fieldA.GetValue(itemA); objB = fieldB.GetValue(itemB); if (objA != null && objB != null) { if (!objA.Equals(objB)) { return(false); } } break; } } } return(true); }
public CItem CreateItem(EItemType itemType) { if (Enum.IsDefined(typeof(EItemType), itemType)) { string itemClass = "Managers.CItem" + itemType.ToString(); CItem item = (CItem)System.Reflection.Assembly.GetAssembly(typeof(CItem)).CreateInstance(itemClass); return(item); } return(null); }
public CItem GetItemByID(uint id, bool dontCopy = false) { CItem item = defaultItems.Single(i => i.id == id); if (ReferenceEquals(item, null)) { return(null); } if (dontCopy) { return(item); } return(item.Copy()); }
public CItem Copy() { CItem copy = (CItem)MemberwiseClone(); return(copy); }