Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EnumItem"/> class.
        /// </summary>
        /// <param name="document">
        /// The document that contains the element.
        /// </param>
        /// <param name="parent">
        /// The parent of the element.
        /// </param>
        /// <param name="header">
        /// The Xml header for this element.
        /// </param>
        /// <param name="attributes">
        /// The list of attributes attached to this element.
        /// </param>
        /// <param name="declaration">
        /// The declaration code for this element.
        /// </param>
        /// <param name="initialization">
        /// The initialization expression, if there is one.
        /// </param>
        /// <param name="unsafeCode">
        /// Indicates whether the element resides within a block of unsafe code.
        /// </param>
        /// <param name="generated">
        /// Indicates whether the code element was generated or written by hand.
        /// </param>
        internal EnumItem(
            CsDocument document, 
            Enum parent, 
            XmlHeader header, 
            ICollection<Attribute> attributes, 
            Declaration declaration, 
            Expression initialization, 
            bool unsafeCode, 
            bool generated)
            : base(document, parent, ElementType.EnumItem, "enum item " + declaration.Name, header, attributes, declaration, unsafeCode, generated)
        {
            Param.Ignore(document, parent, header, attributes, declaration, initialization, unsafeCode, generated);

            this.initialization = initialization;
            if (this.initialization != null)
            {
                this.AddExpression(this.initialization);
            }
        }
        /// <summary>
        /// The save.
        /// </summary>
        /// <param name="enum">
        /// The enum.
        /// </param>
        private void Save(Enum @enum)
        {
            this.headerWriter.WriteLine(@enum.Name);
            this.headerWriter.WriteLine("{");

            this.headerWriter.Indent++;

            var first = true;
            foreach (var enumItem in @enum.Items)
            {
                var csElement = enumItem as CsElement;

                if (!first)
                {
                    this.headerWriter.WriteLine(",");
                }

                var index = enumItem.Name.LastIndexOf(' ');
                if (index >= 0)
                {
                    this.headerWriter.Write(enumItem.Name.Substring(index + 1));

                    if (enumItem.Initialization != null)
                    {
                        this.headerWriter.Write(" = ");

                        this.SwitchStreams();

                        //this.SetLogicalExpressionPrefixForOthers(string.Concat(parts[parts.Length - 2], '_'));

                        this.@switch(enumItem.Initialization);

                        this.ClearLogicalExpressionPrefixForOthers();

                        this.SwitchStreams();
                    }
                }

                first = false;
            }

            this.headerWriter.Indent--;

            this.headerWriter.WriteLine();
            this.headerWriter.WriteLine("};");
            this.headerWriter.WriteLine();
        }