private object ProcessTemplateElem(IParentNode dataNode, IParentNode templateNode) { //create an object based on the template node, and insert it in the template node var nodeTypes = typeof (DynamicTemplate) .Assembly .GetTypes() .Where(type => type.Name.ToLower() == templateNode.Name.ToLower()); if (nodeTypes.Count() != 1) throw new Exception("Found " + nodeTypes.Count() + " of type " + templateNode.Name); var newType = nodeTypes.Single(); var newObj = newType.GetConstructor(Type.EmptyTypes).Invoke(new object[] {}); templateNode.Attributes().Do(attr => ProcessAttribute(dataNode, templateNode, attr, newObj)); //TODO: now do child elements of the templateNode //each element in the template will have data registered to it, //even if the parent never explicitly calls it. //A later optimization step could cull this out return newObj; }