예제 #1
0
        public EventDetail(RootDetail parent, EventInfo ei)
            : base(parent, ei)
        {
            _name       = ei.Name;
            _visibility = VisibilityUtil.GetVisibilityFor(ei.GetAddMethod(true));
            _category   = "event";

            CodeStringBuilder csb = new CodeStringBuilder();

            AppendAttributesDeclaration(csb);

            csb.Mode = AppendMode.NonText;
            csb.AppendVisibility(_visibility);
            csb.AppendText(" ");
            csb.Mode = AppendMode.All;

            csb.AppendKeyword("event ");
            csb.AppendType(ei.EventHandlerType);
            csb.AppendText(" ");
            csb.AppendText(ei.Name);

            _declaration         = csb.ToString();
            _declarationHtml     = csb.ToHtmlString();
            _declarationMarkdown = csb.ToMarkdownString();
        }
예제 #2
0
        protected ChangeType PerformCompareInternal(ICanCompare from, bool suppressBreakingChanges)
        {
            if (from == null)
            {
                throw new ArgumentNullException("from");
            }

            if (from.Status == Status.Missing && _status == Status.Missing)
            {
                _changeThisInstance = ChangeType.None;
            }
            else if (from.Status == Status.Missing)
            {
                _changeThisInstance = ChangeType.Added;

                ForceChangeToAllDescendants();
            }
            else if (_status == Status.Missing)
            {
                if (suppressBreakingChanges || (((RootDetail)from).SuppressBreakingChangesInChildren))
                {
                    _changeThisInstance = ChangeType.RemovedNonBreaking;
                }
                else
                {
                    Visibility visibility = VisibilityUtil.GetMostVisible(from);

                    if (visibility == Visibility.Public)
                    {
                        _changeThisInstance = ChangeType.RemovedBreaking;
                    }
                    else
                    {
                        _changeThisInstance = ChangeType.RemovedNonBreaking;
                    }
                }

                ForceChangeToAllDescendants();
            }
            else
            {
                if (from.GetType() != GetType())
                {
                    throw new InvalidOperationException("Cannot calculate changes between different types");
                }

                if (string.Compare(from.AlignmentIdentifier, this.AlignmentIdentifier) != 0)
                {
                    throw new InvalidOperationException("Cannot calculate changes between objects with different identifiers. The identifier correlates the same objects in different lists.");
                }

                _changeThisInstance = CompareInstance(from, suppressBreakingChanges);
            }

            return(_changeThisInstance);
        }
예제 #3
0
 public override string GetTextDeclaration()
 {
     if (_visibility != Visibility.Invalid)
     {
         return(VisibilityUtil.GetVisibilityString(_visibility) + " " + _declaration);
     }
     else
     {
         return(_declaration);
     }
 }
예제 #4
0
 public override string GetTextTitle()
 {
     if ((_visibility != Visibility.Invalid) && (_category != null))
     {
         return(VisibilityUtil.GetVisibilityString(_visibility) + " " + _category + " " + this.FullName);
     }
     else
     {
         return(this.FullName);
     }
 }
예제 #5
0
        public EnumDetail(RootDetail parent, Type type)
            : base(parent, type)
        {
            _visibility = VisibilityUtil.GetVisibilityFor(type);
            _category   = "enum";

            foreach (string name in Enum.GetNames(type))
            {
                _children.Add(
                    new EnumItemDetail(
                        this,
                        name,
                        Convert.ToInt64(
                            type.GetField(name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static)
                            .GetRawConstantValue()),
                        _visibility));
            }

            CodeStringBuilder csb = new CodeStringBuilder();

            AppendAttributesDeclaration(csb);

            csb.Mode = AppendMode.NonText;
            csb.AppendVisibility(_visibility);
            csb.AppendText(" ");
            csb.Mode = AppendMode.All;

            csb.AppendKeyword("enum ");
            csb.AppendText(type.Name);

            csb.Mode = AppendMode.NonText;
            csb.AppendNewline();
            csb.AppendText("{");
            csb.AppendNewline();

            foreach (EnumItemDetail eid in FilterChildren <EnumItemDetail>())
            {
                csb.AppendIndent();
                csb.AppendText(eid.GetHtmlDeclaration());
                csb.AppendText(",");
                csb.AppendNewline();
            }

            csb.RemoveCharsFromEnd("<br>".Length);
            csb.RemoveCharsFromEnd(",".Length);
            csb.AppendNewline();
            csb.AppendText("}");
            csb.Mode = AppendMode.All;

            _declaration         = csb.ToString();
            _declarationHtml     = csb.ToHtmlString();
            _declarationMarkdown = csb.ToMarkdownString();
        }
