CloseScope() public method

public CloseScope ( ) : void
return void
コード例 #1
0
ファイル: CSharpGenerator.cs プロジェクト: kcj/czml-writer
        private void WriteConstructorsAndCloneMethod(CodeWriter writer, Schema schema)
        {
            WriteSummaryText(writer, "Initializes a new instance.");
            writer.WriteLine("public {0}CesiumWriter(string propertyName)", schema.NameWithPascalCase);
            writer.WriteLine("    : base(propertyName)");
            writer.OpenScope();
            WriteAsTypeLazyInitialization(writer, schema);
            writer.CloseScope();
            writer.WriteLine();

            WriteSummaryText(writer, "Initializes a new instance as a copy of an existing instance.");
            WriteParameterText(writer, "existingInstance", "The existing instance to copy.");
            writer.WriteLine("protected {0}CesiumWriter({0}CesiumWriter existingInstance)", schema.NameWithPascalCase);
            writer.WriteLine("    : base(existingInstance)");
            writer.OpenScope();
            WriteAsTypeLazyInitialization(writer, schema);
            writer.CloseScope();
            writer.WriteLine();

            WriteInheritDoc(writer);
            writer.WriteLine("public override {0}CesiumWriter Clone()", schema.NameWithPascalCase);
            writer.OpenScope();
            writer.WriteLine("return new {0}CesiumWriter(this);", schema.NameWithPascalCase);
            writer.CloseScope();
            writer.WriteLine();
        }
コード例 #2
0
ファイル: CSharpGenerator.cs プロジェクト: kcj/czml-writer
        private void GeneratePacketWriter(Schema packetSchema)
        {
            string packetWriterFilename = Path.Combine(m_outputDirectory, "PacketCesiumWriter.cs");

            using (CodeWriter writer = new CodeWriter(packetWriterFilename))
            {
                WriteGeneratedWarning(writer);
                writer.WriteLine();
                WriteNamespaces(writer, packetSchema);
                writer.WriteLine();

                writer.WriteLine("namespace {0}", m_configuration.Namespace);
                writer.OpenScope();

                WriteDescriptionAsClassSummary(writer, packetSchema);
                writer.WriteLine(m_configuration.Access + " class PacketCesiumWriter : CesiumElementWriter");
                writer.OpenScope();

                WritePropertyNameConstants(writer, packetSchema);
                WritePropertyLazyFields(writer, packetSchema);
                WritePacketOpenClose(writer);
                WriteProperties(writer, packetSchema);

                writer.CloseScope();

                writer.CloseScope();
            }
        }
コード例 #3
0
        private void GenerateWriterClass(Schema schema)
        {
            if (m_writtenSchemas.Contains(schema))
                return;

            m_writtenSchemas.Add(schema);

            string writerFilename = Path.Combine(m_outputDirectory, schema.NameWithPascalCase + "CesiumWriter.cs");
            using (CodeWriter writer = new CodeWriter(writerFilename))
            {
                WriteGeneratedWarning(writer);
                writer.WriteLine();
                WriteNamespaces(writer, schema);
                writer.WriteLine();

                writer.WriteLine("namespace {0}", m_configuration.Namespace);
                writer.OpenScope();

                WriteDescriptionAsClassSummary(writer, schema);

                string defaultValueType = GetDefaultValueType(schema);

                if (defaultValueType != null)
                {
                    bool isInterpolatable = schema.Extends != null && schema.Extends.Name == "InterpolatableProperty";
                    if (isInterpolatable)
                        writer.WriteLine("public class {0}CesiumWriter : CesiumInterpolatableValuePropertyWriter<{1}, {0}CesiumWriter>", schema.NameWithPascalCase, defaultValueType);
                    else
                        writer.WriteLine("public class {0}CesiumWriter : CesiumValuePropertyWriter<{1}, {0}CesiumWriter>", schema.NameWithPascalCase, defaultValueType);
                }
                else
                {
                    writer.WriteLine("public class {0}CesiumWriter : CesiumPropertyWriter<{0}CesiumWriter>", schema.NameWithPascalCase);
                }

                writer.OpenScope();

                WritePropertyNameConstants(writer, schema);
                WritePropertyLazyFields(writer, schema);
                WriteConstructorsAndCloneMethod(writer, schema);
                WriteProperties(writer, schema);

                writer.CloseScope();

                writer.CloseScope();
            }
        }
