internal DataItemCollection(ComponentBase parent) { m_parent = parent; }
private static T FromXElement <T>(XNamespace ns, XElement element, Device parent) where T : ComponentBase { if (ns == null) { ns = string.Empty; } PropertyCollection props = ConfigParser.GetAttributes(element); T comp = default(T); // the reason for this is to prevent exposing a public, parameterless constructor for Device and Component var typeInfo = typeof(T).GetTypeInfo().DeclaredConstructors; var ctor = typeof(T).GetTypeInfo().DeclaredConstructors.First(c => c.GetParameters().ElementAt(0).ParameterType == typeof(PropertyCollection)); if (parent == null) { comp = (T)ctor.Invoke(new object[] { props }); } else { comp = (T)ctor.Invoke(new object[] { props, parent }); } if (comp is Device) { parent = comp as Device; } comp.XmlNodeName = element.Name.LocalName; var subcomps = (from d in element.Descendants(ns + NodeNames.Components) select d).FirstOrDefault(); if (subcomps != null) { foreach (var c in subcomps.Elements()) { Debug.WriteLine(c.Name); var subcomp = ComponentBase.FromXElement <Component>(ns, c, parent); if (subcomp != null) { comp.Components.Add(subcomp); } } } var dataItems = (from d in element.Descendants(ns + NodeNames.DataItems) select d).FirstOrDefault(); if (dataItems != null) { foreach (var di in dataItems.Elements()) { var item = DataItem.FromXElement(ns, di); if (item != null) { comp.DataItems.Add(item); } } } return(comp); }
public InvalidComponentException(ComponentBase component, string message) : base(message) { Component = component; }