예제 #6
0
        protected override ChangeType CompareInstance(ICanCompare previous, bool suppressBreakingChanges)
        {
            ChangeType change = base.CompareInstance(previous, suppressBreakingChanges);

            StubDetail other = (StubDetail)previous;

            change |= VisibilityUtil.GetVisibilityChange(other._visibility, _visibility, suppressBreakingChanges);

            if (_content != other._content)
            {
                change |= ChangeType.ContentChanged;
            }

            return(change);
        }
예제 #7
0
        public FieldDetail(RootDetail parent, FieldInfo fi)
            : base(parent, fi)
        {
            _name       = fi.Name;
            _visibility = VisibilityUtil.GetVisibilityFor(fi);
            _category   = "field";

            CodeStringBuilder csb = new CodeStringBuilder();

            AppendAttributesDeclaration(csb);

            csb.Mode = AppendMode.NonText;
            csb.AppendVisibility(_visibility);
            csb.AppendText(" ");
            csb.Mode = AppendMode.All;

            if (fi.IsLiteral)
            {
                csb.AppendKeyword("const ");
            }
            else if (fi.IsStatic)
            {
                csb.AppendKeyword("static ");
            }

            if (fi.IsInitOnly)
            {
                csb.AppendKeyword("readonly ");
            }

            csb.AppendType(fi.FieldType);
            csb.AppendText(" ");
            csb.AppendText(fi.Name);

            if (fi.IsLiteral)
            {
                csb.AppendParameterValue(fi.GetRawConstantValue());
            }

            _declaration         = csb.ToString();
            _declarationHtml     = csb.ToHtmlString();
            _declarationMarkdown = csb.ToMarkdownString();
        }
예제 #8
0
        protected virtual ChangeType CompareVisibility(ICanCompare previous, bool suppressBreakingChanges)
        {
            MemberDetail other = (MemberDetail)previous;

            return(VisibilityUtil.GetVisibilityChange(other._visibility, _visibility, suppressBreakingChanges));
        }
        public PropertyDetail(RootDetail parent, PropertyInfo pi)
            : base(parent, pi)
        {
            _name     = pi.Name;
            _category = "property";

            MethodInfo[] methods = pi.GetAccessors(true);
            foreach (MethodInfo mi in methods)
            {
                MethodDetail m = new MethodDetail(this, mi);

                if ((m.Name.Length > 3) && (mi.IsSpecialName))
                {
                    m.Name = m.Name.Substring(0, 3);
                }

                m.Declaration = null;
                _children.Add(m);
            }

            if (pi.GetIndexParameters().Length > 0)
            {
                CodeStringBuilder csbParameters = new CodeStringBuilder(AppendMode.Text);

                foreach (ParameterInfo ip in pi.GetIndexParameters())
                {
                    csbParameters.AppendParameterType(ip);
                    csbParameters.AppendText(", ");

                    _parameterCount++;
                }

                csbParameters.RemoveCharsFromEnd(2);

                _parameterTypesList = csbParameters.ToString();
            }

            _visibility = VisibilityUtil.GetMostVisible(FilterChildren <MethodDetail>());

            CodeStringBuilder csb = new CodeStringBuilder();

            AppendAttributesDeclaration(csb);

            csb.Mode = AppendMode.Html;
            csb.AppendVisibility(_visibility);
            csb.AppendText(" ");
            csb.Mode = AppendMode.Both;

            csb.AppendType(pi.PropertyType);
            csb.AppendText(" ");
            csb.AppendText(pi.Name);

            if (this.ParameterCount > 0)
            {
                csb.AppendText("[");
                csb.AppendText(this.ParameterTypesList);
                csb.AppendText("]");
            }

            csb.Mode = AppendMode.Html;

            csb.AppendNewline();
            csb.AppendText("{");
            csb.AppendNewline();
            csb.AppendIndent();

            foreach (MethodDetail mi in FilterChildren <MethodDetail>())
            {
                if (mi.Visibility != _visibility)
                {
                    csb.AppendVisibility(mi.Visibility);
                    csb.AppendText(" ");
                }

                csb.AppendText(mi.Name);
                csb.AppendText("; ");
            }

            csb.AppendNewline();
            csb.AppendText("}");

            _declaration     = csb.ToString();
            _declarationHtml = csb.ToHtmlString();
        }
