Exemple #1
0
        private static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Usage: dumppdb PDBFILE");
                Console.WriteLine("Dumps the parsed symbols from the given PDBFILE in CSV format.");
                return;
            }

            string                 pdbFile          = args[0];
            string                 assemblyName     = Path.GetFileNameWithoutExtension(pdbFile);
            MethodMapper           mapper           = new MethodMapper();
            AssemblyMethodMappings assemblyMappings = mapper.GetMethodMappings(pdbFile, assemblyName);
            // sorts the elements by source file and then line number since OrderBy guarantees a stable sort
            IEnumerable <MethodMapping> sortedMappings = assemblyMappings.MethodMappings.OrderBy(mapping => mapping.StartLine)
                                                         .OrderBy(mapping => mapping.SourceFile);

            Console.WriteLine("MethodToken, StartLine, EndLine, SourceFile");
            foreach (MethodMapping mapping in assemblyMappings.MethodMappings)
            {
                // we pad all fields to the length of the corresponding header plus the comma to align
                // the fields nicely on the console for easy readability
                // the source file is the last field because we cannot pad it to a fixed length
                string tokenField     = $"{mapping.MethodToken},".PadRight(12);
                string startLineField = $"{mapping.StartLine},".PadRight(10);
                string endLineField   = $"{mapping.EndLine},".PadRight(8);
                Console.WriteLine($"{tokenField} {startLineField} {endLineField} {mapping.SourceFile}");
            }
        }
Exemple #2
0
        // --------------------------------------------------------------------------------------------
        /// <summary>
        /// Calls the appropriate event method.
        /// </summary>
        /// <param name="sender">Object initiating the event.</param>
        /// <param name="mapper">Mapper to define the method to execute</param>
        /// <param name="useAction">Allows using the menu command action</param>
        // --------------------------------------------------------------------------------------------
        private void HandleMenuCommandEvent(object sender, MethodMapper mapper, bool useAction)
        {
            // --- Check for command
            var command = sender as OleMenuCommand;

            if (command == null)
            {
                return;
            }

            // --- Obtain infiormation for command
            var targetInfo = GetTargetInfo();
            var menuInfo   = targetInfo.FindMenuInfo(command.CommandID);

            if (menuInfo == null)
            {
                return;
            }

            // --- Get the apropriate commmand method
            MethodInfo commandMethod = mapper(menuInfo);

            if (commandMethod == null)
            {
                return;
            }

            // --- Execute the default command action
            if (useAction && menuInfo.Action != null)
            {
                menuInfo.Action.ExecuteAction(_Package, command.CommandID);
            }

            // --- Execute the command
            var paramCount = commandMethod.GetParameters().Count();
            var parameters = new object[paramCount];

            // --- Create a simple context if no one exists
            if (Context == null)
            {
                Context = new CommandContext(_Package);
            }
            if (paramCount > 0)
            {
                parameters[0] =
                    commandMethod.GetParameters()[0].ParameterType == typeof(OleMenuCommand)
            ? (object)command : Context;
            }
            if (paramCount == 2)
            {
                parameters[1] = Context;
            }
            commandMethod.Invoke(EventTarget, parameters);
        }
Exemple #3
0
        private void MapMethods(Type aspectDeclaringType, ITypeMap typeMap)
        {
            var methods      = aspectDeclaringType.GetMethods();
            var methodMapper = new MethodMapper(typeMap);

            var mappedMethodsEnumerable = methodMapper.Select(map => {
                var aspectMethod = methods.FirstOrDefault(method => {
                    return(method.IsMatchedTo(map.ContractMember));
                });

                return(new AspectMethodMap(map.ContractType,
                                           map.ImplementationType,
                                           map.ImplementationMember,
                                           map.ContractMember,
                                           aspectMethod));
            });

            mappedMethods = mappedMethodsEnumerable.ToList <IAspectMethodMap>();
        }
Exemple #4
0
        // Takes a list of type variables to substitute into fragments and returns a string containing the
        // required methods
        // TypeVars in fragments have names T, T1, T2, T3, etc.
        public string rewriteCodeFragment(string code, IList <string> tyArgs)
        {
            string       ret    = code;
            MethodMapper mapper = new MethodMapper(this);

            if (tyArgs != null)
            {
                int idx = 0;
                foreach (string t in tyArgs)
                {
                    string toReplace = "${T" + (idx == 0 ? "" : Convert.ToString(idx)) + "}";
                    ret = ret.Replace(toReplace, tyArgs[idx]);
                    idx++;
                }
            }
            // replace @m{<method name>} with (possibly transformed) <method name>
            ret = Regex.Replace(ret, "(?:@m\\{(\\w+)\\})", new MatchEvaluator(mapper.RewriteMethod));

            return(ret);
        }
        /// <summary>
        /// Creates a symbol collection from the given PDB files.
        /// </summary>
        public static SymbolCollection CreateFromFiles(IEnumerable <string> pdbFilePaths)
        {
            MethodMapper mapper = new MethodMapper();
            List <AssemblyMethodMappings> mappings = new List <AssemblyMethodMappings>();

            foreach (string filePath in pdbFilePaths)
            {
                logger.Debug("Loading mappings from PDB {filePath}", filePath);
                string assemblyName = Path.GetFileNameWithoutExtension(filePath);
                try
                {
                    AssemblyMethodMappings assemblyMappings = mapper.GetMethodMappings(filePath, assemblyName);
                    mappings.Add(assemblyMappings);
                }
                catch (Exception e)
                {
                    logger.Error(e, "Failed to parse PDB file {pdbFile}. This file will be ignored and no coverage will be reported for its corresponding assembly." +
                                 " You may get follow-up errors that method IDs cannot be resolved for this assembly", filePath);
                }
            }
            return(new SymbolCollection(mappings));
        }
Exemple #6
0
       // Takes a list of type variables to substitute into fragments and returns a string containing the 
       // required methods
       // TypeVars in fragments have names T, T1, T2, T3, etc.
       public string rewriteCodeFragment(string code, IList<string> tyArgs)
       {
          string ret = code;
          MethodMapper mapper = new MethodMapper(this);

          if (tyArgs != null)
          {
             int idx = 0;
             foreach (string t in tyArgs)
             {
                string toReplace = "${T" + (idx == 0 ? "" : Convert.ToString(idx)) + "}";
                ret = ret.Replace(toReplace,tyArgs[idx]);
                idx++;
             }
          }
          // replace @m{<method name>} with (possibly transformed) <method name>
          ret = Regex.Replace(ret, "(?:@m\\{(\\w+)\\})", new MatchEvaluator(mapper.RewriteMethod));

          return ret;
       }