/// <summary> /// Returns a <see cref="ClassContext"/> for the given target type, or <see langword="null" /> if the type is not configured in this /// <see cref="MixinConfiguration"/>. /// </summary> /// <param name="targetOrConcreteType">Base type for which a context should be returned or a concrete mixed type.</param> /// <returns>A <see cref="ClassContext"/> for the a given target type, or <see langword="null"/> if the type is not configured.</returns> /// <exception cref="ArgumentNullException">The <paramref name="targetOrConcreteType"/> parameter is <see langword="null"/>.</exception> /// <remarks> /// <para> /// Use this to extract a class context for a given target type from an <see cref="MixinConfiguration"/> as it would be used for mixed type code /// generation. Besides looking up the target type in the <see cref="ClassContexts"/> collection, this method also checks whether the class /// context is empty, and returns <see langword="null" /> if so. /// </para> /// <para> /// If <paramref name="targetOrConcreteType"/> is already a generated type, the <see cref="ClassContext"/> used for its generation is returned. /// </para> /// </remarks> public ClassContext GetContext(Type targetOrConcreteType) { ArgumentUtility.CheckNotNull("targetOrConcreteType", targetOrConcreteType); if (MixinTypeUtility.IsGeneratedConcreteMixedType(targetOrConcreteType)) { var classContextForConcreteType = MixinTypeUtility.GetClassContextForConcreteType(targetOrConcreteType); // Theoretically, classContextForConcreteType should never be null here. However, the heuristics of IsGeneratedConcreteMixedType can be // wrong, which is why we allow for a null classContextForConcreteType in the assertion below. Assertion.IsTrue(classContextForConcreteType == null || classContextForConcreteType.Type != targetOrConcreteType); return(classContextForConcreteType); } ClassContext context = ClassContexts.GetWithInheritance(targetOrConcreteType); Assertion.IsTrue(context == null || context.Type == targetOrConcreteType); if (context == null || context.IsEmpty()) { return(null); } else { return(context); } }
public void CircularSuppressingMixins() { MixinConfiguration configuration = new DeclarativeConfigurationBuilder(null) .AddType(typeof(MixinWithCircularSuppress1)) .AddType(typeof(MixinWithCircularSuppress2)) .BuildConfiguration(); ClassContext classContext = configuration.ClassContexts.GetExact(typeof(ClassWithMixins)); Assert.That(classContext.IsEmpty(), Is.True); }
public void IsEmpty_False_ComposedInterfaces() { var context = new ClassContext(typeof(BaseType1), new MixinContext[0], new[] { typeof(ICBT6Mixin3) }); Assert.That(context.IsEmpty(), Is.False); }