public List <List <GUI_content> > GetContentMatrix() { List <List <GUI_content> > rowContents = new List <List <GUI_content> >(); List <GUI_content> tempList = new List <GUI_content>(); int rows = GetTotalRows(); int column = 1; int row = 0; foreach (GUI_content content in itemsContent) { tempList.Add(content); if (column == columns) { rowContents.Add(tempList.ShallowCopy()); tempList.Clear(); column = 1; row++; continue; } column++; } if (row != rows) { rowContents.Add(tempList.ShallowCopy()); } return(rowContents); }
private void VisitInternal(CXCursor cursor, CXCursor parent, List <CXCursor> parents) { VisitChild(cursor, parents.ShallowCopy().Select(c => new VisitorCursor(c)).ToList()); clang.visitChildren(cursor, (CXCursor ccursor, CXCursor cparent, IntPtr cdata) => { var newParents = parents.ShallowCopy(); newParents.Add(cursor); VisitInternal(ccursor, cursor, newParents); return(CXChildVisitResult.CXChildVisit_Continue); }, new CXClientData(IntPtr.Zero)); }
// Construction public CChatPlayer( EPersistenceID persistence_id, ESessionID session_id, string name, List< EPersistenceID > ignore_list ) { PersistenceID = persistence_id; SessionID = session_id; Name = name; ignore_list.ShallowCopy( m_IgnoreList ); }
public void ShallowCopy() { // Arrange List <int> list = new List <int>(new int[] { 1, 2, 3 }); // Act List <int> copy = list.ShallowCopy(); // Assert; for (int i = 0; i < list.Count; i++) { Assert.That(list[i] == copy[i]); } }
public CXChildVisitResult Visit(CXCursor cursor, CXCursor parent, IntPtr data) { if (cursor.IsInSystemHeader()) { return(CXChildVisitResult.CXChildVisit_Continue); } var parents = new List <CXCursor> { parent }; VisitInternal(cursor, parent, parents.ShallowCopy()); return(CXChildVisitResult.CXChildVisit_Continue); }
/// <summary> /// Parses an NBT list tag given the starting data. /// </summary> private static void ParseList(byte[] data, IEnumerable <byte> afterHeader, object typeObj, List <PropertyInfo> possibleOriginal, int dataStart, ref int nextIndex) { //Get the length of the list. int listLen = BitConverter.ToInt32(afterHeader.Skip(1).Take(4).Reverse().ToArray()); //If the list is zero length, just shuffle up the next index and return. if (listLen == 0) { nextIndex = dataStart + 5; return; } //Get the list type. NBT_Tag tag = (NBT_Tag)afterHeader.ElementAt(0); if (tag == NBT_Tag.EndCompound && listLen != 0) { throw new Exception("NBT list cannot be of type 'EndCompound' and have a non-zero length."); } Type listType = GetTypeFromTag(tag); //Shallow copy the original list to not modify it. List <PropertyInfo> possible = possibleOriginal.ShallowCopy(); //Whittle down the possible properties (must be lists with generic parameter (if found). for (int i = 0; i < possible.Count; i++) { //Make sure it's a list. (todo: check) if (possible[i].PropertyType.GetGenericTypeDefinition() != typeof(List <>) || !possible[i].PropertyType.IsGenericType || possible[i].PropertyType.GetGenericArguments().Length == 0) { possible.RemoveAt(i); i--; continue; } //Is the list generic of the right type (if type required). if (listType != null && possible[i].PropertyType.GetGenericArguments()[0] != listType) { possible.RemoveAt(i); i--; continue; } } //Make a list of the type and get values for the straightforward value types. if (listType != null) { var lt = typeof(List <>).MakeGenericType(listType); var list = (System.Collections.IList)Activator.CreateInstance(lt); int startIndex = 5; for (int i = 0; i < listLen; i++) { list.Add(GetTagValue(tag, afterHeader.Skip(startIndex), startIndex, ref startIndex)); } //Set next, return the list. nextIndex = dataStart + startIndex; possible.SetValue(typeObj, list); return; } //If it's a list of lists, give up (for now) and just emulate RDLP. if (tag == NBT_Tag.List) { dataStart += 5; for (int i = 0; i < listLen; i++) { ParseList(data, data.Skip(dataStart), new NBTCompound(), new List <PropertyInfo>(), dataStart, ref nextIndex); dataStart = nextIndex; } } //If it's a list of compounds, get the listed type from the NBTList tag. if (tag == NBT_Tag.StartCompound) { foreach (var prop in possible) { //Yes, use it to get the types for the list indices. listType = prop.PropertyType.GetGenericArguments()[0]; var lt = typeof(List <>).MakeGenericType(listType); var list = (System.Collections.IList)Activator.CreateInstance(lt); dataStart += 5; for (int i = 0; i < listLen; i++) { //Create an instance of that type. var listPropObj = Activator.CreateInstance(listType); var nbtProps = listType.GetProperties() .Where(x => x.GetCustomAttribute(typeof(NBTItem)) != null) .ToList(); //Process all tags for the object. ProcessTag(data, ref dataStart, listPropObj, nbtProps); list.Add(listPropObj); } //Set list property. prop.SetValue(typeObj, list); } //If no possible properties, just emulate with an empty class. if (possible.Count == 0) { dataStart += 5; for (int i = 0; i < listLen; i++) { //Create an instance of some class (doesn't really matter). var listPropObj = Activator.CreateInstance(typeof(NBTCompound)); //Process all tags for the object. ProcessTag(data, ref dataStart, listPropObj, new List <PropertyInfo>()); } } //Set the new starting index. nextIndex = dataStart; } }
// Construction public CAnnouncePlayerToChatServerRequest( ESessionID session_id, EPersistenceID persistence_id, string name, List< EPersistenceID > ignore_list ) : base() { SessionID = session_id; PersistenceID = persistence_id; Name = name; IgnoreList = new List< EPersistenceID >(); ignore_list.ShallowCopy( IgnoreList ); }