예제 #10
0
        public EntityDetail(RootDetail parent, Type type, bool takeVisibilityFromParent)
            : base(parent, type)
        {
            _visibility = VisibilityUtil.GetVisibilityFor(type);

            BindingFlags flags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

            List <MethodBase> methods = FilterMethods(type.GetMethods(flags), type, false);

            foreach (MethodBase mi in methods)
            {
                MethodDetail md = new MethodDetail(this, mi);

                if (takeVisibilityFromParent)
                {
                    md.Visibility = _visibility;
                }

                _children.Add(md);
            }

            List <MethodBase> constructors = FilterMethods(type.GetConstructors(flags), type, false);

            foreach (MethodBase mi in constructors)
            {
                MethodDetail md = new MethodDetail(this, mi);

                if (takeVisibilityFromParent)
                {
                    md.Visibility = _visibility;
                }

                _children.Add(md);
            }

            List <MethodBase> operators = FilterMethods(type.GetMethods(flags), type, true);

            foreach (MethodBase mi in operators)
            {
                OperatorDetail od = new OperatorDetail(this, mi);

                if (takeVisibilityFromParent)
                {
                    od.Visibility = _visibility;
                }

                _children.Add(od);
            }

            List <PropertyInfo> props = FilterProperties(type.GetProperties(flags), type);

            foreach (PropertyInfo pi in props)
            {
                PropertyDetail pd = new PropertyDetail(this, pi);

                if (takeVisibilityFromParent)
                {
                    pd.Visibility = _visibility;
                }

                _children.Add(pd);
            }

            List <EventInfo> events = FilterEvents(type.GetEvents(flags), type);

            foreach (EventInfo ei in events)
            {
                EventDetail ed = new EventDetail(this, ei);

                if (takeVisibilityFromParent)
                {
                    ed.Visibility = _visibility;
                }

                _children.Add(ed);
            }

            List <FieldInfo> fields = FilterFields(type.GetFields(flags), type);

            foreach (FieldInfo fi in fields)
            {
                FieldDetail fd = new FieldDetail(this, fi);

                if (takeVisibilityFromParent)
                {
                    fd.Visibility = _visibility;
                }

                _children.Add(fd);
            }

            CodeStringBuilder csb = new CodeStringBuilder();

            AppendAttributesDeclaration(csb);

            csb.Mode = AppendMode.NonText;
            csb.AppendVisibility(_visibility);
            csb.AppendText(" ");
            csb.Mode = AppendMode.All;

            if (type.IsAbstract && type.IsSealed)
            {
                csb.AppendKeyword("static ");
            }
            else if (type.IsInterface)
            {
                csb.AppendKeyword("interface ");
            }
            else if (type.IsAbstract)
            {
                csb.AppendKeyword("abstract ");
            }
            else if (type.IsSealed)
            {
                csb.AppendKeyword("sealed ");
            }

            if (type.IsClass)
            {
                csb.AppendKeyword("class ");
            }

            csb.AppendText(_name);

            csb.AppendBaseClasses(type);

            csb.AppendGenericRestrictions(type);

            _declaration         = csb.ToString();
            _declarationHtml     = csb.ToHtmlString();
            _declarationMarkdown = csb.ToMarkdownString();
        }
