Ejemplo n.º 1
0
        /// <summary>
        /// ユニット定義情報を<see cref="TextWriter"/>に書き出します。
        /// メソッド内で<see cref="IDisposable.Dispose"/>は呼び出されません。
        /// 呼び出し側で必要に応じて呼び出しを行ってください。
        /// </summary>
        /// <param name="self">レシーバ・オブジェクト</param>
        /// <param name="writer">ライター・オブジェクト</param>
        /// <param name="options">書式化オプション</param>
        public static void WriteTo(this IUnit self, TextWriter writer, FormatOptions options)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            var           depth = self.FullName.Fragments.Count;
            StringBuilder b     = new StringBuilder();

            writer.AppendTabs(depth - 1, options).Append("unit=")
            .Append(self.Attributes.UnitName).Append(',')
            .Append(self.Attributes.PermissionMode).Append(',')
            .Append(self.Attributes.Jp1UserName).Append(',')
            .Append(self.Attributes.ResourceGroupName).Append(';').Append(options.NewLine)
            .AppendTabs(depth - 1, options).Append('{').Append(options.NewLine);

            foreach (IParameter p in self.Parameters)
            {
                writer.AppendTabs(depth, options).Append(p.ToString()).Append(options.NewLine);
            }

            foreach (IUnit u in self.SubUnits)
            {
                u.WriteTo(writer, options);
                writer.Append(options.NewLine);
            }

            writer.AppendTabs(depth - 1, options).Append('}');
            writer.Flush();
        }