private void CreateElement(AFDatabase afDatabase, string name, string path, string template) { // check if we have a parent element, if yes we get it, if not we set parent to database level Logger.InfoFormat("Parsing parameters"); dynamic parent = !string.IsNullOrEmpty(path)?(object)AFElement.FindObject(path, afDatabase):afDatabase; var elementTemplate = !string.IsNullOrEmpty(template) ? GetTemplate(afDatabase, template):null; //if parent is null, the passed string did not resolve to a parent if (parent == null) { throw new NoNullAllowedException(string.Format("The parent path passed {0} could not resolve to an AF object in the Database", path)); } // here we check if the FindObject method has returned a Element, if not an exception will be thrown if (!(parent is AFElement || parent is AFDatabase)) { throw new InvalidAFObjectException(); } // create the element Logger.InfoFormat("Creating the element"); parent.Elements.Add(name, elementTemplate); parent.CheckIn(); Logger.InfoFormat("Element {0} created.", name); }