public void GetCalledMethodsTest()
		{
			MethodBase method = MethodBase.GetCurrentMethod();
			MethodBodyReader reader = new MethodBodyReader(method);

			IList<MethodBase> calledMethods = reader.GetCalledMethods(false, false);
			foreach (MethodBase calledMethod in calledMethods)
			{
				Console.WriteLine("     {0}.{1}", calledMethod.ReflectedType, calledMethod.Name);
			}

			Assert.IsTrue(calledMethods.Count > 3);
		}
		public void InstructionsTest()
		{
			MethodBase method = MethodBase.GetCurrentMethod();
			ILanguageInfo language = new CsLanguageInfo();
			MethodBodyReader reader = new MethodBodyReader(method, language);

			language.RegisterNamespace("System");
			language.RegisterNamespace("System.Collections.Generic");
			language.RegisterNamespace("System.Reflection");
			language.RegisterNamespace("Arebis.Reflection");

			IList<ILInstruction> instructions = reader.Instructions;
			foreach (ILInstruction instruction in instructions)
			{
				Console.WriteLine("     {0}", instruction.GetCode());
			}

			Assert.IsTrue(instructions.Count > 12);
		}
        /// <summary>
        /// Process the given session and return a codemodel containing
        /// the in-memory method call network.
        /// </summary>
        public CodeModel Process(StaticCodeAnalyzerSession session)
        {
            List<ModelAssembly> massemblies = new List<ModelAssembly>();
            List<ModelType> mtypes = new List<ModelType>();
            Dictionary<string, ModelMethod> mmethods = new Dictionary<string, ModelMethod>();
            ILanguageInfo languageInfo = session.LanguageInfo;
            IAnalyzerFilter analyzerFilter = session.AnalyzerFilter;

            // Retrieve all methods and constructors:
            foreach (Assembly asm in session.Assemblies)
            {
                try
                {
                    if ((analyzerFilter != null)
                        && (!analyzerFilter.ProcessAssembly(asm)))
                        continue;

                    ModelAssembly masm = new ModelAssembly(asm, languageInfo);
                    massemblies.Add(masm);

                    foreach (Type type in asm.GetTypes())
                    {
                        try
                        {
                            if ((analyzerFilter != null)
                                && (!analyzerFilter.ProcessType(type)))
                                continue;

                            ModelType mtype = new ModelType(masm, type, languageInfo);
                            mtypes.Add(mtype);

                            foreach (MethodBase mb in type.GetConstructors(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
                            {
                                if ((analyzerFilter != null)
                                    && (!analyzerFilter.ProcessMethod(mb)))
                                    continue;

                                mmethods[GetMethodKey(mb)] = new ModelMethod(mtype, mb, languageInfo);
                            }
                            foreach (MethodBase mb in type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly))
                            {
                                if ((analyzerFilter != null)
                                    && (!analyzerFilter.ProcessMethod(mb)))
                                    continue;

                                mmethods[GetMethodKey(mb)] = new ModelMethod(mtype, mb, languageInfo);
                            }
                        }
                        catch (Exception ex)
                        {
                            // Rethrow with mode info:
                            throw new TargetInvocationException(
                                String.Format("Error reading type {0}: {1} (See innerException.)", type.FullName, ex.Message),
                                ex
                            );
                        }
                    }
                }
                catch (ReflectionTypeLoadException ex)
                {
                    // Rethrow with mode info:
                    throw new TargetInvocationException(
                        String.Format("Error reading assembly {0}: {1} (See innerException.)", asm.FullName, ex.Message),
                        ex.LoaderExceptions.FirstOrDefault() ?? ex
                    );

                }
                catch (Exception ex)
                {
                    // Rethrow with mode info:
                    throw new TargetInvocationException(
                        String.Format("Error reading assembly {0}: {1} (See innerException.)", asm.FullName, ex.Message),
                        ex
                    );
                }
            }

            // Build network of method calls:
            foreach (ModelMethod m in mmethods.Values)
            {
                try
                {
                    MethodBodyReader reader = new MethodBodyReader(m.MethodBase);

                    foreach (MethodBase calledmb in reader.GetCalledMethods(true, true))
                    {
                        ModelMethod calledm = FindMethod(mmethods, calledmb);
                        if (calledm != null)
                        {
                            m.CallsMethods.Add(calledm);
                        }
                    }
                }
                catch (InvalidOperationException ex)
                {
                    Debug.WriteLine(ex.Message);
                }
            }

            // Construct a code model:
            CodeModel codeModel = new CodeModel(
                massemblies,
                mtypes,
                mmethods.Values);

            // Apply processors:
            foreach (IProcessor processor in session.Processors)
            {
                processor.Process(codeModel);
            }

            // Construct & return a code model:
            return codeModel;
        }