Click here to Skip to main content
15,885,767 members
Articles / Programming Languages / C#

Resolving Symbolic References in a CodeDOM (Part 7)

Rate me:
Please Sign up or sign in to vote.
4.75/5 (6 votes)
2 Dec 2012CDDL12 min read 19.4K   509   14  
Resolving symbolic references in a CodeDOM.
// The Nova Project by Ken Beckett.
// Copyright (C) 2007-2012 Inevitable Software, all rights reserved.
// Released under the Common Development and Distribution License, CDDL-1.0: http://opensource.org/licenses/cddl1.php

using System.Collections.Generic;
using System.Reflection;
using Mono.Cecil;

using Nova.CodeDOM;

namespace Nova.UI
{
    /// <summary>
    /// The view model for a <see cref="CodeDOM.EventRef"/>.
    /// </summary>
    public class EventRefVM : VariableRefVM
    {
        #region /* STATICS */

        internal static void AddViewModelMapping()
        {
            CreateViewModel.Add(typeof(EventRef),
                delegate(CodeObject codeObject, bool isDescription, Dictionary<CodeObject, CodeObjectVM> dictionary) { return new EventRefVM((EventRef)codeObject, dictionary); });
        }

        #endregion

        #region /* CONSTRUCTORS */

        /// <summary>
        /// Create a view model instance for the specified <see cref="CodeDOM.EventRef"/>.
        /// </summary>
        public EventRefVM(EventRef eventRef, Dictionary<CodeObject, CodeObjectVM> dictionary)
            : base(eventRef, dictionary)
        { }

        #endregion

        #region /* PROPERTIES */

        /// <summary>
        /// The underlying <see cref="CodeDOM.EventRef"/> model.
        /// </summary>
        public EventRef EventRef
        {
            get { return (EventRef)CodeObject; }
        }

        #endregion

        #region /* METHODS */

        #endregion

        #region /* RENDERING */

        public static void RenderEventDefinition(CodeRenderer renderer, EventDefinition eventDefinition, RenderFlags flags, CodeObjectVM tag)
        {
            RenderFlags passFlags = flags & ~RenderFlags.Description;
            bool hasBorder = flags.HasFlag(RenderFlags.ForceBorder);
            if (hasBorder)
                renderer.CreateBorder(PropertyDeclBaseVM.StaticBorderBrush, PropertyDeclBaseVM.StaticBackgroundBrush, tag);

            if (!flags.HasFlag(RenderFlags.NoPreAnnotations))
                AttributeVM.RenderAttributes(renderer, eventDefinition, tag);
            renderer.RenderText(ModifiersHelpers.AsString(EventRef.GetEventModifiers(eventDefinition)), KEYWORD_BRUSH, tag);
            TypeRefBaseVM.RenderTypeReferenceAsTypeRefVM(renderer, eventDefinition.EventType, passFlags, tag);  // Render as TypeRefVM for nested tooltips
            renderer.RenderText(" ", PUNC_BRUSH, tag);
            TypeRefBaseVM.RenderTypeReferenceAsTypeRefVM(renderer, eventDefinition.DeclaringType, passFlags, tag);  // Render as TypeRefVM for nested tooltips
            renderer.RenderText(Dot.ParseToken, PUNC_BRUSH, tag);
            renderer.RenderText(eventDefinition.Name, IDENTIFIER_BRUSH, tag);

            // If we have a border, return to the previous one
            if (hasBorder)
                renderer.ReturnToBorderParent(tag);
        }

        public static void RenderEventInfo(CodeRenderer renderer, EventInfo eventInfo, RenderFlags flags, CodeObjectVM tag)
        {
            RenderFlags passFlags = flags & ~RenderFlags.Description;
            bool hasBorder = flags.HasFlag(RenderFlags.ForceBorder);
            if (hasBorder)
                renderer.CreateBorder(PropertyDeclBaseVM.StaticBorderBrush, PropertyDeclBaseVM.StaticBackgroundBrush, tag);

            if (!flags.HasFlag(RenderFlags.NoPreAnnotations))
                AttributeVM.RenderAttributes(renderer, eventInfo, tag);
            renderer.RenderText(ModifiersHelpers.AsString(EventRef.GetEventModifiers(eventInfo)), KEYWORD_BRUSH, tag);
            TypeRefBaseVM.RenderTypeAsTypeRefVM(renderer, eventInfo.EventHandlerType, passFlags, tag);  // Render as TypeRefVM for nested tooltips
            renderer.RenderText(" ", PUNC_BRUSH, tag);
            TypeRefBaseVM.RenderTypeAsTypeRefVM(renderer, eventInfo.DeclaringType, passFlags, tag);  // Render as TypeRefVM for nested tooltips
            renderer.RenderText(Dot.ParseToken, PUNC_BRUSH, tag);
            renderer.RenderText(eventInfo.Name, IDENTIFIER_BRUSH, tag);

            // If we have a border, return to the previous one
            if (hasBorder)
                renderer.ReturnToBorderParent(tag);
        }

        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Common Development and Distribution License (CDDL)


Written By
Software Developer (Senior)
United States United States
I've been writing software since the late 70's, currently focusing mainly on C#.NET. I also like to travel around the world, and I own a Chocolate Factory (sadly, none of my employees are oompa loompas).

Comments and Discussions