FormBuilder code suggestions for POCO I am constructing a form builder in ASP.NET and I am wanting help with the structure of my POCO classes I have the following so far. I just don't see why I need to add to a list and then process it further again would their be a neater way to return a list of .net controls just to add to Panel using LoadControl(controlname).

POCO Class

public class FormClass
    {

        public string name { get; set; }
        public string displayName { get; set; }
        // This may actually work with Type, but I'm not so sure
        public string type { get; set; }
        public int length { get; set; }
        public bool key { get; set; }
        public bool required { get; set; }
        public string ControlType { get; set; }


    }


And then I'm using the following code to populate a list for further processing:

    PortalContext DBConext = new PortalContext();
    List&lt;FormClass&gt; formData = new List&lt;FormClass&gt;();
    List&lt;FormStructure&gt; frmstructList = new List&lt;FormStructure&gt;();
    public List&lt;FormStructure&gt; GetFormDataFromService()
    {   // XNamespace xNamespace = "http://CompanyName.AppName.Service.Contracts";



        Guid newGuid = Guid.NewGuid();
        XElement xdoc = XElement.Load(@"c:\form.xml");
        XNamespace ns = xdoc.GetDefaultNamespace();
        var classDetails = from classDetail in xdoc.Descendants(ns + "ClassDetails")
                           select new FormClass
                           {
                               name = (string)classDetail.Element(ns + "name"),
                               type = (string)classDetail.Element(ns + "type"),                                  
                               displayName = (string)classDetail.Element(ns + "displayName"),
                               length = (int)classDetail.Element(ns + "length"),
                               key = (bool)classDetail.Element(ns + "key"),
                               required = (bool)classDetail.Element(ns + "required"),
                           };

        foreach (FormClass classDetail in classDetails)
        {
              FormStructure frmstruct = new FormStructure();
              frmstruct.FormStructureId = newGuid;
              frmstruct.name = classDetail.name;
              frmstruct.displayname = classDetail.displayName;
              frmstruct.FormKey = classDetail.key;
              frmstruct.Required = classDetail.required;
              frmstruct.ClassName = "Incident";

              if (classDetail.type == "System.String")
                  frmstruct.ControlType = "TextBox";

              if (classDetail.type == "System.Enum") //to be dropdown
                  frmstruct.ControlType = "DropDown";

              if (classDetail.type == "System.DateTime")//date picker            
                  frmstruct.ControlType = "DateTimePicker";

              if (classDetail.type == "System.Boolean")
                  frmstruct.ControlType = "RadioButton";






              frmstructList.Add(frmstruct);


        }
        return frmstructList;


    }


XML Data



  &lt;name&gt;DisplayName&lt;/name&gt;

  &lt;displayName&gt;Display Name&lt;/displayName&gt;

  &lt;parent&gt;Object&lt;/parent&gt;

  &lt;type&gt;System.String&lt;/type&gt;

  &lt;length&gt;4000&lt;/length&gt;

  &lt;key&gt;false&lt;/key&gt;

  &lt;required&gt;false&lt;/required&gt;

&lt;/ArrayOfClassDetails&gt;
Your naming conventions are a bit off. Property names (i.e. in FormClass) are commonly PascalCase.
If you are not married to the XML file structure (i.e. it's under your control) then you can simplify the de/serialization quite a lot by using the XmlSerializer. For example:

public class ClassDetails
{
    public List&lt;FormClass&gt; Models { get; set; }
}

public static class XmlUtils
{

    public static void Save&lt;T&gt;(T obj, string filename, string namespace)
    {
         using (var writer = new StreamWriter(filename))
         {
             var serializer = new XmlSerializer(typeof(T), namespace);
             serializer.Serialize(writer, obj);
         }
    }

    public static T Load&lt;T&gt;(string filename, string namespace)
    {
         using (var writer = new StreamWriter(filename))
         {
             var serializer = new XmlSerializer(typeof(T), namespace);
             return (T)serializer.Deserialize(writer);
         }
    }
}


then you can load/save the file with:

var details = XmlUtils.Load&lt;ClassDetails&gt;(@"c:\form.xml", "http://CompanyName.AppName.Service.Contracts");

...

XmlUtils.Save(details, @"c:\form.xml", "http://CompanyName.AppName.Service.Contracts");

Rather than having a big if-else cascade I'd use a dictionary to map the types:

Dictionary&lt;string, string&gt; ModelToFormTypeMap = 
    new Dictionary&lt;string, string&gt; {
          { "System.String", "TextBox" },
          { "System.Enum", "DropDown" },
          ...
        };


then with an addition of a little bit of Linq you get 

XmlUtils.Load&lt;ClassDetails&gt;((@"c:\form.xml", "http://CompanyName.AppName.Service.Contracts")
        .Models
        .Select(m =&gt; new FormStructure 
                     {
                          FormStructureId = newGuid,
                          name = m.name,
                          displayname = m.displayName,
                          FormKey = m.key,
                          Required = m.required,
                          ClassName = "Incident",
                          ControlType = ModelToFormTypeMap[m.type]
                     })
         .ToList();