예제 #1
0
        /// <summary>
        /// The callback method, triggered once _trigger is disposed.
        /// When used @ aspect compile-time, it means that the .pssym file is generated!
        /// </summary>
        /// <param name="trigger">The trigger, not used for anything.</param>
        private static void OnPostCompile(PostCompileTrigger trigger)
        {
            // When no actions are queued, just return (no descriptions to add)
            if (_actions.Count == 0)
            {
                return;
            }

            // Calculate the path of the project' pssym file
            var pssymPath = Path.Combine(trigger.PathBin, trigger.AssemblyName + ".pssym");

            // declare the local doc variable
            XDocument document;

            try
            {
                // pssym wasn't found - just return in that case
                if (!File.Exists(pssymPath))
                {
                    return;
                }

                // Attempt to load the pssym file (its XML)
                document = XDocument.Load(pssymPath);

                // Should not occur, but if we don't have a root, just return
                if (document.Root == null)
                {
                    return;
                }

                // Create a new dictionary, to store the pssym mappings / current count
                var storage = new Dictionary <string, string>();

                // Load the mappings (the core entries) from the pssym (if it fails, no new entries will be added)
                ExtractSymbols(document, storage);

                // Process all actions (each action is a description that should be added
                foreach (var a in _actions)
                {
                    try
                    {
                        a(document, storage);
                    }
                    catch
                    {
                        // Silently ignore exceptions
                    }
                }

                // Store the modified pssym
                document.Save(pssymPath);
            }
            catch
            {
                // Silently ignore exceptions
            }
        }
예제 #2
0
        // ReSharper restore UnaccessedField.Local

        /// <summary>
        /// Create the PostCompileTrigger to trigger @ post compile
        /// </summary>
        static PostSharpDescription()
        {
            _trigger = new PostCompileTrigger {
                OnPostCompile = OnPostCompile
            };

            if (!_trigger.HasProperties)
            {
                Message.Write(SeverityType.Warning, "PostSharpDescription(1)",
                              "PostCompileTrigger was unable to extract one or more required properties. Did you update your PostSharp.targets/PostSharp.Custom.targets file? The added descriptions will not be available on-hover.");
            }
        }