Ejemplo n.º 1
0
        /// <summary>
        /// Gets a list of type parameters for an element.
        /// </summary>
        public static List <TypeParameterItem> GetTypeParameters(CsElement element)
        {
            List <TypeParameterItem> result = new List <TypeParameterItem>();

            for (Node <CsToken> node = element.Tokens.First; node != null; node = node.Next)
            {
                if (node.Value.CsTokenType == CsTokenType.OpenCurlyBracket ||
                    node.Value.CsTokenType == CsTokenType.OpenParenthesis ||
                    node.Value.CsTokenType == CsTokenType.BaseColon ||
                    node.Value.CsTokenType == CsTokenType.Where)
                {
                    break;
                }

                if (node.Value.CsTokenClass == CsTokenClass.GenericType)
                {
                    GenericType type = (GenericType)node.Value;

                    if (element.ElementType == ElementType.Method)
                    {
                        Method method = (Method)element;
                        if (type == method.ReturnType)
                        {
                            continue;
                        }
                    }

                    if (element.ElementType == ElementType.Delegate)
                    {
                        Delegate @delegate = (Delegate)element;
                        if (type == @delegate.ReturnType)
                        {
                            continue;
                        }
                    }

                    for (Node <CsToken> inner = type.ChildTokens.First; inner != null; inner = inner.Next)
                    {
                        if (inner.Value.CsTokenClass == CsTokenClass.Type)
                        {
                            result.Add(new TypeParameterItem
                            {
                                Name       = inner.Value.Text,
                                Tokens     = new[] { inner.Value },
                                LineNumber = inner.Value.LineNumber
                            });
                        }
                    }
                }
            }

            return(result);
        }
        /// <summary>
        /// The save.
        /// </summary>
        /// <param name="delegate">
        /// The delegate.
        /// </param>
        private void Save(Delegate @delegate)
        {
            // 1 to destHeader
            if (!(@delegate.Parent is Namespace))
            {
                this.SaveModifiersBefore(@delegate);
            }

            // 1 to destHeader
            this.headerWriter.Write("delegate ");
            this.headerWriter.Write(@delegate.Declaration.ElementType);
            this.headerWriter.Write(" ");
            this.headerWriter.Write(@delegate.Declaration.Name);
            this.headerWriter.Write(@delegate.Parameters);

            this.headerWriter.WriteLine(';');
        }