private T AddNewObject <T>(DocumentBodyItemChoiceType type) where T : class, new() { T t = new T(); lock (this) { this.itemsElementNameField.Add(type); this.itemsField.Add(t); } return(t); }
private T GetObjectArray <T>(int p, DocumentBodyItemChoiceType type) where T : class { lock (this) { int pos = GetObjectIndex(type, p); if (pos < 0 || pos >= this.itemsField.Count) { return(null); } return(itemsField[pos] as T); } }
private void RemoveObject(DocumentBodyItemChoiceType type, int p) { lock (this) { int pos = GetObjectIndex(type, p); if (pos < 0 || pos >= this.itemsField.Count) { return; } itemsElementNameField.RemoveAt(pos); itemsField.RemoveAt(pos); } }
private int SizeOfArray(DocumentBodyItemChoiceType type) { lock (this) { int size = 0; for (int i = 0; i < itemsElementNameField.Count; i++) { if (itemsElementNameField[i] == type) { size++; } } return(size); } }
private List <T> GetObjectList <T>(DocumentBodyItemChoiceType type) where T : class { lock (this) { List <T> list = new List <T>(); for (int i = 0; i < itemsElementNameField.Count; i++) { if (itemsElementNameField[i] == type) { list.Add(itemsField[i] as T); } } return(list); } }
private static int GetObjectIndex(List <DocumentBodyItemChoiceType> names, DocumentBodyItemChoiceType type, int p) { int num2 = 0; for (int i = 0; i < names.Count; i++) { if (names[i] == type) { if (num2 == p) { return(i); } num2++; } } return(-1); }
private void SetObject <T> (DocumentBodyItemChoiceType type, int p, T obj) where T : class { lock (this) { int pos = GetObjectIndex(type, p); if (pos < 0 || pos >= this.itemsField.Count) { return; } if (this.itemsField[pos] is T) { this.itemsField[pos] = obj; } else { throw new Exception(string.Format(@"object types are difference, itemsField[{0}] is {1}, and parameter obj is {2}", pos, this.itemsField[pos].GetType().Name, typeof(T).Name)); } } }
private int GetObjectIndex(DocumentBodyItemChoiceType type, int p) { int index = -1; int pos = 0; for (int i = 0; i < itemsElementNameField.Count; i++) { if (itemsElementNameField[i] == type) { if (pos == p) { index = i; break; } else { pos++; } } } return(index); }