protected override object ParseAttributeValue(Parser parser, string name)
        {
            // Override parsing of the 'name' attribute to parse as a reference
            if (StringUtil.NNEqualsIgnoreCase(name, AttributeName))
            {
                // By default, parse a string value (including any whitespace) delimited by single or double quotes.
                // If there's no delimiter, just use the text of the token (perhaps a single word).
                string value;
                int    lineNumber   = parser.Token.LineNumber;
                ushort columnNumber = parser.Token.ColumnNumber;
                if (parser.TokenText == ParseTokenValueQuote1 || parser.TokenText == ParseTokenValueQuote2)
                {
                    ++columnNumber;  // Start just past the quote
                    value = parser.GetToDelimiter(parser.TokenText[0]);
                }
                else
                {
                    value = parser.TokenText;
                }
                parser.NextToken(true);  // Move past delimiter (or token)

                NameRef = new UnresolvedRef(value.Trim(), lineNumber, columnNumber);
                return(_nameRef);
            }
            return(base.ParseAttributeValue(parser, name));
        }
 /// <summary>
 /// Find a child namespace in the specified <see cref="NamespaceRef"/> with the specified name.
 /// </summary>
 /// <returns>A <see cref="NamespaceRef"/> to the namespace, or an <see cref="UnresolvedRef"/> if no match was found.</returns>
 public static SymbolicRef Find(SymbolicRef symbolicRef, string name, bool isFirstOnLine)
 {
     if (symbolicRef is NamespaceRef)
     {
         Find(((NamespaceRef)symbolicRef).Namespace.Find(name), name, isFirstOnLine);
     }
     return(new UnresolvedRef(name, isFirstOnLine));
 }
        /// <summary>
        /// Determine if the current reference refers to the same code object as the specified reference.
        /// </summary>
        public override bool IsSameRef(SymbolicRef symbolicRef)
        {
            UnresolvedRef unresolvedRef = (symbolicRef is AliasRef ? ((AliasRef)symbolicRef).Alias.Expression.SkipPrefixes() : symbolicRef) as UnresolvedRef;

            if (unresolvedRef == null || (string)Reference != (string)unresolvedRef.Reference)
            {
                return(false);
            }

            // The strings of the UnresolvedRefs match, but we have to also verify that any Dot prefixes
            // match - if either side has one, they must match, otherwise neither side can have one.
            Dot         parentDot  = _parent as Dot;
            Dot         parentDot2 = symbolicRef.Parent as Dot;
            SymbolicRef dotPrefix  = (parentDot != null && parentDot.Right == this ? parentDot.Left as SymbolicRef : null);
            SymbolicRef dotPrefix2 = (parentDot2 != null && parentDot2.Right == this ? parentDot2.Left as SymbolicRef : null);

            return(dotPrefix == null || dotPrefix2 == null || dotPrefix.IsSameRef(dotPrefix2));
        }
        /// <summary>
        /// Find the first attribute expression (Call or ConstructorRef) with the specified name.
        /// </summary>
        /// <returns>The expression if found, otherwise <c>null</c>.</returns>
        public Expression FindAttributeExpression(string attributeName)
        {
            if (_attributeExpressions != null)
            {
                foreach (Expression expression in _attributeExpressions)
                {
                    // 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.
                    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))
                    {
                        return(expression);
                    }
                }
            }
            return(null);
        }
        /// <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);
        }
Example #6
0
        /// <summary>
        /// Determine if the current reference refers to the same code object as the specified reference.
        /// </summary>
        public override bool IsSameRef(SymbolicRef symbolicRef)
        {
            if (!(symbolicRef is TypeParameterRef))
            {
                return(false);
            }

            TypeParameterRef typeParameterRef          = (TypeParameterRef)symbolicRef;
            object           reference                 = GetReferencedType();
            object           typeParameterRefReference = typeParameterRef.GetReferencedType();

            if (reference != typeParameterRefReference)
            {
                // We also have to consider the references the same if the Name and NamespaceNames match.
                // This can occur when types are present both in an assembly reference, and also as CodeDOM
                // objects (either in the current project, or a referenced project).  This can occur if one
                // or both types are in a project with assembly references instead of project references to
                // a type that is defined in the current solution, which isn't uncommon - it will occur in
                // "master" solutions that include projects that are also used in other solutions, and also
                // if a project in the solution uses a non-supported language and so is referenced by its
                // assembly.
                if (Name != typeParameterRef.Name || NamespaceName != typeParameterRef.NamespaceName)
                {
                    return(false);
                }

                // With type parameters, the declaring (parent) type names must also match for the type
                // parameters to be considered the same.
                string declaringTypeName = GetDeclaringTypeOrMethodName(reference);
                string typeParameterRefDeclaringTypeName = typeParameterRef.GetDeclaringTypeOrMethodName();
                if (declaringTypeName == null || typeParameterRefDeclaringTypeName == null ||
                    declaringTypeName != typeParameterRefDeclaringTypeName)
                {
                    return(false);
                }
            }

            return(HasSameArrayRanks(typeParameterRef));
        }
