/// <summary> /// Creates and populates an IEnumerabe{T} using the result set of a SQL querty /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public IEnumerable <T> Instantiate <T>() where T : new() { var list = new _InternalEnumerable <T> (); using (var conn = new SqlConnection(GetConnectionString())) { conn.Open(); var command = new SqlCommand(sql, conn); var rdr = command.ExecuteReader(); var sw = new System.Diagnostics.Stopwatch(); sw.Start(); Action <T> act = null; if (typeof(T).IsSubclassOf(typeof(IDataInstantiable))) { act = (x) => (x as IDataInstantiable).Hydrate(rdr); } else { var count = rdr.FieldCount; var names = new string[count]; var string_comparer = new stringComparer(); for (var i = 0; i < count; i++) { names[i] = rdr.GetName(i); } var explicityly_mapped_properties = from p in typeof(T).GetProperties() let c = p.GetCustomAttributes(typeof(ColumnMappingAttribute), false) where c.Length > 0 && p.CanWrite select new { ColumnName = ((ColumnMappingAttribute)c[0]).ColumnName, Property = p }; var implicitly_mapped_properties = from p in typeof(T).GetProperties() where p.GetCustomAttributes(typeof(ColumnMappingAttribute), false).Length == 0 && names.Contains(p.Name, string_comparer) && p.CanWrite select new { ColumnName = p.Name, Property = p }; var properties = explicityly_mapped_properties.Union(implicitly_mapped_properties); act = (x) => { foreach (var p in properties) { p.Property.SetValue(x, rdr[p.ColumnName], null); } }; } while (rdr.Read()) { var o = new T(); act(o); list.xs.Add(o); } sw.Stop(); System.Diagnostics.Debug.WriteLine(sw.ElapsedMilliseconds); } return(list); }
string asterisk(float x, float y, float startDist, float rayLength, int depth=0, bool visible=false, string Orig="") { string retstr = ""; string U = rayOfSight (x,y,startDist, rayLength, Vector2.up,depth,visible,Orig); string D = rayOfSight (x,y,startDist+0.5f, rayLength, Vector2.down,depth,visible,Orig); string L = rayOfSight (x,y,startDist, 10, Vector2.left,depth,visible,Orig); string R = rayOfSight (x,y,startDist, 10, Vector2.right,depth,visible,Orig); string RGR = rayOfSight (x,y-2,startDist, rayLength, Vector2.right,depth,visible,Orig); string LGR = rayOfSight (x,y-2,startDist, rayLength, Vector2.left,depth,visible,Orig); string UR = rayOfSight (x,y,startDist, rayLength, new Vector2(1,1),depth,visible,Orig); string UL = rayOfSight (x,y,startDist, rayLength, new Vector2(-1,1),depth,visible,Orig); string DR = rayOfSight (x,y,startDist, rayLength, new Vector2(1,-1),depth,visible,Orig); string DL = rayOfSight (x,y,startDist, rayLength, new Vector2(-1,-1),depth,visible,Orig); string URR = rayOfSight (x,y,startDist, rayLength, new Vector2(2,1),depth,visible,Orig); string UUR = rayOfSight (x,y,startDist, rayLength, new Vector2(1,2),depth,visible,Orig); string DRR = rayOfSight (x,y,startDist, rayLength, new Vector2(2,-1),depth,visible,Orig); string UUL = rayOfSight (x,y,startDist, rayLength, new Vector2(-1,2),depth,visible,Orig); string ULL = rayOfSight (x,y,startDist, rayLength, new Vector2(-2,1),depth,visible,Orig); string DLL = rayOfSight (x,y,startDist, rayLength, new Vector2(-2,-1),depth,visible,Orig); if (U!="NULL") retstr += Orig+(" " + U + "; "); if (D!="NULL") retstr += Orig+(" " + D + "; "); if (L!="NULL") retstr += Orig+(" " + L + "; "); if (R!="NULL") retstr += Orig+(" " + R + "; "); if (LGR!="NULL") retstr += Orig+(" " + LGR + "; "); if (RGR!="NULL") retstr += Orig+(" " + RGR + "; "); if (UR!="NULL") retstr += Orig+(" " + UR + "; "); if (UL!="NULL") retstr += Orig+(" " + UL + "; "); if (DR!="NULL") retstr += Orig+(" " + DR + "; "); if (DL!="NULL") retstr += Orig+(" " + DL + "; "); if (URR!="NULL") retstr += Orig+(" " + URR + "; "); if (UUR!="NULL") retstr += Orig+(" " + UUR + "; "); if (DRR!="NULL") retstr += Orig+(" " + DRR + "; "); if (UUL!="NULL") retstr += Orig+(" " + UUL + "; "); if (ULL!="NULL") retstr += Orig+(" " + ULL + "; "); if (DLL!="NULL") retstr += Orig+(" " + DLL + "; "); string[] paths = retstr.Split (';'); ArrayList PathList = new ArrayList (); PathList.AddRange (paths); stringComparer ab = new stringComparer (); PathList.Sort(ab); string PathToTraverse = ""; foreach (string path in PathList) { //print (path); if (path.Trim (' ') != "") { string PATH = ""; //print ("POTENTIAL PATH: " + path); string[] terms = path.Split (' '); foreach (string term in terms) { if (term.Trim (' ') != "") { if(term.Length>2&&term[2]!='-'&&term[1]!='-') { if (term[0]=='U'&&term[1]=='U'&&term[2]=='L') PATH+= "HIGH JUMP LEFT -- "; else if (term[0]=='U'&&term[1]=='U'&&term[2]=='R') PATH+= "HIGH JUMP RIGHT -- "; else if (term[0]=='U'&&term[1]=='L'&&term[2]=='L') PATH+= "LONG JUMP LEFT -- "; else if (term[0]=='U'&&term[1]=='R'&&term[2]=='R') PATH+= "LONG JUMP RIGHT -- "; else if (term[0]=='D'&&term[1]=='L'&&term[2]=='L') PATH+= "SLIGHTLY FALL LEFT -- "; else if (term[0]=='D'&&term[1]=='R'&&term[2]=='R') PATH+= "SLIGHTLY FALL RIGHT -- "; } else if(term.Length>1&&term[1]!='-') { if (term[0]=='U'&&term[1]=='L') PATH+= "JUMP LEFT -- "; else if (term[0]=='U'&&term[1]=='R') PATH+= "JUMP RIGHT -- "; else if (term[0]=='D'&&term[1]=='L') PATH+= "FALL LEFT -- "; else if (term[0]=='D'&&term[1]=='R') PATH+= "FALL RIGHT -- "; } else { //if (term[0]=='D') PATH+= "MOVE DOWN -- "; //else if (term[0]=='U') PATH+= "JUMP -- "; if (term[0]=='L') PATH+= "MOVE LEFT -- "; else if (term[0]=='R') PATH+= "MOVE RIGHT -- "; } if(term.Length>6){ if(term[term.Length-1]=='T'&&term[term.Length-2]=='A'&&term[term.Length-3]=='L'&&term[term.Length-4]=='P'){ if(term[term.Length-5]=='R'){ PATH+= ("PLATFORM CUTOFF AT RIGHT -- "); } else if(term[term.Length-5]=='L'){ PATH+= ("PLATFORM CUTOFF AT LEFT -- "); } } else PATH+= (term+" "); } else PATH+= (term+" "); } } //print ("PATH REALIZED: " + PATH); //if(depth==0) print ("EMBRYONIC PATH: " + path); PathToTraverse = PATH; break; } } //print ("CHOSEN PATH: " + PathToTraverse); if (depth == 0) retstr = PathToTraverse; //print (retstr); return retstr; }