예제 #11
0
        public MethodDetail(RootDetail parent, MethodBase mi)
            : base(parent, mi)
        {
            CodeStringBuilder csb = new CodeStringBuilder(AppendMode.Text);

            csb.AppendMethodName(mi);
            _name = csb.ToString();

            _visibility = VisibilityUtil.GetVisibilityFor(mi);
            _category   = "method";

            MethodBody body = null;

            try
            {
                body = mi.GetMethodBody();
            }
            catch (VerificationException)
            {
                // "Operation could destabilize the runtime" on .NET 3.0 WPF PresentationCore.dll
            }

            if (body != null)
            {
                _body = GenericUtility.GetILAsHashedText(mi);
            }

            csb = new CodeStringBuilder();

            AppendAttributesDeclaration(csb);

            MethodInfo bi = null;

            if (mi is MethodInfo)
            {
                bi = ((MethodInfo)mi).GetBaseDefinition();
            }

            csb.Mode = AppendMode.NonText;
            csb.AppendVisibility(_visibility);
            csb.AppendText(" ");
            csb.Mode = AppendMode.All;

            if (mi.IsAbstract)
            {
                if (!mi.DeclaringType.IsInterface)
                {
                    csb.AppendKeyword("abstract ");
                }
            }
            else if (mi.IsVirtual && !mi.IsFinal)
            {
                if (!object.ReferenceEquals(mi, bi))
                {
                    csb.AppendKeyword("override ");
                }
                else
                {
                    csb.AppendKeyword("virtual ");
                }
            }
            else if (mi.IsStatic)
            {
                csb.AppendKeyword("static ");
            }

            if (mi is MethodInfo)
            {
                csb.AppendParameter(((MethodInfo)mi).ReturnParameter);
            }

            csb.AppendText(" ");
            csb.AppendText(_name);
            csb.AppendText("(");

            // Add "this" keyword for extension methods.
            if (mi.CustomAttributes.Any(x => typeof(ExtensionAttribute).IsAssignableFrom(x.AttributeType)))
            {
                csb.AppendKeyword("this");
                csb.AppendText(" ");
            }


            CodeStringBuilder csbParameters = new CodeStringBuilder(AppendMode.Text);

            foreach (ParameterInfo pi in mi.GetParameters())
            {
                csb.AppendParameter(pi);
                csb.AppendText(", ");

                csbParameters.AppendParameterType(pi);
                csbParameters.AppendText(", ");

                _parameterCount++;
            }

            if (mi.GetParameters().Length > 0)
            {
                csb.RemoveCharsFromEnd(2);
                csbParameters.RemoveCharsFromEnd(2);
            }

            csb.AppendText(")");

            if (mi is MethodInfo)
            {
                csb.AppendGenericRestrictions(mi);
            }

            _declaration         = csb.ToString();
            _declarationHtml     = csb.ToHtmlString();
            _declarationMarkdown = csb.ToMarkdownString();
            _parameterTypesList  = csbParameters.ToString();
        }
예제 #12
0
        public virtual string GetMarkdownChangeDescription()
        {
            if (this.Change == ChangeType.None)
            {
                // Show nothing.
                return(string.Empty);
            }

            StringBuilder sb       = new StringBuilder();
            RootDetail    previous = (RootDetail)_navigateBackward;

            sb.AppendLine("Changes found:");
            sb.AppendLine();

            if ((this.Change & ChangeType.Added) != 0)
            {
                AppendClauseMarkdown(sb, "Added");
            }

            if (((this.Change & ChangeType.RemovedBreaking) != 0) || ((this.Change & ChangeType.RemovedNonBreaking) != 0))
            {
                AppendClauseMarkdown(sb, "Removed");
            }

            if ((this.Change & ChangeType.ContentChanged) != 0)
            {
                AppendClauseMarkdown(sb, "Content changed");
            }

            if ((this.Change & ChangeType.ValueChangedBreaking) != 0)
            {
                AppendClauseMarkdown(sb, "Value has a breaking change");
            }
            else if ((this.Change & ChangeType.ValueChangedNonBreaking) != 0)
            {
                AppendClauseMarkdown(sb, "Value has a non-breaking change");
            }

            if (((this.Change & ChangeType.DeclarationChangedBreaking) != 0) || ((this.Change & ChangeType.DeclarationChangedNonBreaking) != 0))
            {
                AppendClauseMarkdown(sb, "Declaration changed");
            }

            if (((this.Change & ChangeType.VisibilityChangedBreaking) != 0) || ((this.Change & ChangeType.VisibilityChangedNonBreaking) != 0))
            {
                AppendClauseMarkdown(sb, VisibilityUtil.GetVisibilityChangeText(previous, this));
            }

            if (((this.Change & ChangeType.MembersChangedBreaking) != 0) || ((this.Change & ChangeType.MembersChangedNonBreaking) != 0))
            {
                GetMarkdownDescriptionBriefMembers(sb);
            }

            if ((this.Change & ChangeType.ImplementationChanged) != 0)
            {
                AppendClauseMarkdown(sb, "Implementation changed");
            }

            if ((this.Change & ChangeType.AttributesChanged) != 0)
            {
                AppendClauseMarkdown(sb, "Attributes changed");
            }

            return(sb.ToString());
        }