コード例 #4
0
ファイル: CSharpGenerator.cs プロジェクト: kcj/czml-writer
        private void GenerateWriterClass(Schema schema)
        {
            if (m_writtenSchemas.Contains(schema))
            {
                return;
            }

            m_writtenSchemas.Add(schema);

            string writerFilename = Path.Combine(m_outputDirectory, schema.NameWithPascalCase + "CesiumWriter.cs");

            using (CodeWriter writer = new CodeWriter(writerFilename))
            {
                WriteGeneratedWarning(writer);
                writer.WriteLine();
                WriteNamespaces(writer, schema);
                writer.WriteLine();

                writer.WriteLine("namespace {0}", m_configuration.Namespace);
                writer.OpenScope();

                WriteDescriptionAsClassSummary(writer, schema);

                bool isInterpolatable = schema.Extends != null && schema.Extends.Name == "InterpolatableProperty";
                if (isInterpolatable)
                {
                    writer.WriteLine(m_configuration.Access + " class {0}CesiumWriter : CesiumInterpolatablePropertyWriter<{0}CesiumWriter>", schema.NameWithPascalCase);
                }
                else
                {
                    writer.WriteLine(m_configuration.Access + " class {0}CesiumWriter : CesiumPropertyWriter<{0}CesiumWriter>", schema.NameWithPascalCase);
                }

                writer.OpenScope();

                WritePropertyNameConstants(writer, schema);
                WritePropertyLazyFields(writer, schema);
                WriteConstructorsAndCloneMethod(writer, schema);
                WriteProperties(writer, schema);
                WriteAsTypeMethods(writer, schema);

                writer.CloseScope();

                writer.CloseScope();
            }
        }
コード例 #5
0
ファイル: CSharpGenerator.cs プロジェクト: kcj/czml-writer
        private static void WritePacketOpenClose(CodeWriter writer)
        {
            WriteSummaryText(writer, "Writes the start of a new JSON object representing the packet.");
            writer.WriteLine("protected override void OnOpen()");
            writer.OpenScope();
            writer.WriteLine("Output.WriteStartObject();");
            writer.CloseScope();

            writer.WriteLine();

            WriteSummaryText(writer, "Writes the end of the JSON object representing the packet.");
            writer.WriteLine("protected override void OnClose()");
            writer.OpenScope();
            writer.WriteLine("Output.WriteEndObject();");
            writer.CloseScope();

            writer.WriteLine();
        }
コード例 #6
0
        private void WriteLeafProperty(CodeWriter writer, Schema schema, Property property, bool isFirstValueProperty)
        {
            OverloadInfo[] overloads = GetOverloadsForProperty(property);

            foreach (OverloadInfo overload in overloads)
            {
                WriteSummaryText(writer, string.Format("Writes the <code>{0}</code> property.  The <code>{0}</code> property specifies {1}", property.Name, StringHelper.UncapitalizeFirstLetter(property.Description)));
                foreach (ParameterInfo parameter in overload.Parameters)
                {
                    if (string.IsNullOrEmpty(parameter.Description))
                    {
                        continue;
                    }
                    WriteParameterText(writer, parameter.Name, parameter.Description);
                }

                writer.WriteLine("public void Write{0}({1})", property.NameWithPascalCase, overload.FormattedParameters);
                writer.OpenScope();
                if (overload.CallOverload != null)
                {
                    writer.WriteLine("Write{0}({1});", property.NameWithPascalCase, overload.CallOverload);
                }
                else
                {
                    writer.WriteLine("const string PropertyName = {0}PropertyName;", property.NameWithPascalCase);

                    if (schema.Name == "Packet")
                    {
                        writer.WriteLine("Output.WritePropertyName(PropertyName);");
                    }
                    else if (isFirstValueProperty && !overload.NeedsInterval)
                    {
                        // For the first value property only, if an overload is marked
                        // as not needing an interval, because it writes a simple JSON
                        // type (string, number, boolean), we can skip opening an interval
                        // and just write the property value directly.
                        writer.WriteLine("if (IsInterval)");
                        writer.WriteLine("    Output.WritePropertyName(PropertyName);");
                    }
                    else
                    {
                        writer.WriteLine("OpenIntervalIfNecessary();");

                        if (overload.WritePropertyName)
                        {
                            writer.WriteLine("Output.WritePropertyName(PropertyName);");
                        }
                    }

                    writer.WriteLine(overload.WriteValue);
                }
                writer.CloseScope();
                writer.WriteLine();
            }
        }
