Exemple #1
0
        /// <summary>
        /// Check the method body of the Initialize method of an analyzer and if that's empty,
        /// then the analyzer hasn't been implemented yet.
        /// </summary>
        private static bool HasImplementation(DiagnosticAnalyzer analyzer)
        {
            System.Reflection.MethodInfo method = analyzer.GetType().GetMethod("Initialize");
            if (method != null)
            {
                System.Reflection.MethodBody body = method.GetMethodBody();
                int?ilInstructionCount            = body?.GetILAsByteArray()?.Count();
                // An empty method has two IL instructions - nop and ret.
                return(ilInstructionCount != 2);
            }

            return(true);
        }