/// <summary> /// Ensure that we only allow single instances of some objects to be added /// as direct children. /// </summary> public override void AddChild(CIElement aChild) { bool exception = false; // if (aChild is CIEventList && Events != null) { exception = true; } else if (aChild is CISymbolDictionary && Symbols != null) { exception = true; } else if (aChild is CIMessageDictionary && Messages != null) { exception = true; } else if (aChild is CISourceElement && Source != null) { exception = true; } else if (aChild is CISummarisableEntityList && Summaries != null) { exception = true; } else if (aChild is CIHeader && Header != null) { exception = true; } else if (aChild is CIReportInfo && ReportInfo != null) { exception = true; } else { // These aren't mandatory, but there should only be one... int count = -1; if (aChild is CIInfoHW) { count = base.ChildrenByType <CIInfoHW>().Count; } else if (aChild is CIInfoSW) { count = base.ChildrenByType <CIInfoSW>().Count; } if (count > 1) { throw new ArgumentException("An instance of the specified object has already been added to the container"); } } if (exception) { throw new ArgumentException("Can only add a single instance of " + aChild.GetType() + " to the container"); } base.AddChild(aChild); }
public override void AddChild(CIElement aChild) { if (aChild.GetType() != typeof(CIMemoryInfo)) { throw new ArgumentException("Child must be a CIMemoryInfo"); } base.AddChild(aChild); }
public void TryAutoPopulateColumns(CIElement aElement) { Type customAttributeType = typeof(CIDBAttributeColumn); Type thisObjectType = aElement.GetType(); object[] attribs = thisObjectType.GetCustomAttributes(customAttributeType, true); if (attribs != null && attribs.Length > 0) { ExtractAttributeColumns(attribs, aElement); } }
public override void AddChild(CIElement aChild) { // We support 4 types of children at the moment. // Registers, stacks and exit info, messages. if (aChild.GetType() == typeof(CIExitInfo)) { if (base.ChildrenByType <CIExitInfo>().Count != 0) { throw new ArgumentException("Exit Info already associated with the thread"); } } else if (aChild.GetType() == typeof(CIThreadRegisterListCollection)) { if (base.ChildrenByType <CIThreadRegisterListCollection>().Count != 0) { throw new ArgumentException("Registers already associated with the thread"); } } else if (aChild.GetType() == typeof(CIStack)) { CIStack stack = (CIStack)aChild; // We must ensure we don't already have a stack of the specified mode // associated with the thread. bool exists = iStacks.ContainsKey(stack.Type); if (exists) { throw new ArgumentException(ArmRegisterBankUtils.BankAsStringLong(stack.Type) + " mode stack already registered with thread"); } else { iStacks.Add(stack.Type, stack); } } // base.AddChild(aChild); }
public void TryAutoPopulateCells(CIElement aElement) { if (AutoPopulate) { SortedDictionary <int, CIDBRow> rows = new SortedDictionary <int, CIDBRow>(); Type customAttributeType = typeof(CIDBAttributeCell); Type thisObjectType = aElement.GetType(); // Get properties featuring the CIDBAttribute PropertyInfo[] propertyInfo = thisObjectType.GetProperties(); foreach (PropertyInfo p in propertyInfo) { object[] attribs = p.GetCustomAttributes(customAttributeType, true); if (attribs != null && attribs.Length > 0) { object propertyValue = p.GetValue(aElement, null); ExtractAttributeCells(p.ToString(), aElement, attribs, propertyValue, rows); } } // Same, but get methods featuring the CIDBAttribute MethodInfo[] methodInfo = thisObjectType.GetMethods(); foreach (MethodInfo m in methodInfo) { object[] attribs = m.GetCustomAttributes(customAttributeType, true); if (attribs != null && attribs.Length > 0) { // We only support this attribute on methods that don't contain // any arguments int paramCount = m.GetParameters().Length; if (paramCount != 0) { throw new NotSupportedException("Method: " + m.ToString() + " has CIDBAttribute but non-empty parameter list -> Not supported"); } // Get property value object propertyValue = m.Invoke(aElement, null); ExtractAttributeCells(m.ToString(), aElement, attribs, propertyValue, rows); } } // Since the list is already sorted for us, just add the items in order foreach (KeyValuePair <int, CIDBRow> kvp in rows) { this.Add(kvp.Value); } } }