Esempio n. 1
0
        /// <summary>
        /// Check imported interfaces.
        /// </summary>
        /// <param name="checkerData">Used types and assemblies candidates.</param>
        /// <param name="evaluator">The project evaluator.</param>
        private void CheckImportedInterfaces(CheckerSharedData checkerData, IProjectEvaluator evaluator)
        {
            IEnumerable <TypeReference> typeReferences = evaluator.ProjectImportedTypesDefinitions
                                                         .SelectMany(item => item.GetInterfaces());

            IMetadataScope forwardedFrom;

            foreach (TypeReference typeRef in typeReferences)
            {
                try
                {
                    TypeDefinition typeDef = typeRef.Resolve(out forwardedFrom);
                    checkerData.RemoveFromCandidates(forwardedFrom);
                    if (typeDef != null)
                    {
                        _helper.Check(typeDef, checkerData);
                    }

                    if (!checkerData.HasCandidateReferences)
                    {
                        break;
                    }
                }
                catch (Exception ex)
                {
                    throw Error.CheckType(typeRef.AssemblyQualifiedName(),
                                          string.Format(Resources.CleanExecutor_CheckInteropTypeException, typeRef.AssemblyQualifiedName()), ex);
                }
            }
        }
 /// <summary>
 /// Performs checking of attributes of types of assembly.
 /// </summary>
 /// <param name="sharedData">Used types and assemblies candidates.</param>
 /// <param name="evaluator">The project evaluator.</param>
 public void Check(CheckerSharedData sharedData, IProjectEvaluator evaluator)
 {
     foreach (TypeDefinition type in evaluator.ProjectTypesDefinitions)
     {
         _helper.Check(type, sharedData);
         if (!sharedData.HasCandidateReferences)
         {
             return;
         }
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Performs assembly's types checking.
        /// </summary>
        /// <param name="sharedData">Used types and assemblies candidates.</param>
        /// <param name="evaluator">The project evaluator.</param>
        public void Check(CheckerSharedData sharedData, IProjectEvaluator evaluator)
        {
            var query = (from reference in sharedData.CandidateReferences
                         join assemblyRef in evaluator.ManifestAssemblies
                         on reference.FullName.ToUpper() equals assemblyRef.FullName.ToUpper()
                         select reference).ToList();

            foreach (var reference in query)
            {
                sharedData.RemoveFromCandidates(reference);
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Performs assembly's types checking.
 /// </summary>
 /// <param name="sharedData">Used types and assemblies candidates.</param>
 /// <param name="evaluator">The project evaluator.</param>
 public void Check(CheckerSharedData sharedData, IProjectEvaluator evaluator)
 {
     try
     {
         var reader = new ResourcesReader(evaluator);
         CheckXamlDeclaredTypes(sharedData, evaluator, reader.GetXamlDeclaredTypes());
     }
     catch (Exception ex)
     {
         throw Error.CheckType(evaluator.ProjectAssembly.FullName,
                               Resources.BamlTypesChecker_CheckTypeException, ex);
     }
 }
Esempio n. 5
0
 /// <summary>
 /// Check imported classes.
 /// </summary>
 /// <param name="checkerData">Used types and assemblies candidates.</param>
 /// <param name="evaluator">The project evaluator.</param>
 private void CheckImportedClasses(CheckerSharedData checkerData, IProjectEvaluator evaluator)
 {
     foreach (TypeDefinition typeDef in evaluator.ProjectImportedTypesDefinitions)
     {
         try
         {
             _helper.Check(typeDef, checkerData);
         }
         catch (Exception ex)
         {
             throw Error.CheckType(typeDef.AssemblyQualifiedName(),
                                   string.Format(Resources.CleanExecutor_CheckInteropTypeException, typeDef.AssemblyQualifiedName()), ex);
         }
     }
 }
Esempio n. 6
0
        /// <summary>
        /// Check assembly types.
        /// </summary>
        /// <param name="assemblyDefinition">The assembly.</param>
        private void CheckAssemblyTypes(AssemblyDefinition assemblyDefinition, CheckerSharedData checkerData, IProjectEvaluator evaluator)
        {
            var referencedAssemblyTypes = evaluator.ProjectTypesReferences
                                          .Select(projectTypeRef => projectTypeRef)
                                          .Join(assemblyDefinition.Modules.GetTypesDefinitions().Where(moduleType => moduleType.BaseType != null),
                                                projectTypeRef => projectTypeRef.FullName.ToLower(),
                                                moduleType => moduleType.FullName.ToLower(),
                                                (projectTypeRef, moduleType) => projectTypeRef);

            foreach (TypeDefinition referencedType in referencedAssemblyTypes)
            {
                if (checkerData.UsedTypes.Contains(referencedType.AssemblyQualifiedName()))
                {
                    _memberRefsCheckHelper.Check(referencedType, checkerData, evaluator);
                    if (!checkerData.HasCandidateReferences)
                    {
                        break;
                    }
                }
                else
                {
                    checkerData.RemoveFromCandidates(referencedType.Scope);
                    if (!checkerData.HasCandidateReferences)
                    {
                        break;
                    }

                    _classCheckHeper.Check(referencedType, checkerData);
                    if (!checkerData.HasCandidateReferences)
                    {
                        break;
                    }

                    _interfaceCheckHelper.Check(referencedType, checkerData);
                    if (!checkerData.HasCandidateReferences)
                    {
                        break;
                    }

                    _memberRefsCheckHelper.Check(referencedType, checkerData, evaluator);
                    if (!checkerData.HasCandidateReferences)
                    {
                        break;
                    }
                }
            }
        }
Esempio n. 7
0
 /// <summary>
 /// Performs dependent assemblies checking.
 /// </summary>
 /// <param name="sharedData">Used types and assemblies candidates.</param>
 /// <param name="evaluator">The project evaluator.</param>
 public void Check(CheckerSharedData sharedData, IProjectEvaluator evaluator)
 {
     foreach (AssemblyDefinition manifestAssemblyDefinition in evaluator.ManifestAssemblies)
     {
         try
         {
             CheckAssemblyTypes(manifestAssemblyDefinition, sharedData, evaluator);
             if (!sharedData.HasCandidateReferences)
             {
                 break;
             }
         }
         catch (Exception ex)
         {
             ex.Data.Add("AssemblyDefinition", manifestAssemblyDefinition.FullName);
             throw;
         }
     }
 }
Esempio n. 8
0
        /// <summary>
        /// Checks project references in order to find unused.
        /// </summary>
        /// <returns>Returns list of unused references.</returns>
        public IEnumerable <ProjectReference> Check()
        {
            var checkers = from checker in GetTypeCheckers()
                           orderby checker.OrderNumber ascending
                           select checker;

            using (var checkerData = new CheckerSharedData(_evaluator.GetCandidates()))
            {
                foreach (var checker in checkers)
                {
                    checker.Check(checkerData, _evaluator);

                    if (!checkerData.HasCandidateReferences)
                    {
                        break;
                    }
                }
                return(checkerData.CandidateReferences.ToList());
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Checking assembly's types which are used in BAML.
        /// </summary>
        /// <param name="sharedData">Used types and assemblies candidates.</param>
        /// <param name="evaluator">The project evaluator.</param>
        /// <param name="declaredTypes">Declared in BAML types.</param>
        private void CheckXamlDeclaredTypes(CheckerSharedData sharedData, IProjectEvaluator evaluator, IEnumerable <XamlTypeDeclaration> declaredTypes)
        {
            var xamlTypeResolver = new XamlTypeResolver(evaluator);

            foreach (var type in declaredTypes)
            {
                var typeDef = xamlTypeResolver.Resolve(type);
                if (typeDef != null && !sharedData.IsUsedTypeExists(typeDef.AssemblyQualifiedName()))
                {
                    _classChecher.Check(typeDef, sharedData);
                    _interfaceChecker.Check(typeDef, sharedData);
                    sharedData.RemoveFromCandidates(typeDef.Scope);

                    if (!sharedData.HasCandidateReferences)
                    {
                        return;
                    }
                }
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Performs assembly's types checking.
        /// </summary>
        /// <param name="sharedData">Used types and assemblies candidates.</param>
        /// <param name="evaluator">The project evaluator.</param>
        public void Check(CheckerSharedData sharedData, IProjectEvaluator evaluator)
        {
            if (sharedData == null)
            {
                throw Error.ArgumentNull("sharedData");
            }

            if (evaluator == null)
            {
                throw Error.ArgumentNull("evaluator");
            }

            _assemblyDefinitions.Clear();

            CheckImportedClasses(sharedData, evaluator);

            if (sharedData.HasCandidateReferences)
            {
                CheckImportedInterfaces(sharedData, evaluator);
            }
        }