コード例 #1
0
 public void WriteIdentifier(string id, bool escape)
 {
     // Escape keywords
     if (escape && CSharpCciExtensions.IsKeyword(id))
     {
         id = "@" + id;
     }
     _writer.WriteIdentifier(id);
 }
コード例 #2
0
        public static void WriteSyntaxToken(this ISyntaxWriter writer, SyntaxToken token)
        {
            switch (token.Type)
            {
            default:
            case SyntaxTokenType.Literal:
                writer.Write(token.Token); break;

            case SyntaxTokenType.Symbol:
                writer.WriteSymbol(token.Token); break;

            case SyntaxTokenType.Identifier:
                writer.WriteIdentifier(token.Token); break;

            case SyntaxTokenType.Keyword:
                writer.WriteKeyword(token.Token); break;

            case SyntaxTokenType.TypeName:
                writer.WriteTypeName(token.Token); break;
            }
        }
コード例 #3
0
        private void WriteTypeName(ITypeReference type, bool noSpace = false, IEnumerable <ICustomAttribute> attributes = null, bool useTypeKeywords = true,
                                   bool omitGenericTypeList          = false)
        {
            if (attributes != null && IsDynamic(attributes))
            {
                WriteKeyword("dynamic", noSpace: noSpace);
                return;
            }

            NameFormattingOptions namingOptions = NameFormattingOptions.TypeParameters | NameFormattingOptions.ContractNullable;

            if (useTypeKeywords)
            {
                namingOptions |= NameFormattingOptions.UseTypeKeywords;
            }

            if (_forCompilationIncludeGlobalprefix)
            {
                namingOptions |= NameFormattingOptions.UseGlobalPrefix;
            }

            if (!_forCompilation)
            {
                namingOptions |= NameFormattingOptions.OmitContainingNamespace;
            }

            if (omitGenericTypeList)
            {
                namingOptions |= NameFormattingOptions.EmptyTypeParameterList;
            }

            void WriteTypeNameInner(ITypeReference typeReference)
            {
                string name = TypeHelper.GetTypeName(typeReference, namingOptions);

                if (CSharpCciExtensions.IsKeyword(name))
                {
                    _writer.WriteKeyword(name);
                }
                else
                {
                    _writer.WriteTypeName(name);
                }
            }

            var definition = type.GetDefinitionOrNull();

            if (definition is IGenericTypeInstance genericType && genericType.IsValueTuple())
            {
                string[] names = attributes.GetValueTupleNames();

                _writer.WriteSymbol("(");

                int i = 0;
                foreach (var parameter in genericType.GenericArguments)
                {
                    if (i != 0)
                    {
                        _writer.WriteSymbol(",");
                        _writer.WriteSpace();
                    }

                    WriteTypeNameInner(parameter);

                    if (names?[i] != null)
                    {
                        _writer.WriteSpace();
                        _writer.WriteIdentifier(names[i]);
                    }

                    i++;
                }

                _writer.WriteSymbol(")");
            }