コード例 #7
0
        private static void WritePacketOpenClose(CodeWriter writer)
        {
            WriteSummaryText(writer, "Writes the start of a new JSON object representing the packet.");
            writer.WriteLine("protected override void OnOpen()");
            writer.OpenScope();
            writer.WriteLine("Output.WriteStartObject();");
            writer.CloseScope();

            writer.WriteLine();

            WriteSummaryText(writer, "Writes the end of the JSON object representing the packet.");
            writer.WriteLine("protected override void OnClose()");
            writer.OpenScope();
            writer.WriteLine("Output.WriteEndObject();");
            writer.CloseScope();

            writer.WriteLine();
        }
コード例 #8
0
        private void GeneratePacketWriter(Schema packetSchema)
        {
            string packetWriterFilename = Path.Combine(m_outputDirectory, "PacketCesiumWriter.cs");
            using (CodeWriter writer = new CodeWriter(packetWriterFilename))
            {
                WriteGeneratedWarning(writer);
                writer.WriteLine();
                WriteNamespaces(writer, packetSchema);
                writer.WriteLine();

                writer.WriteLine("namespace {0}", m_configuration.Namespace);
                writer.OpenScope();

                WriteDescriptionAsClassSummary(writer, packetSchema);
                writer.WriteLine("public class PacketCesiumWriter : CesiumElementWriter");
                writer.OpenScope();

                WritePropertyNameConstants(writer, packetSchema);
                WritePropertyLazyFields(writer, packetSchema);
                WritePacketOpenClose(writer);
                WriteProperties(writer, packetSchema);

                writer.CloseScope();

                writer.CloseScope();
            }
        }
コード例 #9
0
        private void WriteAsTypeMethods(CodeWriter writer, Schema schema)
        {
            if (schema.Properties == null)
                return;

            foreach (Property property in schema.Properties)
            {
                if (!property.IsValue)
                    continue;
                if (PropertyValueIsIntervals(property))
                    continue;

                OverloadInfo[] overloads = GetOverloadsForProperty(property);

                if (overloads[0].Parameters.Length != 1)
                    continue;

                OverloadInfo sampleOverload = FindSampledDataOverload(overloads);

                string interfaceName = "ICesiumValuePropertyWriter";
                if (sampleOverload != null)
                    interfaceName = "ICesiumInterpolatableValuePropertyWriter";

                WriteSummaryText(writer, string.Format("Returns a wrapper for this instance that implements <see cref=\"{0}{{T}}\" /> to write a value in <code>{1}</code> format.  Because the returned instance is a wrapper for this instance, you may call <see cref=\"ICesiumElementWriter.Close\" /> on either this instance or the wrapper, but you must not call it on both.", interfaceName, property.NameWithPascalCase));
                writer.WriteLine("/// <returns>The wrapper.</returns>");
                writer.WriteLine("public {0}<{1}> As{2}()",
                                 interfaceName,
                                 overloads[0].Parameters[0].Type,
                                 property.NameWithPascalCase);
                writer.OpenScope();
                writer.WriteLine("return m_as{0}.Value;", property.NameWithPascalCase);
                writer.CloseScope();
                writer.WriteLine();

                string adaptorName = "CesiumWriterAdaptor";
                if (sampleOverload != null)
                    adaptorName = "CesiumInterpolatableWriterAdaptor";

                writer.WriteLine("private {0}<{1}> Create{2}Adaptor()",
                                 interfaceName,
                                 overloads[0].Parameters[0].Type,
                                 property.NameWithPascalCase);
                writer.OpenScope();
                writer.WriteLine("return new {0}<{1}CesiumWriter, {2}>(",
                                 adaptorName,
                                 schema.NameWithPascalCase,
                                 overloads[0].Parameters[0].Type);
                if (sampleOverload != null)
                {
                    writer.WriteLine("    this, (me, value) => me.Write{0}(value), ({1}CesiumWriter me, IList<JulianDate> dates, IList<{2}> values, int startIndex, int length) => me.Write{0}(dates, values, startIndex, length));",
                                     property.NameWithPascalCase,
                                     schema.NameWithPascalCase,
                                     overloads[0].Parameters[0].Type);
                }
                else
                {
                    writer.WriteLine("    this, (me, value) => me.Write{0}(value));",
                                     property.NameWithPascalCase);
                }
                writer.CloseScope();
                writer.WriteLine();
            }
        }
