コード例 #1
0
 /// <summary>
 /// Applies constraints described by concept type.
 /// </summary>
 /// <param name="conceptType">A static type describing concept.</param>
 /// <exception cref="ConstraintViolationException">One or more constraints defined by concept type are violated.</exception>
 /// <exception cref="ArgumentException"><paramref name="conceptType"/> is not marked with <see cref="ConceptAttribute"/>.</exception>
 public static void Assert(Type conceptType)
 {
     if (!conceptType.IsDefined <ConceptAttribute>())
     {
         throw new ArgumentException(ExceptionMessages.ConceptTypeInvalidAttribution <ConceptAttribute>(conceptType), nameof(conceptType));
     }
     try
     {
         // run class constructor for concept type and its parents
         for (Type?lookup = conceptType; lookup is not null; lookup = lookup.BaseType)
         {
             RunClassConstructor(conceptType.TypeHandle);
         }
     }
     catch (TypeInitializationException e) when(e.InnerException is ConstraintViolationException violation)
     {
         Capture(violation).Throw();
     }
 }