Example #1
0
        public ClassContext DeriveContext(ClassContext contextToBeDerived, IEnumerable <ClassContext> baseContexts)
        {
            ArgumentUtility.CheckNotNull("contextToBeDerived", contextToBeDerived);
            ArgumentUtility.CheckNotNull("baseContexts", baseContexts);

            List <MixinContext> mixins;
            List <Type>         interfaces;

            mixins     = new List <MixinContext> (contextToBeDerived.Mixins);
            interfaces = new List <Type> (contextToBeDerived.ComposedInterfaces);

            foreach (ClassContext baseContext in baseContexts)
            {
                ApplyInheritance(contextToBeDerived.Type, contextToBeDerived.Mixins, baseContext, mixins, interfaces);
            }

            return(new ClassContext(contextToBeDerived.Type, mixins, interfaces));
        }
Example #2
0
        public void ApplyInheritance(Type targetClass, IEnumerable <MixinContext> ownMixins, ClassContext baseContext, ICollection <MixinContext> mixins, ICollection <Type> interfaces)
        {
            Tuple <MixinContext, MixinContext> overridden_override = GetFirstOverrideThatIsNotOverriddenByBase(mixins, baseContext.Mixins);

            if (overridden_override != null)
            {
                string message = string.Format(
                    "The class {0} inherits the mixin {1} from class {2}, but it is explicitly "
                    + "configured for the less specific mixin {3}.",
                    targetClass.FullName,
                    overridden_override.Item2.MixinType.FullName,
                    baseContext.Type.FullName,
                    overridden_override.Item1.MixinType);
                throw new ConfigurationException(message);
            }

            ApplyInheritanceForMixins(ownMixins, baseContext, mixins);
            ApplyInheritanceForInterfaces(baseContext, interfaces);
        }
Example #3
0
 private static int CalculateHashCode(ClassContext classContext)
 {
     return(classContext.Type.GetHashCode()
            ^ EqualityUtility.GetXorHashCode(classContext.Mixins)
            ^ EqualityUtility.GetXorHashCode(classContext.ComposedInterfaces));
 }
Example #4
0
        /// <summary>
        /// Returns a new <see cref="ClassContext"/> with the same mixins and composed interfaces as this object, but a different target type.
        /// </summary>
        /// <param name="type">The target type to create the new <see cref="ClassContext"/> for.</param>
        /// <returns>A clone of this <see cref="ClassContext"/> for a different target type.</returns>
        public ClassContext CloneForSpecificType(Type type)
        {
            var newInstance = new ClassContext(type, Mixins, ComposedInterfaces);

            return(newInstance);
        }