示例#1
0
        /// <summary>
        /// Check validity of structureType. If error is found, appropriate exception is thrown.
        /// </summary>
        /// <param name="structureType">Type describing validated structure.</param>
        internal static void ThrowOnInvalid(Type structureType)
        {
            if (structureType.GetInterfaces().Count() != 1)
            {
                throw new TypeValidationException(
                          userMsg: "Structure type '{0}' has incorrect format, only IConfiguration interface can be implemented",
                          developerMsg: "StructureValidation::ThrowOnInvalid failed because on structure type '{0}' was found more than IConfiguration interface implemented",
                          validatedType: structureType
                          );
            }

            checkSignature(structureType, false);
            checkIDsValidity(StructureFactory.GetSectionProperties(structureType), StructureFactory.ResolveSectionID);
            checkSectionUniqueness(structureType);

            foreach (var sectionProperty in structureType.GetProperties())
            {
                if (sectionProperty.GetSetMethod() != null)
                {
                    throw new PropertyValidationException(
                              userMsg: "Setter detected on section property '{0}'. Section properties cannot have setters.",
                              developerMsg: "StructureValidation::ThrowOnInvalid failed because setter has been found on section property '{0}'",
                              validatedProperty: sectionProperty
                              );
                }

                var sectionType = sectionProperty.PropertyType;
                checkSignature(sectionType, true);
                checkIDsValidity(StructureFactory.GetOptionProperties(sectionType), StructureFactory.ResolveOptionID);
                checkOptionUniqueness(sectionType);
                checkTypeMatching(sectionType);
            }
        }
示例#2
0
 /// <summary>
 /// Check that every section in structure has unique ID.
 /// </summary>
 /// <param name="structureType">Type describing structure.</param>
 private static void checkSectionUniqueness(Type structureType)
 {
     checkIDUniqueness(StructureFactory.GetSectionProperties(structureType), StructureFactory.ResolveSectionID);
 }