コード例 #10
0
        private void WriteConstructorsAndCloneMethod(CodeWriter writer, Schema schema)
        {
            WriteSummaryText(writer, "Initializes a new instance.");
            writer.WriteLine("public {0}CesiumWriter(string propertyName)", schema.NameWithPascalCase);
            writer.WriteLine("    : base(propertyName)");
            writer.OpenScope();
            WriteAsTypeLazyInitialization(writer, schema);
            writer.CloseScope();
            writer.WriteLine();

            WriteSummaryText(writer, "Initializes a new instance as a copy of an existing instance.");
            writer.WriteLine("/// <param name=\"existingInstance\">The existing instance to copy.</param> ");
            writer.WriteLine("protected {0}CesiumWriter({0}CesiumWriter existingInstance)", schema.NameWithPascalCase);
            writer.WriteLine("    : base(existingInstance)");
            writer.OpenScope();
            WriteAsTypeLazyInitialization(writer, schema);
            writer.CloseScope();
            writer.WriteLine();

            writer.WriteLine("/// <inheritdoc />");
            writer.WriteLine("public override {0}CesiumWriter Clone()", schema.NameWithPascalCase);
            writer.OpenScope();
            writer.WriteLine("return new {0}CesiumWriter(this);", schema.NameWithPascalCase);
            writer.CloseScope();
            writer.WriteLine();
        }
コード例 #11
0
        private void WriteLeafProperty(CodeWriter writer, Schema schema, Property property, bool isFirstValueProperty)
        {
            OverloadInfo[] overloads = GetOverloadsForProperty(property);

            foreach (OverloadInfo overload in overloads)
            {
                WriteSummaryText(writer, string.Format("Writes the <code>{0}</code> property.  The <code>{0}</code> property specifies {1}", property.Name, StringHelper.UncapitalizeFirstLetter(property.Description)));
                foreach (ParameterInfo parameter in overload.Parameters)
                {
                    if (string.IsNullOrEmpty(parameter.Description))
                        continue;
                    WriteParameterText(writer, parameter.Name, parameter.Description);
                }

                writer.WriteLine("public void Write{0}({1})", property.NameWithPascalCase, overload.FormattedParameters);
                writer.OpenScope();
                if (overload.CallOverload != null)
                {
                    writer.WriteLine("Write{0}({1});", property.NameWithPascalCase, overload.CallOverload);
                }
                else
                {
                    writer.WriteLine("const string PropertyName = {0}PropertyName;", property.NameWithPascalCase);

                    if (schema.Name == "Packet")
                    {
                        writer.WriteLine("Output.WritePropertyName(PropertyName);");
                    }
                    else if (isFirstValueProperty && !overload.NeedsInterval)
                    {
                        // For the first value property only, if an overload is marked 
                        // as not needing an interval, because it writes a simple JSON 
                        // type (string, number, boolean), we can skip opening an interval 
                        // and just write the property value directly.
                        writer.WriteLine("if (IsInterval)");
                        writer.WriteLine("    Output.WritePropertyName(PropertyName);");
                    }
                    else
                    {
                        writer.WriteLine("OpenIntervalIfNecessary();");

                        if (overload.WritePropertyName)
                            writer.WriteLine("Output.WritePropertyName(PropertyName);");
                    }

                    writer.WriteLine(overload.WriteValue);
                }
                writer.CloseScope();
                writer.WriteLine();
            }
        }
