private static void ApplyFPInfo(object o, FPInfo info) { Type ftype = info.FPType; Random rand = Utils.random; if (ftype == typeof(int)) { int a = rand.Next(500); info.SetValue(a, o); } else if (ftype == typeof(float)) { if (info.Name.ToLower().Contains("scale")) { return; } float a = (float)rand.NextDouble() * 500f; info.SetValue(a, o); } else if (ftype == typeof(bool)) { int a = rand.Next(100); bool b = a % 2 == 0 ? true : false; info.SetValue(b, o); } else if (ftype.IsEnum) { if (ftype == typeof(mtypes)) { return; } ArrayList list = new ArrayList(Enum.GetValues(ftype)); int a = rand.Next(list.Count); info.SetValue(list[a], o); } }
public void SetValue(object value) { if (membertype == member_type.dictentry) { //holy shit that's dynamic. dynamic dict = parentItem.obj; dynamic KEY = key; dynamic VALUE = value; if (!dict.GetType().IsGenericType || dict.GetType().GetGenericTypeDefinition() != typeof(Dictionary <,>)) { return; } dict[KEY] = VALUE; obj = VALUE; return; } if (fpinfo == null) { throw new SystemException("fpinfo was null during SetValue in InspectorInfo"); } if (Utils.isToggle(fpinfo.FPType)) { dynamic toggle; if (Utils.isToggle(value)) { toggle = GetValue(); dynamic tog2 = value; toggle.GetType().GetProperty("enabled").SetValue(toggle, tog2.enabled, null); if (tog2.value.GetType() == toggle.value.GetType()) { toggle.GetType().GetProperty("value").SetValue(toggle, tog2.value, null); //Console.WriteLine(parentItem.obj.GetType() + " >> " + this + " >> " + value.GetType() + " >> " + value); } return; } else if (value is bool) { toggle = GetValue(); toggle.GetType().GetProperty("enabled").SetValue(toggle, value, null); //Console.WriteLine(parentItem.obj.GetType() + " >> " + this + " >> " + toggle.GetType() + " >> " + toggle); return; } object san = TrySanitize(value); if (san != null) { toggle = GetValue(); if (value.GetType() == toggle.value.GetType()) { toggle.GetType().GetProperty("value").SetValue(toggle, san, null); //Console.WriteLine(parentItem.obj.GetType() + " >> " + this + " >> " + toggle.GetType() + " >> " + toggle); } } return; } else if (fpinfo.FPType.IsEnum && !value.GetType().IsEnum) { object san = TrySanitize(value); if (san != null) { fpinfo.SetValue(san, parentItem.obj); //Console.WriteLine(parentItem.obj.GetType() + " >> " + this + " >> " + value.GetType() + " >> " + value); } return; } if (value.GetType() == fpinfo.FPType) { fpinfo.SetValue(value, parentItem.obj); //Console.WriteLine(parentItem.obj.GetType() + " >> " + this + " >> " + value.GetType() + " >> " + value); } }