/// <summary> /// Validates a type description. /// </summary> private void ValidateDescription(TypeDescription description) { OpaqueType opaque = description as OpaqueType; if (opaque != null) { if (!opaque.LengthInBitsSpecified) { m_warnings.Add(String.Format(CultureInfo.InvariantCulture, "Warning: The opaque type '{0}' does not have a length specified.", description.Name)); } if (IsNull(opaque.Documentation)) { m_warnings.Add(String.Format(CultureInfo.InvariantCulture, "Warning: The opaque type '{0}' does not have any documentation.", description.Name)); } } EnumeratedType enumerated = description as EnumeratedType; if (enumerated != null) { if (!enumerated.LengthInBitsSpecified) { throw Exception("The enumerated type '{0}' does not have a length specified.", description.Name); } } StructuredType structure = description as StructuredType; if (structure != null) { if (structure.Field == null || structure.Field.Length == 0) { structure.Field = new FieldType[0]; } int bitCount = 0; Dictionary<string,FieldType> fields = new Dictionary<string,FieldType>(); for (int ii = 0; ii < structure.Field.Length; ii++) { FieldType field = structure.Field[ii]; ValidateField(structure, fields, field); int fieldLength = GetFieldLength(field); if (fieldLength == -1) { if (bitCount % 8 != 0) { throw Exception("Field '{1}' in structured type '{0}' is not aligned on a byte boundary .", description.Name, field.Name); } bitCount = 0; } else { bitCount += fieldLength; } fields.Add(field.Name, field); } } }
/// <summary> /// Validates a type description. /// </summary> private void ValidateDescription(TypeDescription description) { OpaqueType opaque = description as OpaqueType; if (opaque != null) { if (!opaque.LengthInBitsSpecified) { m_warnings.Add(String.Format(CultureInfo.InvariantCulture, "Warning: The opaque type '{0}' does not have a length specified.", description.Name)); } if (IsNull(opaque.Documentation)) { m_warnings.Add(String.Format(CultureInfo.InvariantCulture, "Warning: The opaque type '{0}' does not have any documentation.", description.Name)); } } EnumeratedType enumerated = description as EnumeratedType; if (enumerated != null) { if (!enumerated.LengthInBitsSpecified) { throw Exception("The enumerated type '{0}' does not have a length specified.", description.Name); } } StructuredType structure = description as StructuredType; if (structure != null) { if (structure.Field == null || structure.Field.Length == 0) { structure.Field = new FieldType[0]; } int bitCount = 0; Dictionary <string, FieldType> fields = new Dictionary <string, FieldType>(); for (int ii = 0; ii < structure.Field.Length; ii++) { FieldType field = structure.Field[ii]; ValidateField(structure, fields, field); int fieldLength = GetFieldLength(field); if (fieldLength == -1) { if (bitCount % 8 != 0) { throw Exception("Field '{1}' in structured type '{0}' is not aligned on a byte boundary .", description.Name, field.Name); } bitCount = 0; } else { bitCount += fieldLength; } fields.Add(field.Name, field); } } }
/// <summary> /// Imports a type description. /// </summary> private void ImportDescription(TypeDescription description, string targetNamespace) { if (description == null) { return; } if (!IsValidName(description.Name)) { throw Exception("'{0}' is not a valid qualified name.", description.Name); } description.QName = new XmlQualifiedName(description.Name, targetNamespace); if (m_descriptions.ContainsKey(description.QName)) { throw Exception("The description name '{0}' already used by another description.", description.Name); } m_descriptions.Add(description.QName, description); }