コード例 #12
0
        private void WriteIntervalsProperty(CodeWriter writer, Schema schema, Property property)
        {
            GenerateWriterClass(property.ValueType);

            WriteSummaryText(writer, string.Format("Gets the writer for the <code>{0}</code> property.  The returned instance must be opened by calling the <see cref=\"CesiumElementWriter.Open\"/> method before it can be used for writing.  The <code>{0}</code> property defines {1}",
                                                   property.Name, StringHelper.UncapitalizeFirstLetter(property.Description)));
            writer.WriteLine("public {0}CesiumWriter {1}Writer", property.ValueType.NameWithPascalCase, property.NameWithPascalCase);
            writer.OpenScope();
            writer.WriteLine("get {{ return m_{0}.Value; }}", property.Name);
            writer.CloseScope();
            writer.WriteLine();

            WriteSummaryText(writer, string.Format("Opens and returns the writer for the <code>{0}</code> property.  The <code>{0}</code> property defines {1}",
                                                   property.Name, StringHelper.UncapitalizeFirstLetter(property.Description)));
            writer.WriteLine("public {0}CesiumWriter Open{1}Property()", property.ValueType.NameWithPascalCase, property.NameWithPascalCase);
            writer.OpenScope();
            if (schema.Name != "Packet")
                writer.WriteLine("OpenIntervalIfNecessary();");
            writer.WriteLine("return OpenAndReturn({0}Writer);", property.NameWithPascalCase);
            writer.CloseScope();
            writer.WriteLine();

            if (property.ValueType.Properties != null)
            {
                bool isFirstValueProperty = true;
                foreach (Property nestedProperty in property.ValueType.Properties)
                {
                    if (!nestedProperty.IsValue)
                        continue;

                    OverloadInfo[] overloads = GetOverloadsForProperty(nestedProperty);

                    foreach (OverloadInfo overload in overloads)
                    {
                        WriteSummaryText(writer, string.Format("Writes a value for the <code>{0}</code> property as a <code>{1}</code> value.  The <code>{0}</code> property specifies {2}", property.Name, nestedProperty.Name, StringHelper.UncapitalizeFirstLetter(property.Description)));
                        foreach (ParameterInfo parameter in overload.Parameters)
                        {
                            if (string.IsNullOrEmpty(parameter.Description))
                                continue;
                            WriteParameterText(writer, parameter.Name, parameter.Description);
                        }

                        string subPropertyName = nestedProperty.NameWithPascalCase;
                        if (subPropertyName == property.NameWithPascalCase || isFirstValueProperty)
                            subPropertyName = "";

                        writer.WriteLine("public void Write{0}Property{1}({2})", property.NameWithPascalCase, subPropertyName, overload.FormattedParameters);
                        writer.OpenScope();

                        writer.WriteLine("using (var writer = Open{0}Property())", property.NameWithPascalCase);
                        writer.OpenScope();
                        writer.WriteLine("writer.Write{0}({1});", nestedProperty.NameWithPascalCase, string.Join(", ", Array.ConvertAll(overload.Parameters, p => p.Name)));
                        writer.CloseScope();

                        writer.CloseScope();
                        writer.WriteLine();
                    }

                    isFirstValueProperty = false;
                }
            }
        }
