private ElementListValue ParseElementType(String name, String typeSpec)
 {
     String type = "";
     UInt16? size = null;
     String sizeText = null;
     try
     {
         int sizeBracketPos = typeSpec.IndexOf('[');
         if (sizeBracketPos > 0)
         {
             int sizeStartPos = sizeBracketPos + 1;
             type = typeSpec.Substring(0, sizeBracketPos).Trim().ToUpper();
             int sizeEndBracketPos = typeSpec.IndexOf(']', sizeStartPos);
             if (sizeEndBracketPos > sizeBracketPos)
             {
                 try
                 {
                     sizeText = typeSpec.Substring(sizeStartPos, sizeEndBracketPos - sizeStartPos).Trim();
                     size = System.Convert.ToUInt16(sizeText);
                     sizeText = null;
                 }
                 catch (System.FormatException)  // sizeText will be contain the size variable name
                 {
                 }
             }
         }
         else if (sizeBracketPos == -1)
         {
             type = typeSpec.Trim().ToUpper();
         }
     }
     catch (Exception)
     {
         return null;
     }
     ElementListValue val = new ElementListValue();
     val.Name = name;
     val.Type = type;
     val.Size = size;
     val.SizeName = sizeText;
     return val;
 }
 private void LoadElements()
 {
     _ElementList = new ObservableCollection<ElementListValue>();
     foreach (XmlNode e in settings.ChildNodes)
     {
         if (e.NodeType == XmlNodeType.Element && e.Name == "element")
         {
             XmlAttribute name = (XmlAttribute)e.Attributes.GetNamedItem("name");
             XmlAttribute type = (XmlAttribute)e.Attributes.GetNamedItem("type");
             XmlAttribute value = (XmlAttribute)e.Attributes.GetNamedItem("value");
             XmlAttribute excludeFromChecksum = (XmlAttribute)e.Attributes.GetNamedItem("excludefromchecksum");
             if (name != null && type != null)
             {
                 ElementListValue element = ParseElementType(name.Value, type.Value);
                 if (element != null)
                 {
                     if (value != null)
                     {
                         element.ValueString = value.Value;
                         if (element.ValueIsHex)
                         {
                             element.ValueBytes = SystemServices.HexToBytes(element.ValueString);
                             element.Size = (UInt16)element.ValueBytes.Length;
                         }
                         else
                             element.Size = (UInt16)element.ValueString.Length;
                     }
                     if (excludeFromChecksum != null)
                         element.ExcludeFromChecksum = excludeFromChecksum.Value == "true";
                     _ElementList.Add(element);
                 }
             }
             else if (value != null)
             {
                 ElementListValue element = new ElementListValue();
                 element.Type = "BYTE";
                 element.ValueString = value.Value;
                 if (element.ValueIsHex)
                 {
                     element.ValueBytes = SystemServices.HexToBytes(element.ValueString);
                     element.Size = (UInt16)element.ValueBytes.Length;
                 }
                 else
                     element.Size = (UInt16)element.ValueString.Length;
                 if (excludeFromChecksum != null)
                     element.ExcludeFromChecksum = excludeFromChecksum.Value == "true";
                 _ElementList.Add(element);
             }
         }
     }
 }