示例#1
0
        static void Ncca_Is_Used_Properly(Codebase codebase, IScope scope, int maxInstructions)
        {
            var methods = codebase.Methods
                          .Where(m => m.HasBody && m.Body.Instructions.Count > maxInstructions)
                          .Where(m => m.Has <NoCodeCoverageAttribute>() ||
                                 m.DeclaringType.Has <NoCodeCoverageAttribute>());

            foreach (var method in methods)
            {
                scope.Error("Method is too complex to be marked with NCCA: {0}", method);
            }
        }
示例#2
0
        /// <summary>
        /// Ensures that classes marked with <see cref="ImmutableAttribute"/> have only
        /// readonly fields
        /// </summary>
        /// <param name="codebase">The codebase to run against.</param>
        /// <param name="scope">The scope to report to.</param>
        public static void Immutable_Types_Should_Be_Immutable(Codebase codebase, IScope scope)
        {
            var decorated = codebase.Types
                            .Where(t => t.Has <ImmutableAttribute>());

            var failing = decorated
                          .Where(t => t.GetAllFields(codebase)
                                 .Count(f => !f.IsInitOnly && !f.IsStatic) > 0);

            foreach (var definition in failing)
            {
                scope.Error("Type should be immutable: {0}", definition);
            }
        }