コード例 #1
0
        protected override void AppendParameterDeclaration(T4ParameterDescription description)
        {
            foreach (string inspection in DisabledPropertyInspections)
            {
                AppendDisabledInspections(inspection);
            }

            Result.Append("        private global::");
            var type = description.TypeToken;

            if (CSharpLexer.IsKeyword(type.GetText()))
            {
                Result.Append("@");
            }
            Result.AppendMapped(type);

            Result.Append(" ");
            var name = description.NameToken;

            if (CSharpLexer.IsKeyword(name.GetText()))
            {
                Result.Append("@");
            }
            Result.AppendMapped(name);

            Result.Append(" => ");
            Result.Append(description.FieldNameString);
            Result.AppendLine(";");
        }
コード例 #2
0
 protected override void DoRun(IT4AttributeValue element, IHighlightingConsumer consumer)
 {
     if (!CSharpLexer.IsKeyword(element.GetText()))
     {
         return;
     }
     consumer.AddHighlighting(new EscapedKeywordWarning(element));
 }
コード例 #3
0
 public static string EscapeKeyword([NotNull] this string s)
 {
     if (!CSharpLexer.IsKeyword(s))
     {
         return(s);
     }
     return('@' + s);
 }
コード例 #4
0
 public void AppendName([NotNull] T4CSharpCodeGenerationResult result)
 {
     if (CSharpLexer.IsKeyword(NameToken.GetText()))
     {
         result.Append("@");
     }
     result.AppendMapped(NameToken);
 }
コード例 #5
0
        private string GetTypeFqnString()
        {
            string typeText = TypeToken.GetText();

            if (CSharpLexer.IsKeyword(typeText))
            {
                return($"@{typeText}");
            }
            return(typeText);
        }
コード例 #6
0
        /// <summary>
        /// Determines if the word is a C# or XmlDoc keyword.
        /// </summary>
        /// <param name="word">The word to test.</param>
        /// <returns>True if a keyword.</returns>
        public static bool IsKeyword(string word)
        {
            if (string.IsNullOrEmpty(word))
            {
                return(false);
            }

            var lowerWord = word.ToLower();

            return(CSharpLexer.IsKeyword(lowerWord) || XmlDocTagNames.Contains(lowerWord));
        }
コード例 #7
0
        private void AppendConstantValue([NotNull] ConstantValue constantValue)
        {
            if (constantValue.IsBadValue())
            {
                AppendText("bad value", null);
                return;
            }

            IEnum enumType = constantValue.Type.GetEnumType();

            if (enumType != null && AppendEnumValue(constantValue, enumType))
            {
                return;
            }

            string presentation = constantValue.GetPresentation(CSharpLanguage.Instance);

            if (presentation != null && CSharpLexer.IsKeyword(presentation))
            {
                AppendText(presentation, VsHighlightingAttributeIds.Keyword);
                return;
            }

            IType type = constantValue.Type;

            if (type != null && type.IsNullable())
            {
                type = type.GetNullableUnderlyingType();
            }

            if (type == null)
            {
                AppendText(presentation, null);
                return;
            }

            if (type.IsString())
            {
                AppendText(presentation, VsHighlightingAttributeIds.String);
            }
            else if (type.IsChar())
            {
                AppendText(presentation, VsHighlightingAttributeIds.String);
            }
            else if (type.IsPredefinedNumeric())
            {
                AppendText(presentation, VsHighlightingAttributeIds.Number);
            }
            else
            {
                AppendText(presentation, null);
            }
        }
コード例 #8
0
        protected override void AppendTooltip(CannotUseThisBaseInInitializerError highlighting, CSharpColorizer colorizer)
        {
            string text = highlighting.Expression.GetText();

            colorizer.AppendPlainText("Cannot use '");
            if (CSharpLexer.IsKeyword(text))
            {
                colorizer.AppendKeyword(text);
            }
            else
            {
                colorizer.AppendPlainText(text);
            }
            colorizer.AppendPlainText("' in member initializer");
        }
コード例 #9
0
        public void AppendTypeMapped([NotNull] T4CSharpCodeGenerationResult result)
        {
            string typeText = TypeToken.GetText();
            string keyword  = CSharpTypeFactory.GetTypeKeyword(new ClrTypeName(typeText));

            if (keyword != null)
            {
                result.Append(keyword);
                return;
            }

            result.Append("global::");
            if (CSharpLexer.IsKeyword(typeText))
            {
                result.Append("@");
            }
            result.AppendMapped(TypeToken);
        }
コード例 #10
0
        private void AppendDefaultValue([NotNull] IParameter parameter, [NotNull] ISubstitution substitution)
        {
            if (!parameter.IsOptional)
            {
                return;
            }

            DefaultValue defaultValue = parameter.GetDefaultValue().Substitute(substitution).Normalize();

            if (defaultValue.IsBadValue)
            {
                AppendText(" = ", VsHighlightingAttributeIds.Operator);
                AppendText("bad value", null);
                return;
            }

            if (defaultValue.IsConstant)
            {
                AppendText(" = ", VsHighlightingAttributeIds.Operator);
                string presentation = defaultValue.ConstantValue.GetPresentation(CSharpLanguage.Instance);
                AppendText(presentation, CSharpLexer.IsKeyword(presentation) ? VsHighlightingAttributeIds.Keyword : null);
                return;
            }

            IType defaultType = defaultValue.DefaultTypeValue;

            if (defaultType == null)
            {
                return;
            }

            if (defaultType.IsNullable() || defaultType.IsReferenceType())
            {
                AppendText(" = ", VsHighlightingAttributeIds.Operator);
                AppendText("null", VsHighlightingAttributeIds.Keyword);
                return;
            }

            AppendText(" = ", VsHighlightingAttributeIds.Operator);
            AppendText("default", VsHighlightingAttributeIds.Keyword);
            AppendText("(", null);
            AppendType(defaultType, NamespaceDisplays.Parameters);
            AppendText(")", null);
        }
コード例 #11
0
 private static string FormatShortName([NotNull] string shortName)
 {
     return(CSharpLexer.IsKeyword(shortName) ? "@" + shortName : shortName);
 }
コード例 #12
0
        private void AppendConstantValue([NotNull] ConstantValue constantValue, bool treatEnumAsIntegral)
        {
            if (constantValue.IsBadValue())
            {
                AppendText("bad value", null);
                return;
            }

            IEnum enumType = constantValue.Type.GetEnumType();

            if (enumType != null)
            {
                if (treatEnumAsIntegral)
                {
                    AppendText(constantValue.Value?.ToString() ?? String.Empty, _highlighterIdProvider.Number);
                    return;
                }
                if (AppendEnumValue(constantValue, enumType))
                {
                    return;
                }
            }

            string presentation = constantValue.GetPresentation(CSharpLanguage.Instance);

            if (presentation != null && CSharpLexer.IsKeyword(presentation))
            {
                AppendText(presentation, _highlighterIdProvider.Keyword);
                return;
            }

            IType type = constantValue.Type;

            if (type.IsNullable())
            {
                type = type.GetNullableUnderlyingType();
            }

            if (type == null)
            {
                AppendText(presentation, null);
                return;
            }

            if (type.IsString())
            {
                AppendText(presentation, _highlighterIdProvider.String);
            }
            else if (type.IsChar())
            {
                AppendText(presentation, _highlighterIdProvider.String);
            }
            else if (type.IsPredefinedNumeric())
            {
                AppendText(presentation, _highlighterIdProvider.Number);
            }
            else
            {
                AppendText(presentation, null);
            }
        }