コード例 #13
0
ファイル: CSharpGenerator.cs プロジェクト: kcj/czml-writer
        private void WriteAsTypeMethods(CodeWriter writer, Schema schema)
        {
            if (schema.Properties == null)
            {
                return;
            }

            foreach (Property property in schema.Properties)
            {
                if (!property.IsValue)
                {
                    continue;
                }
                if (PropertyValueIsIntervals(property))
                {
                    continue;
                }

                OverloadInfo[] overloads = GetOverloadsForProperty(property);

                if (overloads[0].Parameters.Length != 1)
                {
                    continue;
                }

                OverloadInfo sampleOverload = FindSampledDataOverload(overloads);

                string interfaceName = "ICesiumValuePropertyWriter";
                if (sampleOverload != null)
                {
                    interfaceName = "ICesiumInterpolatableValuePropertyWriter";
                }

                WriteSummaryText(writer, string.Format("Returns a wrapper for this instance that implements <see cref=\"{0}{{T}}\" /> to write a value in <code>{1}</code> format.  Because the returned instance is a wrapper for this instance, you may call <see cref=\"ICesiumElementWriter.Close\" /> on either this instance or the wrapper, but you must not call it on both.", interfaceName, property.NameWithPascalCase));
                WriteReturnsText(writer, "The wrapper.");
                writer.WriteLine("public {0}<{1}> As{2}()",
                                 interfaceName,
                                 overloads[0].Parameters[0].Type,
                                 property.NameWithPascalCase);
                writer.OpenScope();
                writer.WriteLine("return m_as{0}.Value;", property.NameWithPascalCase);
                writer.CloseScope();
                writer.WriteLine();

                string adaptorName = "CesiumWriterAdaptor";
                if (sampleOverload != null)
                {
                    adaptorName = "CesiumInterpolatableWriterAdaptor";
                }

                writer.WriteLine("private {0}<{1}> Create{2}Adaptor()",
                                 interfaceName,
                                 overloads[0].Parameters[0].Type,
                                 property.NameWithPascalCase);
                writer.OpenScope();
                writer.WriteLine("return new {0}<{1}CesiumWriter, {2}>(",
                                 adaptorName,
                                 schema.NameWithPascalCase,
                                 overloads[0].Parameters[0].Type);
                if (sampleOverload != null)
                {
                    writer.WriteLine("    this, (me, value) => me.Write{0}(value), ({1}CesiumWriter me, IList<JulianDate> dates, IList<{2}> values, int startIndex, int length) => me.Write{0}(dates, values, startIndex, length));",
                                     property.NameWithPascalCase,
                                     schema.NameWithPascalCase,
                                     overloads[0].Parameters[0].Type);
                }
                else
                {
                    writer.WriteLine("    this, (me, value) => me.Write{0}(value));",
                                     property.NameWithPascalCase);
                }
                writer.CloseScope();
                writer.WriteLine();
            }
        }
