private void WriteNamespaceHandler(StreamWriter writer, TypeScriptType type)
 {
     writer.WriteLine();
     writer.WriteLine(Tab(1) + "// default namespace");
     writer.WriteLine(Tab(1) + "@XMLAttribute({name: \"xmlns\"})");
     writer.WriteLine(Tab(1) + "public defaultXmlNamespace?: string;");
     writer.WriteLine();
     writer.WriteLine(Tab(1) + "public enableDefaultXmlNamespace(): void {");
     writer.WriteLine(Tab(2) + "this.defaultXmlNamespace = \"{0}\";", this.XmlNamespace);
     writer.WriteLine(Tab(1) + "}");
     writer.WriteLine();
     writer.WriteLine(Tab(1) + "public disableDefaultXmlNamespace(): void {");
     writer.WriteLine(Tab(2) + "this.defaultXmlNamespace = undefined;");
     writer.WriteLine(Tab(1) + "}");
 }
        private void WriteType(StreamWriter writer, TypeScriptType type)
        {
            if (!string.IsNullOrEmpty(type.Comment))
            {
                WriteTypeComment(writer, type.Comment);
            }

            if (type.Array != null)
            {
                WriteArrayTypeHeader(writer, type);
            }
            else if (type.Enum != null)
            {
                WriteEnumTypeHeader(writer, type);

                if (type.Enum.EnumValues != null)
                {
                    for (int i = 0; i < type.Enum.EnumValues.Count; i++)
                    {
                        bool last       = i == type.Enum.EnumValues.Count - 1;
                        var  enumMember = type.Enum.EnumValues[i];
                        WriteEnumMember(writer, enumMember, last);
                    }
                }
            }
            else
            {
                WriteTypeHeader(writer, type);

                if (type.Properties != null)
                {
                    for (int i = 0; i < type.Properties.Count; i++)
                    {
                        var property = type.Properties[i];
                        WriteProperty(writer, property, i);
                    }
                }
                if (type.IsRootType)
                {
                    WriteNamespaceHandler(writer, type);
                }
            }

            WriteTypeFooter(writer);
        }
Exemple #3
0
 private void WriteEnumTypeHeader(StreamWriter writer, TypeScriptType type)
 {
     writer.WriteLine("export enum {0} {{", type.Name);
 }
Exemple #4
0
 private void WriteArrayTypeHeader(StreamWriter writer, TypeScriptType type)
 {
     writer.WriteLine("export class {0} extends Array<{1}> {{", type.Name, type.Array.ItemsTypeName);
 }
 private void WriteTypeHeader(StreamWriter writer, TypeScriptType type)
 {
     writer.WriteLine("@XMLElement({{root: \"{0}\"}})", System.Char.ToLowerInvariant(type.Name[0]) + type.Name.Substring(1));
     writer.WriteLine("export class {0} {{", type.Name);
 }