예제 #13
0
        public virtual string GetHtmlChangeDescription()
        {
            StringBuilder sb       = new StringBuilder();
            RootDetail    previous = (RootDetail)_navigateBackward;

            if (this.Change == ChangeType.None)
            {
                sb.Append("None");
            }

            if ((this.Change & ChangeType.Added) != 0)
            {
                AppendClauseHtml(sb, false, "Added");
            }

            if (((this.Change & ChangeType.RemovedBreaking) != 0) || ((this.Change & ChangeType.RemovedNonBreaking) != 0))
            {
                AppendClauseHtml(sb, ((this.Change & ChangeType.RemovedBreaking) != 0), "Removed");
            }

            if ((this.Change & ChangeType.AttributesChanged) != 0)
            {
                AppendClauseHtml(sb, false, "Attributes changed");
            }

            if ((this.Change & ChangeType.ImplementationChanged) != 0)
            {
                AppendClauseHtml(sb, false, "Implementation changed");
            }

            if ((this.Change & ChangeType.ContentChanged) != 0)
            {
                AppendClauseHtml(sb, ChangeTypeUtil.HasBreaking(this.Change), "Content changed");
            }

            if (((this.Change & ChangeType.ValueChangedBreaking) != 0) || ((this.Change & ChangeType.ValueChangedNonBreaking) != 0))
            {
                AppendClauseHtml(sb, ((this.Change & ChangeType.ValueChangedBreaking) != 0), "Value changed");
            }

            if (((this.Change & ChangeType.DeclarationChangedBreaking) != 0) || ((this.Change & ChangeType.DeclarationChangedNonBreaking) != 0))
            {
                AppendClauseHtml(sb, ((this.Change & ChangeType.DeclarationChangedBreaking) != 0), "Declaration changed");
            }

            if (((this.Change & ChangeType.VisibilityChangedBreaking) != 0) || ((this.Change & ChangeType.VisibilityChangedNonBreaking) != 0))
            {
                AppendClauseHtml(sb, ((this.Change & ChangeType.VisibilityChangedBreaking) != 0), VisibilityUtil.GetVisibilityChangeText(previous, this));
            }

            if (((this.Change & ChangeType.ObsoleteChangedBreaking) != 0) || ((this.Change & ChangeType.ObsoleteChangedNonBreaking) != 0))
            {
                AppendClauseHtml(sb, ((this.Change & ChangeType.ObsoleteChangedBreaking) != 0), ObsoleteUtil.GetObsoleteChangeText(previous, this));
            }

            if (((this.Change & ChangeType.MembersChangedBreaking) != 0) || ((this.Change & ChangeType.MembersChangedNonBreaking) != 0))
            {
                GetHtmlChangeDescriptionBriefMembers(sb);
            }

            return(sb.ToString());
        }
예제 #14
0
        public virtual string GetTextChangeDescription()
        {
            StringBuilder sb       = new StringBuilder();
            RootDetail    previous = (RootDetail)_navigateBackward;

            if ((this.Change & ChangeType.Added) != 0)
            {
                AppendClauseText(sb, "Added");
            }

            if (((this.Change & ChangeType.RemovedBreaking) != 0) || ((this.Change & ChangeType.RemovedNonBreaking) != 0))
            {
                AppendClauseText(sb, "Removed");
            }

            if ((this.Change & ChangeType.ContentChanged) != 0)
            {
                AppendClauseText(sb, "Content changed");
            }

            if ((this.Change & ChangeType.ValueChangedBreaking) != 0)
            {
                AppendClauseText(sb, "Value has a breaking change");
            }
            else if ((this.Change & ChangeType.ValueChangedNonBreaking) != 0)
            {
                AppendClauseText(sb, "Value has a non-breaking change");
            }

            if (((this.Change & ChangeType.DeclarationChangedBreaking) != 0) || ((this.Change & ChangeType.DeclarationChangedNonBreaking) != 0))
            {
                AppendClauseText(sb, "Declaration changed");
            }

            if (((this.Change & ChangeType.VisibilityChangedBreaking) != 0) || ((this.Change & ChangeType.VisibilityChangedNonBreaking) != 0))
            {
                AppendClauseText(sb, VisibilityUtil.GetVisibilityChangeText(previous, this));
            }

            if (((this.Change & ChangeType.ObsoleteChangedBreaking) != 0) || ((this.Change & ChangeType.ObsoleteChangedNonBreaking) != 0))
            {
                AppendClauseText(sb, ObsoleteUtil.GetObsoleteChangeText(previous, this));
            }

            if (((this.Change & ChangeType.MembersChangedBreaking) != 0) || ((this.Change & ChangeType.MembersChangedNonBreaking) != 0))
            {
                GetTextDescriptionBriefMembers(sb);
            }

            if ((this.Change & ChangeType.ImplementationChanged) != 0)
            {
                AppendClauseText(sb, "Implementation changed");
            }

            if ((this.Change & ChangeType.AttributesChanged) != 0)
            {
                AppendClauseText(sb, "Attributes changed");
            }

            return(sb.ToString());
        }