/// <summary>
        /// Initializes a new instance of the <see cref="SwitchCaseDefinition"/> class.
        /// </summary>
        /// <param name="theCaseNode">The XML element defining this switch case</param>
        /// <param name="caseValue">The case value.</param>
        /// <param name="theManager">The data dictionary manager.</param>
        public SwitchCaseDefinition(XElement theCaseNode, string caseValue, DictionaryManager theManager)
        {
            Value = caseValue;
            Name = (theCaseNode.Element("Name") != null) ? theCaseNode.Element("Name").Value : string.Empty;

            if (theCaseNode.Element("Type") != null)
            {
                TypeDefinition caseType = theManager.GetElementType(theCaseNode.Element("Type").Value);
                TypeName = caseType.Name;
                Type = DictionaryManager.DereferenceTypeDef (caseType);
            }
            else
            {
                Type = theManager.GetNestedTypeDefinition(theCaseNode);
            }
        }
        /// <summary>
        /// Initializes a new instance of the AttributeDefinition class
        /// Constructor. Create a new object by reading contents from the XML node.
        /// </summary>
        /// <param name="attributeNode">The attribute node.</param>
        /// <param name="theManager">The manager.</param>
        /// <param name="parentType">The parent structure.</param>
        public AttributeDefinition(XElement attributeNode, DictionaryManager theManager, TypeDefinition parentType)
        {
            Name = attributeNode.Element("Name").Value;

            if (attributeNode.Element("Discriminator") == null)
            {
                Discriminator = string.Empty;
                HasDiscriminator = false;
            }
            else
            {
                Discriminator = attributeNode.Element("Discriminator").Value;
                HasDiscriminator = true;
            }

            if (attributeNode.Element("ByteOffset") != null)
            {
                int byteOffset;

                if (!int.TryParse(attributeNode.Element("ByteOffset").Value, out byteOffset))
                {
                    throw new DataDictionaryException("{0} : failed to parse ByteOffset as an integer", attributeNode.ToString());
                }

                ByteOffset = byteOffset;
            }

            HasLengthIndicator = false;
            if (attributeNode.Element("ByteSize") != null)
            {
                LengthIndicator = attributeNode.Element("ByteSize").Value;
                HasLengthIndicator = true;
            }

            // Type of the attribute may identified by a number that is the Ref field of a type somewhere
            // or by the name of the type 
            // or by the XML element nested within the attribute definition
            if (attributeNode.Element("Type") != null)
            {
                Type = theManager.GetElementType(attributeNode.Element("Type").Value);
            }
            else
            {
                // Nested type
                Type = theManager.GetNestedTypeDefinition(attributeNode);
            }

            // Follow aliases of typedefs so that the underlying type is stored
            TypeDefinition theType = Type;
            while (theType is TypedefDefinition)
            {
                theType = ((TypedefDefinition)theType).AliasedType;
            }

            // Finally, if we've just created a Switch type set the discriminator
            if (theType != null && theType.TypeId == TypeId.SwitchType)
            {
                SwitchDefinition theSwitchDefinition = Type as SwitchDefinition;

                if (string.IsNullOrEmpty(Discriminator))
                {
                    throw new DataDictionaryException("Attribute {0}: no discriminator supplied for Switch {1}", Name, Type.Name);
                }

                StructureDefinition structureDefinition = (StructureDefinition)parentType;
                theSwitchDefinition.Discriminator = structureDefinition.AttributeDefinitions[Discriminator];
                theSwitchDefinition.Discriminator.DiscriminatorFor = this;
            }
        }