Member code element.
상속: AttributedElement
예제 #1
0
        /// <summary>
        /// Gets the type attribute.
        /// </summary>
        /// <param name="codeElement">The code element.</param>
        /// <returns>The type attibute as text.</returns>
        private static string GetTypeAttribute(ICodeElement codeElement)
        {
            string attributeString = string.Empty;

            MemberElement memberElement = codeElement as MemberElement;

            if (memberElement != null)
            {
                attributeString = memberElement.Type;
            }
            else
            {
                switch (codeElement.ElementType)
                {
                case ElementType.Type:
                    attributeString = EnumUtilities.ToString(((TypeElement)codeElement).Type);
                    break;

                case ElementType.Comment:
                    attributeString = EnumUtilities.ToString(((CommentElement)codeElement).Type);
                    break;

                case ElementType.Using:
                    attributeString = EnumUtilities.ToString(((UsingElement)codeElement).Type);
                    break;
                }
            }

            return(attributeString);
        }
예제 #2
0
        /// <summary>
        /// Creates a comparison delegate based on the configuration.
        /// </summary>
        /// <param name="compareAttribute">The compare attribute.</param>
        /// <returns>
        /// Comparision delegate for two code elements.
        /// </returns>
        public Comparison <ICodeElement> CreateComparison(ElementAttributeType compareAttribute)
        {
            Comparison <ICodeElement> comparison = delegate(ICodeElement x, ICodeElement y)
            {
                int compareValue = 0;

                if (x == null && y != null)
                {
                    compareValue = -1;
                }
                else if (x != null && y == null)
                {
                    compareValue = 1;
                }
                else
                {
                    switch (compareAttribute)
                    {
                    case ElementAttributeType.Access:
                        AttributedElement attributedX = x as AttributedElement;
                        AttributedElement attributedY = y as AttributedElement;
                        if (attributedX != null && attributedY != null)
                        {
                            compareValue = attributedX.Access.CompareTo(attributedY.Access);
                        }
                        break;

                    case ElementAttributeType.Modifier:
                        MemberElement memberX = x as MemberElement;
                        MemberElement memberY = y as MemberElement;
                        if (memberX != null && memberY != null)
                        {
                            compareValue = memberX.MemberModifiers.CompareTo(memberY.MemberModifiers);
                        }
                        break;

                    case ElementAttributeType.ElementType:
                        compareValue = x.ElementType.CompareTo(y.ElementType);
                        break;

                    default:
                        if (compareAttribute == ElementAttributeType.Type &&
                            x is TypeElement && y is TypeElement)
                        {
                            compareValue = ((TypeElement)x).Type.CompareTo(((TypeElement)y).Type);
                        }
                        else if (compareAttribute == ElementAttributeType.Type &&
                                 x is UsingElement && y is UsingElement)
                        {
                            compareValue = ((UsingElement)x).Type.CompareTo(((UsingElement)y).Type);
                        }
                        else
                        {
                            string attributeX = ElementUtilities.GetAttribute(compareAttribute, x);
                            string attributeY = ElementUtilities.GetAttribute(compareAttribute, y);
                            compareValue = StringComparer.OrdinalIgnoreCase.Compare(attributeX, attributeY);
                        }
                        break;
                    }
                }

                return(compareValue);
            };

            return(comparison);
        }