コード例 #14
0
ファイル: CSharpGenerator.cs プロジェクト: kcj/czml-writer
        private void WriteIntervalsProperty(CodeWriter writer, Schema schema, Property property)
        {
            GenerateWriterClass(property.ValueType);

            WriteSummaryText(writer, string.Format("Gets the writer for the <code>{0}</code> property.  The returned instance must be opened by calling the <see cref=\"CesiumElementWriter.Open\"/> method before it can be used for writing.  The <code>{0}</code> property defines {1}",
                                                   property.Name, StringHelper.UncapitalizeFirstLetter(property.Description)));
            writer.WriteLine("public {0}CesiumWriter {1}Writer", property.ValueType.NameWithPascalCase, property.NameWithPascalCase);
            writer.OpenScope();
            writer.WriteLine("get {{ return m_{0}.Value; }}", property.Name);
            writer.CloseScope();
            writer.WriteLine();

            WriteSummaryText(writer, string.Format("Opens and returns the writer for the <code>{0}</code> property.  The <code>{0}</code> property defines {1}",
                                                   property.Name, StringHelper.UncapitalizeFirstLetter(property.Description)));
            writer.WriteLine("public {0}CesiumWriter Open{1}Property()", property.ValueType.NameWithPascalCase, property.NameWithPascalCase);
            writer.OpenScope();
            if (schema.Name != "Packet")
            {
                writer.WriteLine("OpenIntervalIfNecessary();");
            }
            writer.WriteLine("return OpenAndReturn({0}Writer);", property.NameWithPascalCase);
            writer.CloseScope();
            writer.WriteLine();

            if (property.ValueType.Properties != null)
            {
                bool isFirstValueProperty = true;
                foreach (Property nestedProperty in property.ValueType.Properties)
                {
                    if (!nestedProperty.IsValue)
                    {
                        continue;
                    }

                    OverloadInfo[] overloads = GetOverloadsForProperty(nestedProperty);

                    foreach (OverloadInfo overload in overloads)
                    {
                        WriteSummaryText(writer, string.Format("Writes a value for the <code>{0}</code> property as a <code>{1}</code> value.  The <code>{0}</code> property specifies {2}", property.Name, nestedProperty.Name, StringHelper.UncapitalizeFirstLetter(property.Description)));
                        foreach (ParameterInfo parameter in overload.Parameters)
                        {
                            if (string.IsNullOrEmpty(parameter.Description))
                            {
                                continue;
                            }
                            WriteParameterText(writer, parameter.Name, parameter.Description);
                        }

                        string subPropertyName = nestedProperty.NameWithPascalCase;
                        if (subPropertyName == property.NameWithPascalCase || isFirstValueProperty)
                        {
                            subPropertyName = "";
                        }

                        writer.WriteLine("public void Write{0}Property{1}({2})", property.NameWithPascalCase, subPropertyName, overload.FormattedParameters);
                        writer.OpenScope();

                        writer.WriteLine("using (var writer = Open{0}Property())", property.NameWithPascalCase);
                        writer.OpenScope();
                        writer.WriteLine("writer.Write{0}({1});", nestedProperty.NameWithPascalCase, string.Join(", ", Array.ConvertAll(overload.Parameters, p => p.Name)));
                        writer.CloseScope();

                        writer.CloseScope();
                        writer.WriteLine();
                    }

                    isFirstValueProperty = false;
                }
            }
        }
コード例 #15
0
 public void Dispose()
 {
     m_codeWriter.CloseScope();
 }
コード例 #16
0
        private void WriteLeafProperty(CodeWriter writer, Schema schema, Property property, bool isFirstValueProperty)
        {
            OverloadInfo[] overloads = GetOverloadsForProperty(property);

            foreach (OverloadInfo overload in overloads)
            {
                WriteSummaryText(writer, string.Format("Writes the <code>{0}</code> property.  The <code>{0}</code> property specifies {1}", property.Name, StringHelper.UncapitalizeFirstLetter(property.Description)));
                foreach (ParameterInfo parameter in overload.Parameters)
                {
                    if (string.IsNullOrEmpty(parameter.Description))
                        continue;
                    WriteParameterText(writer, parameter.Name, parameter.Description);
                }
                writer.WriteLine("public void Write{0}({1})", isFirstValueProperty ? "Value" : property.NameWithPascalCase, overload.FormattedParameters);
                writer.OpenScope();
                if (overload.CallOverload != null)
                {
                    writer.WriteLine("Write{0}({1});", isFirstValueProperty ? "Value" : property.NameWithPascalCase, overload.CallOverload);
                }
                else
                {
                    // First the first value property only, if an overload has one parameter and that
                    // parameter is a simple JSON type (string, number, boolean), we can skip opening an
                    // interval and just write the property value directly.
                    if (isFirstValueProperty && overload.Parameters.Length == 1 &&
                        (overload.Parameters[0].Type == "string" || overload.Parameters[0].Type == "double" ||
                         overload.Parameters[0].Type == "int" || overload.Parameters[0].Type == "bool"))
                    {
                        writer.WriteLine("if (IsInterval)");
                        writer.WriteLine("    Output.WritePropertyName({0}PropertyName);", property.NameWithPascalCase);
                    }
                    else
                    {
                        writer.WriteLine("OpenIntervalIfNecessary();");
                        writer.WriteLine("Output.WritePropertyName({0}PropertyName);", property.NameWithPascalCase);
                    }
                    writer.WriteLine(overload.WriteValue);
                }
                writer.CloseScope();
                writer.WriteLine();
            }
        }