Exemplo n.º 1
0
    private NamespaceDeclarationSyntax GenerateCodeForEnum(
        ref CompilationUnitSyntax compilationUnit)
    {
        IsEnum = true;

        // Create a namespace
        var @namespace = SyntaxProjectFactory.CreateNamespace(
            ApiProjectOptions,
            NameConstants.Contracts);

        var apiEnumSchema = ApiSchema.GetEnumSchema();

        // Create an enum
        var enumDeclaration = SyntaxEnumFactory.Create(apiEnumSchema.Item1.EnsureFirstCharacterToUpper(), apiEnumSchema.Item2);

        if (enumDeclaration.HasAttributeOfAttributeType(typeof(FlagsAttribute)))
        {
            // Add using statement to compilationUnit
            compilationUnit = compilationUnit.AddUsingStatements(new[] { "System" });
        }

        if (enumDeclaration.HasAttributeOfAttributeType(typeof(SuppressMessageAttribute)))
        {
            // Add using statement to compilationUnit
            compilationUnit = compilationUnit.AddUsingStatements(new[] { "System.Diagnostics.CodeAnalysis" });
        }

        // Add the enum to the namespace.
        @namespace = @namespace.AddMembers(enumDeclaration);
        return(@namespace);
    }