Пример #1
0
        /// <summary>
        ///   Writes the component to a stream.
        /// </summary>
        /// <param name="wr"><see cref="StreamWriter"/> object to write the component to.</param>
        /// <param name="indentOffset">Number of indents to add before any documentation begins.</param>
        /// <exception cref="ArgumentNullException"><paramref name="wr"/> is a null reference.</exception>
        /// <exception cref="InvalidOperationException">No generics or ports were specified.</exception>
        /// <exception cref="IOException">An error occurred while writing to the <see cref="StreamWriter"/> object.</exception>
        public override void Write(StreamWriter wr, int indentOffset)
        {
            if (wr == null)
            {
                throw new ArgumentNullException("wr");
            }

            if (SkipDeclaration)
            {
                return;
            }

            if (indentOffset < 0)
            {
                indentOffset = 0;
            }

            if (Generics.Count == 0 && Ports.Count == 0)
            {
                throw new InvalidOperationException(string.Format("An attempt was made to write a component ({0}), but it doesn't have any ports or generics defined.", Name));
            }

            // Write the header.
            WriteBasicHeader(wr, indentOffset);
            DocumentationHelper.WriteLine(wr, string.Format("component {0} is", Name), indentOffset);

            if (Generics.Count > 0)
            {
                SimplifiedGenericInfo.WriteGenericDeclaration(wr, Generics.ToArray(), indentOffset);
            }

            if (Ports.Count > 0)
            {
                SimplifiedPortInfo.WritePortDeclaration(wr, Ports.ToArray(), indentOffset);
            }

            StringBuilder sb = new StringBuilder();

            sb.Append("end component");
            if (DefaultValues.AddOptionalNames)
            {
                sb.AppendFormat(" {0}", Name);
            }
            sb.Append(";");
            DocumentationHelper.WriteLine(wr, sb.ToString(), indentOffset);
        }
Пример #2
0
        /// <summary>
        ///   Writes the entity to a stream.
        /// </summary>
        /// <param name="wr"><see cref="StreamWriter"/> object to write the entity to.</param>
        /// <param name="indentOffset">Number of indents to add before any documentation begins.</param>
        /// <exception cref="ArgumentNullException"><paramref name="wr"/> is a null reference.</exception>
        /// <exception cref="InvalidOperationException">The number of ports and generics is zero.</exception>
        /// <exception cref="IOException">An error occurred while writing to the <see cref="StreamWriter"/> object.</exception>
        public override void Write(StreamWriter wr, int indentOffset)
        {
            if (wr == null)
            {
                throw new ArgumentNullException("wr");
            }

            if (indentOffset < 0)
            {
                indentOffset = 0;
            }

            if (Generics.Count == 0 && Ports.Count == 0)
            {
                throw new InvalidOperationException(string.Format("An attempt was made to write an entity ({0}), but the entity does not have any ports or generics.", Name));
            }

            // Generate the documentation lookup table.
            Dictionary <string, string[]> lookup = new Dictionary <string, string[]>();

            lookup.Add("Summary", new string[] { Summary });

            if (Generics.Count > 0)
            {
                List <string> subItems = new List <string>(Generics.Count);
                foreach (GenericInfo info in Generics)
                {
                    subItems.Add(info.GetDocumentationString());
                }
                lookup.Add("Generics", subItems.ToArray());
            }

            if (Ports.Count > 0)
            {
                List <string> subItems = new List <string>(Ports.Count);
                foreach (PortInfo info in Ports)
                {
                    subItems.Add(info.GetDocumentationString());
                }
                lookup.Add("Ports", subItems.ToArray());
            }

            if (!string.IsNullOrWhiteSpace(Remarks))
            {
                lookup.Add("Remarks", new string[] { Remarks });
            }

            // Write the header.
            DocumentationHelper.WriteFlowerLine(wr, indentOffset);
            DocumentationHelper.WriteGeneralDocumentationElements(wr, lookup, indentOffset);
            DocumentationHelper.WriteFlowerLine(wr, indentOffset);
            DocumentationHelper.WriteLine(wr, string.Format("entity {0} is", Name), indentOffset);

            if (Generics.Count > 0)
            {
                SimplifiedGenericInfo.WriteGenericDeclaration(wr, Generics.ToArray(), indentOffset);
            }

            if (Ports.Count > 0)
            {
                SimplifiedPortInfo.WritePortDeclaration(wr, Ports.ToArray(), indentOffset);
            }

            StringBuilder sb = new StringBuilder();

            sb.Append("end");
            if (DefaultValues.AddOptionalTypeNames)
            {
                sb.Append(" entity");
            }
            if (DefaultValues.AddOptionalNames)
            {
                sb.AppendFormat(" {0}", Name);
            }
            sb.Append(";");
            DocumentationHelper.WriteLine(wr, sb.ToString(), indentOffset);
        }