コード例 #1
0
        /// <summary>
        ///  This will compile sources using the tools integrated in the .NET framework.
        /// </summary>
        /// <param name="sourceCode"></param>
        /// <param name="resultMessagesAndRows"></param>
        /// <returns>Will return null if compilation was not successful.</returns>
        public static Assembly CompileSourceToAssembly(string sourceCode, out Dictionary <string, int> resultMessagesAndRows)
        {
            resultMessagesAndRows = new Dictionary <string, int>();

            CSharpCodeProvider codeProvider = new CSharpCodeProvider();

            System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters();
            parameters.GenerateInMemory = true;

            // this will add references to all the assemblies we are using.
            foreach (Assembly assembly in ReflectionHelper.GetApplicationEntryAssemblyAndReferencedAssemblies())
            {
                parameters.ReferencedAssemblies.Add(assembly.Location);
            }

            CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, sourceCode);

            if (results.Errors.Count > 0)
            {
                foreach (CompilerError error in results.Errors)
                {
                    resultMessagesAndRows.Add("Line " + error.Line.ToString() + ": (" + error.ErrorNumber.ToString() + ")" + error.ErrorText, error.Line);
                }
                return(null);
            }
            else
            {
                resultMessagesAndRows.Add("Compiled succesfully", -1);
                return(results.CompiledAssembly);
            }
        }
コード例 #2
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public MethodTracerFilter()
        {
            foreach (Assembly assembly in ReflectionHelper.GetApplicationEntryAssemblyAndReferencedAssemblies())
            {
                object[] copyright = assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), true);
                if (copyright != null && copyright.Length > 0)
                {// Skip system assemblies.
                    AssemblyCopyrightAttribute attribute = (AssemblyCopyrightAttribute)copyright[0];
                    if (attribute.Copyright.Contains("Microsoft"))
                    {
                        continue;
                    }
                }

                _assemblies.Add(assembly, new AssemblyTracingInformation());
            }
        }
コード例 #3
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public EnumItemTracerFilter()
        {
            // Find all candidate enum types and assemblies they reside in.
            List <Type> possibleEnumTypes = ReflectionHelper.GatherTypeChildrenTypesFromAssemblies(typeof(Enum), ReflectionHelper.GetApplicationEntryAssemblyAndReferencedAssemblies());

            for (int i = possibleEnumTypes.Count - 1; i >= 0; i--)
            {
                object[] attributes = possibleEnumTypes[i].GetCustomAttributes(typeof(TracerEnumAttribute), true);
                if (attributes == null || attributes.Length == 0)
                {
                    possibleEnumTypes.RemoveAt(i);
                }
                else
                {
                    _assemblies.Add(possibleEnumTypes[i].Assembly);
                }
            }
        }