コード例 #1
0
 /// <summary>
 /// Move any trailing post annotations on the last base type to the first constraint (if any) as prefix annotations.
 /// </summary>
 protected void AdjustBaseTypePostComments()
 {
     if (_baseTypes != null)
     {
         int baseTypes = _baseTypes.Count;
         if (baseTypes > 0 && _baseTypes[baseTypes - 1].HasPostAnnotations && HasConstraintClauses)
         {
             ChildList <Annotation> annotations = _baseTypes[baseTypes - 1].Annotations;
             for (int i = 0; i < annotations.Count;)
             {
                 Annotation annotation = annotations[i];
                 if (annotation.IsPostfix)
                 {
                     annotation.IsPostfix = false;
                     annotations.RemoveAt(i);
                     if (annotation.IsListed)
                     {
                         NotifyListedAnnotationRemoved(annotation);
                     }
                     ConstraintClauses[0].AttachAnnotation(annotation);
                     continue;
                 }
                 ++i;
             }
             if (annotations.Count == 0)
             {
                 _baseTypes[baseTypes - 1].Annotations = null;
             }
         }
     }
 }
コード例 #2
0
        /// <summary>
        /// Normalize content.
        /// </summary>
        public void NormalizeContent()
        {
            if (_content is ChildList <DocComment> )
            {
                ChildList <DocComment> children = (ChildList <DocComment>)_content;

                // Replace an empty collection with null
                if (children.Count == 0)
                {
                    _content = null;
                }
                else
                {
                    for (int i = children.Count - 1; i > 0; --i)
                    {
                        // Combine adjacent DocText objects into a single object
                        if (children[i] is DocText && children[i - 1] is DocText)
                        {
                            children[i - 1].Add(children[i].Text);
                            children.RemoveAt(i);
                        }
                    }
                    if (children.Count == 1)
                    {
                        CodeObject child = children[0];

                        // Replace a single DocText with a string
                        if (child is DocText)
                        {
                            _content = ((DocText)child).Text;
                        }
                        else if (child.NewLines > 0)
                        {
                            // Remove any newlines on the first child if they weren't explicitly set
                            if (!child.IsNewLinesSet && child.NewLines > 0)
                            {
                                // Move the newlines to the parent if it hasn't been explicitly set
                                if (!IsNewLinesSet)
                                {
                                    SetNewLines(child.NewLines);
                                }
                                child.SetNewLines(0);
                            }
                        }
                    }
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Remove the first attribute expression with the specified name.
        /// </summary>
        /// <returns><c>true</c> if found and removed, otherwise <c>false</c>.</returns>
        public bool RemoveAttributeExpression(string attributeName)
        {
            if (_attributeExpressions != null)
            {
                for (int i = _attributeExpressions.Count - 1; i >= 0; --i)
                {
                    // The expression might be a ConstructorRef or an UnresolvedRef, or it might be a Call that
                    // has an invoked expression of one of those types.
                    Expression  expression  = _attributeExpressions[i];
                    SymbolicRef symbolicRef = (expression is Call ? ((Call)expression).Expression.SkipPrefixes() as SymbolicRef : expression as SymbolicRef);

                    // Check if the name matches, with or without an "Attribute" suffix
                    if (symbolicRef != null && (symbolicRef.Name == attributeName ||
                                                symbolicRef.Name + NameSuffix == attributeName || symbolicRef.Name == attributeName + NameSuffix))
                    {
                        _attributeExpressions.RemoveAt(i);
                        return(true);
                    }
                }
            }
            return(false);
        }