public QueueInfo( FPInfo fpInfo, object obj, int queuecount, string id = "" //Type type = typeof(object) ) { this.fpInfo = fpInfo; this.obj = obj; this.queuecount = queuecount; this.id = id; //this.elementType = type; this.queue = new Queue<object>(); }
public static void RandomizeObject(object o) { Type type = o.GetType(); //properties List<PropertyInfo> propertyInfos; propertyInfos = type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).ToList(); foreach(var pinfo in propertyInfos) { FPInfo fpinfo = new FPInfo(pinfo); ApplyFPInfo(o, fpinfo); } //fields List<FieldInfo> fieldInfos; fieldInfos = type.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).ToList(); foreach (var finfo in fieldInfos) { FPInfo fpinfo = new FPInfo(finfo); ApplyFPInfo(o, fpinfo); } }
//for copying component use public FPInfo(FPInfo old) { this.propertyInfo = old.propertyInfo; this.fieldInfo = old.fieldInfo; if (propertyInfo != null) { Name = propertyInfo.Name; DeclaringTypeName = propertyInfo.DeclaringType.ToString(); } else if (fieldInfo != null) { Name = fieldInfo.Name; DeclaringTypeName = fieldInfo.DeclaringType.ToString(); } else if (old.DeclaringTypeName != null) { //PropertyInfo pi = old.DeclaringTypeName.GetProperty(old.Name); PropertyInfo pi = Type.GetType(old.DeclaringTypeName).GetProperty(old.Name); if (pi != null) { this.propertyInfo = pi; Name = old.Name; return; } //FieldInfo fi = old.DeclaringTypeName.GetField(old.Name); FieldInfo fi = Type.GetType(old.DeclaringTypeName).GetField(old.Name); if (fi != null) { this.fieldInfo = fi; Name = old.Name; return; } } else Name = "error_Name_2"; //ob = null; }
//obj = null //a IEnumberable entry public InspectorInfo(IList<object> masterList, InspectorInfo parentItem, object obj) { this.whitespace = "|"; if (parentItem != null) this.whitespace += parentItem.whitespace; this.parentItem = parentItem; this.obj = obj; this.masterList = masterList; this.fpinfo = null; this.children = new List<InspectorInfo>(); //this.inspectorArea = parentItem.inspectorArea; this.sidebar = parentItem.sidebar; this.showValueToString = parentItem.showValueToString; Type t = parentItem.obj.GetType(); if (t.GetInterfaces() .Any(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IEnumerable<>))) { //Console.WriteLine("IEnumerable : {0}", obj.GetType()); membertype = member_type.collectionentry; CheckItemType(); prefix = "" + ((char)164); } else { System.Console.WriteLine("Unexpected: InspectorInfo with no obj reference was not a collection entry"); membertype = member_type.unimplemented; } }
//obj = null //a dictionary entry public InspectorInfo(IList<object> masterList, InspectorInfo parentItem, object obj, object key) { this.whitespace = "|"; if (parentItem != null) this.whitespace += parentItem.whitespace; this.parentItem = parentItem; this.obj = obj; this.masterList = masterList; this.fpinfo = null; this.children = new List<InspectorInfo>(); //this.inspectorArea = parentItem.inspectorArea; this.sidebar = parentItem.sidebar; this.showValueToString = parentItem.showValueToString; Type t = parentItem.obj.GetType(); if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Dictionary<,>)) { membertype = member_type.dictentry; this.key = key; CheckItemType(); prefix = "" + ((char)164); //System.Console.WriteLine(this); //children = GenerateList(obj, whitespace, this); } else { System.Console.WriteLine("Unexpected: InspectorInfo with no obj reference was not a dictionary entry"); membertype = member_type.unimplemented; } }
//a field public InspectorInfo(IList<object> masterList, InspectorInfo parentItem, object obj, FieldInfo fieldInfo) { this.membertype = member_type.field; this.fpinfo = new FPInfo(fieldInfo); FieldOrPropertyInitilize(masterList, parentItem, obj); }
public static void CloneComponent(Component sourceComp, Component destComp) { List<FieldInfo> fields = sourceComp.GetType().GetFields().ToList(); fields.AddRange(sourceComp.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance).ToList()); List<PropertyInfo> properties = sourceComp.GetType().GetProperties().ToList(); foreach (PropertyInfo property in properties) { if (property.PropertyType == typeof(ModifierInfo)) continue; if (property.PropertyType == typeof(Node)) { var cust = property.GetCustomAttributes(typeof(CopyNodeProperty), false); if (cust.Length > 0) { Node n = (Node)property.GetValue(sourceComp, null); Node nclone = n.CreateClone(sourceComp.room); property.SetValue(destComp, nclone, null); //Console.WriteLine("CLONING : " + property.Name); } continue; } if (Utils.isToggle(property.PropertyType)) { dynamic tog = property.GetValue(sourceComp, null); dynamic newtog = tog.Clone(); property.SetValue(destComp, newtog, null); continue; } if (property.PropertyType.IsClass) { if (!typeof(Delegate).IsAssignableFrom(property.PropertyType) && !(property.PropertyType == typeof(Link))) { //Console.WriteLine("We should be aware of this."); } } if (property.GetSetMethod() != null) property.SetValue(destComp, property.GetValue(sourceComp, null), null); } foreach (FieldInfo field in fields) { if (field.Name.Equals("shape")) continue; if (field.FieldType == typeof(Dictionary<string,ModifierInfo>)) { Modifier mod = (Modifier) sourceComp; Dictionary<string, ModifierInfo> newmodinfos = new Dictionary<string, ModifierInfo>(); foreach (KeyValuePair<string, ModifierInfo> kvp in mod.modifierInfos) { string key = kvp.Key; ModifierInfo modifierInfo = kvp.Value; Dictionary<string, FPInfo> newFpInfos = new Dictionary<string, FPInfo>(); Dictionary<string, object> newFpInfosObj = new Dictionary<string, object>(); foreach (string key2 in modifierInfo.fpInfos.Keys) { FPInfo fpinfo = new FPInfo(modifierInfo.fpInfos[key2]); newFpInfos.Add(key2, fpinfo); newFpInfosObj.Add(key2, null); } Dictionary<string, dynamic> newargs = new Dictionary<string, dynamic>(); foreach (string key2 in modifierInfo.args.Keys) { newargs.Add(key2, modifierInfo.args[key2]); //by reference (for now) } ModifierInfo modInfo = new ModifierInfo(newFpInfos, newFpInfosObj, newargs, modifierInfo.modifierDelegate); modInfo.delegateName = modifierInfo.delegateName; newmodinfos.Add(key, modInfo); } field.SetValue(destComp, newmodinfos); } //no longer checking for dictionaries, parent(Node) if ((field.FieldType == typeof(int)) || (field.FieldType == typeof(Single)) || (field.FieldType == typeof(bool)) || (field.FieldType == typeof(string))) { field.SetValue(destComp, field.GetValue(sourceComp)); } else if (field.FieldType == typeof(Vector2)) { Vector2 vect = (Vector2)field.GetValue(sourceComp); Vector2 newvect = new Vector2(vect.X, vect.Y); field.SetValue(destComp, newvect); } else if (field.FieldType == typeof(Color)) { Color col = (Color)field.GetValue(sourceComp); Color newcol = new Color(col.R, col.G, col.B, col.A); field.SetValue(destComp, newcol); } else { //this would be an object field if (field.Name.Equals("room")) { field.SetValue(destComp, field.GetValue(sourceComp)); } } //field.SetValue(newobj, field.GetValue(obj)); } destComp.InitializeLists(); destComp.AfterCloning(); }
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 RebuildInfo(object obj) { if (fpInfos.Count < 1) { Console.Write("There were not keys in fpInfos while Rebuilding the Info"); return; } fpInfosObj = new Dictionary<string, object>(); foreach(string key in fpInfos.Keys) { fpInfos[key] = new FPInfo(fpInfos[key].Name, obj); fpInfosObj.Add(key, obj); } }
public void AddFPInfoObject(string id, FPInfo fpInfo, object obj) { fpInfos.Add(id, fpInfo); fpInfosObj.Add(id, obj); }
public void AddFPInfoFromString(string id, string fieldname, object obj) { FPInfo fpInfo = new FPInfo(fieldname, obj); if (fpInfos.ContainsKey(id)) { Console.WriteLine("[{0}] was already found in the dictionary", id); return; } if (fpInfosObj.ContainsKey(id)) { Console.WriteLine("[{0}] was already found in the dictionary", id); return; } fpInfos.Add(id, fpInfo); fpInfosObj.Add(id, obj); }