public void DayStarted(object sender, DayStartedEventArgs e) { LazyHelper.OverwritePlayerLimit(); }
protected override object SelectObjectByID(Type type, int id) { // Checking to see if object exists... MySqlCommand cmdExists = new MySqlCommand( string.Format("select count(*) from Documents where ID={0}", id), _connection); if ((int)((long)cmdExists.ExecuteScalar()) == 0) return null; // Object exists, starting to retrieve it... ConstructorInfo ctor = type.GetConstructor( BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, new Type[] { }, null); if (ctor == null) throw new ApplicationException("Cannot have a LegoDocument which doesn't have a default constructor, type name is '" + type.FullName + "'"); object retVal = ctor.Invoke(null); type.GetProperty("ID", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).GetSetMethod(true).Invoke(retVal, new object[] { id }); PropertyInfo[] props = type.GetProperties( BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (PropertyInfo idxProp in props) { ActiveFieldAttribute[] attrs = idxProp.GetCustomAttributes(typeof(ActiveFieldAttribute), true) as ActiveFieldAttribute[]; if (attrs != null && attrs.Length > 0) { // Serializable property string where = " FK_Document=" + id + " and Name='" + Helpers.PropertyName(idxProp) + "'"; string tableName; switch (idxProp.PropertyType.FullName) { case "System.Boolean": tableName = "PropertyBools"; break; case "System.DateTime": tableName = "PropertyDates"; break; case "System.Decimal": tableName = "PropertyDecimals"; break; case "System.Int32": tableName = "PropertyInts"; break; case "System.String": tableName = "PropertyStrings"; break; case "System.Byte[]": tableName = "PropertyBLOBS"; break; default: if (idxProp.PropertyType.FullName.IndexOf("Ra.Brix.Types.LazyList") == 0) { // LazyList... Type typeOfList = idxProp.PropertyType; Type typeOfListGenericArgument = idxProp.PropertyType.GetGenericArguments()[0]; LazyHelper helper = new LazyHelper(typeOfListGenericArgument, id, attrs[0].IsOwner, idxProp.Name); FunctorGetItems del = helper.GetItems; object tmp = typeOfList.GetConstructors()[0].Invoke(new object[] { del }); idxProp.GetSetMethod(true).Invoke(retVal, new[] { tmp }); } else if (idxProp.PropertyType.FullName.IndexOf("System.Collections.Generic.List") == 0) { // NOT LazyList, but still List...! Type typeOfListGenericArgument = idxProp.PropertyType.GetGenericArguments()[0]; List<object> tmpValues = attrs[0].IsOwner ? new List<object>(Instance.Select(typeOfListGenericArgument, idxProp.Name, Criteria.ParentId(id))) : new List<object>(Instance.Select(typeOfListGenericArgument, idxProp.Name, Criteria.ExistsIn(id))); MethodInfo addMethod = idxProp.PropertyType.GetMethod("Add"); object listContent = idxProp.GetGetMethod(true).Invoke(retVal, new object[] { }); foreach (object idxTmpValue in tmpValues) { addMethod.Invoke(listContent, new[] { idxTmpValue }); } } else { if (attrs[0].IsOwner) { object tmp = SelectFirst(idxProp.PropertyType, idxProp.Name, Criteria.ParentId(id)); idxProp.GetSetMethod().Invoke(retVal, new[] { tmp }); } else { object tmp = SelectFirst(idxProp.PropertyType, idxProp.Name, Criteria.ExistsIn(id)); idxProp.GetSetMethod().Invoke(retVal, new[] { tmp }); } } continue; // Possibly composition } MySqlCommand cmd = new MySqlCommand( string.Format("select Value from {0} where {1}", tableName, where), _connection); object propValue = cmd.ExecuteScalar(); if (propValue is DBNull || propValue == null) propValue = null; else if (idxProp.PropertyType == typeof(bool)) propValue = ((ulong)propValue) != 0 ? true : false; idxProp.GetSetMethod(true).Invoke(retVal, new[] { propValue }); } } return retVal; }
public void FirstUpdateTick(object sender, GameLaunchedEventArgs e) { // Overwrite the player limit in Stardew Valley source code LazyHelper.OverwritePlayerLimit(); }