Ejemplo n.º 1
0
        private static void GenerateEnumeration(ScriptGenerator generator, EnumerationSymbol enumSymbol)
        {
            ScriptTextWriter writer = generator.Writer;
            string enumName = enumSymbol.FullGeneratedName;

            writer.Write("var ");
            writer.Write(enumSymbol.FullGeneratedName);
            writer.Write(" = {");
            writer.Indent++;

            bool firstValue = true;
            foreach (MemberSymbol memberSymbol in enumSymbol.Members) {
                EnumerationFieldSymbol fieldSymbol = memberSymbol as EnumerationFieldSymbol;
                if (fieldSymbol == null) {
                    continue;
                }

                if (firstValue == false) {
                    writer.Write(", ");
                }

                writer.WriteLine();
                writer.Write(fieldSymbol.GeneratedName);
                writer.Write(": ");
                if (enumSymbol.UseNamedValues) {
                    writer.Write(Utility.QuoteString(enumSymbol.CreateNamedValue(fieldSymbol)));
                }
                else {
                    writer.Write(fieldSymbol.Value);
                }
                firstValue = false;
            }

            writer.Indent--;
            writer.WriteLine();
            writer.Write("};");
            writer.WriteLine();
        }
Ejemplo n.º 2
0
        private static void GenerateEnumeration(ScriptGenerator generator, EnumerationSymbol enumSymbol) {
            ScriptTextWriter writer = generator.Writer;

            if (enumSymbol.Namespace.Length == 0) {
                writer.Write("window.");
            }

            writer.Write(enumSymbol.FullGeneratedName);
            writer.WriteTrimmed(" = ");
            writer.Write("function()");
            writer.WriteTrimmed(" { ");

            if (generator.Options.EnableDocComments) {
                DocCommentGenerator.GenerateComment(generator, enumSymbol);
            }

            writer.Write("};");
            writer.WriteNewLine();
            writer.Write(enumSymbol.FullGeneratedName);
            writer.Write(".prototype = {");
            writer.Indent++;

            bool firstValue = true;
            foreach (MemberSymbol memberSymbol in enumSymbol.Members) {
                EnumerationFieldSymbol fieldSymbol = memberSymbol as EnumerationFieldSymbol;
                if (fieldSymbol == null) {
                    continue;
                }

                if (firstValue == false) {
                    writer.WriteTrimmed(", ");
                }

                writer.WriteNewLine();
                writer.Write(fieldSymbol.GeneratedName);
                writer.WriteTrimmed(": ");
                if (enumSymbol.UseNamedValues) {
                    writer.Write(Utility.QuoteString(enumSymbol.CreateNamedValue(fieldSymbol)));
                }
                else {
                    writer.Write(fieldSymbol.Value);
                }
                firstValue = false;
            }

            writer.Indent--;
            writer.WriteNewLine();
            writer.WriteTrimmed("}");
            writer.WriteSignificantNewLine();

            writer.Write(enumSymbol.FullGeneratedName);
            writer.Write(".registerEnum('");
            writer.Write(enumSymbol.FullGeneratedName);
            writer.WriteTrimmed("', ");
            writer.Write(enumSymbol.Flags ? "true" : "false");
            writer.Write(");");
            writer.WriteNewLine();
        }