private void AddGenericDefinitionsRecursively(InvolvedTypeStore involvedTypes)
 {
     foreach (var type in involvedTypes.Where(t => t.Type.IsGenericType))
     {
         var genericType = type.Type;
         while (genericType.IsGenericType && genericType.GetGenericTypeDefinition() != genericType)
         {
             var genericTypeDefinition = genericType.GetGenericTypeDefinition();
             genericType = involvedTypes.GetOrCreateValue(genericTypeDefinition).Type;
         }
     }
 }
        public InvolvedType[] FindInvolvedTypes()
        {
            var involvedTypes = new InvolvedTypeStore();
            var classContexts = _mixinConfiguration.GetProperty("ClassContexts");

            foreach (var assembly in _assemblies)
            {
                try
                {
                    foreach (var type in assembly.GetTypes())
                    {
                        var classContext = classContexts.CallMethod("GetWithInheritance", type);
                        if (classContext != null)
                        {
                            var involvedType          = involvedTypes.GetOrCreateValue(type);
                            var targetClassDefinition = GetTargetClassDefinition(type, classContext);
                            involvedType.ClassContext          = classContext;
                            involvedType.TargetClassDefinition = targetClassDefinition;

                            foreach (var mixinContext in classContext.GetProperty("Mixins"))
                            {
                                var mixinType = mixinContext.GetProperty("MixinType").To <Type> ();
                                var mixin     = involvedTypes.GetOrCreateValue(mixinType);
                                mixin.TargetTypes.Add(involvedType, GetMixinDefiniton(mixinType, targetClassDefinition));
                            }
                        }

                        // also add classes which inherit from Mixin<> or Mixin<,>, but are actually not used as Mixins (not in ClassContexts)
                        if (_remotionReflector.IsInheritedFromMixin(type) && !_remotionReflector.IsInfrastructureType(type))
                        {
                            involvedTypes.GetOrCreateValue(type);
                        }
                    }
                }
                catch (ReflectionTypeLoadException ex)
                {
                    var loaderExceptionLog = new StringBuilder();
                    foreach (var loaderException in ex.LoaderExceptions)
                    {
                        loaderExceptionLog.AppendFormat("   {1}{0}", Environment.NewLine, loaderException.Message);
                    }

                    XRef.Log.SendWarning("Unable to analyze '{1}' in '{2}' because some referenced assemblies could not be loaded: {0}{3}",
                                         Environment.NewLine, assembly.FullName, assembly.Location, loaderExceptionLog);
                }
            }

            var additionalTypesCollector = new AdditionalTypesCollector();

            foreach (IVisitableInvolved involvedType in involvedTypes)
            {
                involvedType.Accept(additionalTypesCollector);
            }

            foreach (var additionalType in additionalTypesCollector.AdditionalTypes)
            {
                involvedTypes.GetOrCreateValue(additionalType);
            }

            AddGenericDefinitionsRecursively(involvedTypes);

            return(involvedTypes.ToArray());
        }