Example #7
0
        /// <summary>
        /// Determine a default of 1 or 2 newlines when adding items to a <see cref="Block"/>.
        /// </summary>
        public override int DefaultNewLines(CodeObject previous)
        {
            // Default to a preceeding blank line if the object has first-on-line annotations
            if (HasFirstOnLineAnnotations)
            {
                return(2);
            }

            // Default to a preceeding blank line if the previous object was another using directive
            // with a different root namespace, otherwise use a single newline.
            if (previous is UsingDirective)
            {
                SymbolicRef symbolicRef = ((UsingDirective)previous).Namespace.FirstPrefix() as SymbolicRef;
                if (symbolicRef != null && !symbolicRef.IsSameRef(Namespace.FirstPrefix() as SymbolicRef))
                {
                    return(2);
                }
                return(1);
            }

            // Default to no preceeding blank line if the previous object was an alias directive with
            // the same root namespace, otherwise use a preceeding blank line.
            if (previous is Alias)
            {
                SymbolicRef symbolicRef = ((Alias)previous).Expression.FirstPrefix() as SymbolicRef;
                if (symbolicRef != null && symbolicRef.IsSameRef(Namespace.FirstPrefix() as SymbolicRef))
                {
                    return(1);
                }
                return(2);
            }

            // Default to a preceeding blank line if the object is a different type than the previous one
            if (previous.GetType() != GetType())
            {
                return(2);
            }
            return(1);
        }
        /// <summary>
        /// Determine if the current reference refers to the same code object as the specified reference.
        /// </summary>
        public override bool IsSameRef(SymbolicRef symbolicRef)
        {
            NamespaceRef namespaceRef = (symbolicRef is AliasRef ? ((AliasRef)symbolicRef).Namespace : symbolicRef as NamespaceRef);

            return(namespaceRef != null && Reference == namespaceRef.Reference);
        }
 protected DocNameBase(SymbolicRef nameRef, params DocComment[] docComments)
     : base(docComments)
 {
     NameRef = nameRef;
 }
 protected DocNameBase(SymbolicRef nameRef, string text)
     : base(text)
 {
     NameRef = nameRef;
 }
 /// <summary>
 /// Determine if the current reference refers to the same code object as the specified reference.
 /// </summary>
 public override bool IsSameRef(SymbolicRef symbolicRef)
 {
     return(base.IsSameRef(symbolicRef) || (IsType && Type.IsSameRef(symbolicRef)) || (IsNamespace && Namespace.IsSameRef(symbolicRef)));
 }
 /// <summary>
 /// Create an <see cref="UnresolvedRef"/>.
 /// </summary>
 public UnresolvedRef(SymbolicRef symbolicRef)
     : this(symbolicRef.Name, symbolicRef.IsFirstOnLine)
 {
     Parent = symbolicRef.Parent;
     SetLineCol(symbolicRef);
 }
 /// <summary>
 /// Determine if the current reference refers to the same code object as the specified reference.
 /// </summary>
 public virtual bool IsSameRef(SymbolicRef symbolicRef)
 {
     return(symbolicRef != null && Reference == symbolicRef.Reference);
 }
Example #14
0
 /// <summary>
 /// Create a <see cref="BaseInitializer"/> operator.
 /// </summary>
 public BaseInitializer(SymbolicRef symbolicRef, params Expression[] parameters)
     : base(symbolicRef, parameters)
 {
 }
 /// <summary>
 /// Find a child namespace in the specified <see cref="NamespaceRef"/> with the specified name.
 /// </summary>
 /// <returns>A <see cref="NamespaceRef"/> to the namespace, or an <see cref="UnresolvedRef"/> if no match was found.</returns>
 public static SymbolicRef Find(SymbolicRef symbolicRef, string name)
 {
     return(Find(symbolicRef, name, false));
 }
 /// <summary>
 /// Create an <see cref="ExternAlias"/> with the specified namespace reference.
 /// </summary>
 public ExternAlias(SymbolicRef rootNamespaceRef)
 {
     RootNamespaceRef = rootNamespaceRef;
 }
 /// <summary>
 /// Create an <see cref="Attribute"/>.
 /// </summary>
 public Attribute(SymbolicRef constructorRef, params Expression[] arguments)
     : this(AttributeTarget.None, constructorRef, arguments)
 {
 }
 /// <summary>
 /// Create an <see cref="Attribute"/>.
 /// </summary>
 public Attribute(AttributeTarget target, SymbolicRef constructorRef, params Expression[] arguments)
     : this(target, (arguments.Length > 0 ? (Expression) new Call(constructorRef, arguments) : constructorRef))
 {
 }
Example #19
0
 /// <summary>
 /// Create a <see cref="Dot"/> operator.
 /// </summary>
 public Dot(Expression left, SymbolicRef right)
     : base(left, right)
 {
 }
 /// <summary>
 /// Create a <see cref="ConstraintClause"/>.
 /// </summary>
 public ConstraintClause(SymbolicRef symbolicRef, params TypeParameterConstraint[] constraints)
 {
     TypeParameter = symbolicRef;
     CreateConstraints().AddRange(constraints);
 }
Example #21
0
 protected ConstructorInitializer(SymbolicRef symbolicRef, params Expression[] parameters)
     : base(symbolicRef, parameters)
 {
 }