Esempio n. 1
0
        private void AppendType([NotNull] IType type, NamespaceDisplays expectedNamespaceDisplay)
        {
            var arrayType = type as IArrayType;

            if (arrayType != null)
            {
                AppendArrayType(arrayType, expectedNamespaceDisplay);
                return;
            }

            var pointerType = type as IPointerType;

            if (pointerType != null)
            {
                AppendPointerType(pointerType, expectedNamespaceDisplay);
                return;
            }

            var declaredType = type as IDeclaredType;

            if (declaredType != null)
            {
                AppendDeclaredType(declaredType, expectedNamespaceDisplay);
            }

            if (type is IAnonymousType)
            {
                AppendText("anonymous type", null);
            }
        }
Esempio n. 2
0
        private void AppendDeclaredType([NotNull] IDeclaredType declaredType, NamespaceDisplays expectedNamespaceDisplay)
        {
            if (declaredType.IsNullable())
            {
                IType underlyingType = declaredType.GetNullableUnderlyingType();
                if (underlyingType != null)
                {
                    AppendType(underlyingType, expectedNamespaceDisplay);
                    AppendText("?", VsHighlightingAttributeIds.Operator);
                    return;
                }
            }

            if (declaredType is IDynamicType)
            {
                AppendText("dynamic", VsHighlightingAttributeIds.Keyword);
                return;
            }

            if (_options.UseTypeKeywords)
            {
                string typeKeyword = CSharpTypeFactory.GetTypeKeyword(declaredType.GetClrName());
                if (typeKeyword != null)
                {
                    AppendText(typeKeyword, VsHighlightingAttributeIds.Keyword);
                    return;
                }
            }
            else if (declaredType.IsVoid())
            {
                AppendText("void", VsHighlightingAttributeIds.Keyword);
                return;
            }

            ITypeElement typeElement = declaredType.GetTypeElement();

            if (typeElement == null || !typeElement.IsValid())
            {
                AppendText(declaredType.GetPresentableName(UnknownLanguage.Instance), null);
                return;
            }

            AppendTypeElement(typeElement, declaredType.GetSubstitution(), expectedNamespaceDisplay);
        }
Esempio n. 3
0
        private void AppendTypeElement([NotNull] ITypeElement typeElement, [NotNull] ISubstitution substitution, NamespaceDisplays expectedNamespaceDisplay)
        {
            if (!(typeElement is ITypeParameter))
            {
                if ((_options.ShowNamespaces & expectedNamespaceDisplay) != NamespaceDisplays.None)
                {
                    AppendNamespace(typeElement.GetContainingNamespace());
                    AppendText(".", VsHighlightingAttributeIds.Operator);
                }

                ITypeElement containingType = typeElement.GetContainingType();
                if (containingType != null && !(typeElement is IDelegate && _options.FormatDelegatesAsLambdas))
                {
                    AppendDeclaredType(TypeFactory.CreateType(containingType, substitution), NamespaceDisplays.None);
                    AppendText(".", VsHighlightingAttributeIds.Operator);
                }
            }

            var deleg = typeElement as IDelegate;

            if (deleg != null && _options.FormatDelegatesAsLambdas && expectedNamespaceDisplay == NamespaceDisplays.Parameters)
            {
                AppendParameters(deleg.InvokeMethod, substitution, false);
                AppendText(" => ", VsHighlightingAttributeIds.Operator);
                AppendType(substitution.Apply(deleg.InvokeMethod.ReturnType), expectedNamespaceDisplay);
                return;
            }

            string attributeId = _options.UseReSharperColors
                                ? HighlightingAttributeIds.GetHighlightAttributeForTypeElement(typeElement)
                                : VsHighlightingAttributeIds.GetForTypeElement(typeElement);

            AppendText(FormatShortName(typeElement.ShortName), attributeId);
            AppendTypeParameters(typeElement, substitution);
        }
Esempio n. 4
0
 private void AppendPointerType([NotNull] IPointerType pointerType, NamespaceDisplays expectedNamespaceDisplay)
 {
     AppendType(pointerType.ElementType, expectedNamespaceDisplay);
     AppendText("*", VsHighlightingAttributeIds.Operator);
 }
Esempio n. 5
0
 private void AppendArrayType([NotNull] IArrayType arrayType, NamespaceDisplays expectedNamespaceDisplay)
 {
     AppendType(arrayType.ElementType, expectedNamespaceDisplay);
     AppendText("[" + new string(',', arrayType.Rank - 1) + "]", null);
 }
Esempio n. 6
0
        private void AppendElementType([NotNull] IDeclaredElement element, [NotNull] ISubstitution substitution, NamespaceDisplays namespaceDisplays,
                                       [CanBeNull] string before, [CanBeNull] string after)
        {
            // Use the special type first if available (eg Razor helper), colorize it as a keyword
            string specialTypeString = CSharpModificationUtil.GetSpecialElementType(_specialTypeStyle, element, substitution);

            if (!specialTypeString.IsEmpty())
            {
                AppendText(before, null);
                AppendText(specialTypeString, VsHighlightingAttributeIds.Keyword);
                AppendText(after, null);
                return;
            }

            IType elementType = GetElementType(element, substitution);

            if (elementType == null)
            {
                return;
            }

            AppendText(before, null);
            AppendType(elementType, namespaceDisplays);
            AppendText(after, null);
        }