Ejemplo n.º 1
0
        private void RenderModule(TypeScriptModule module)
        {
            if (_processedModules.Contains(module.Module))
              {
            return;
              }

              _processedModules.Add(module.Module);

              var moduleBuffer = new IndentedStringBuilder(module.ModuleMembers.Count * 256, _options.CodeGenerationOptions.IndentationCharacter, _options.CodeGenerationOptions.IndentationIncrementAmount);

              moduleBuffer.AppendLine("{1}module {0} {{", module.Module, _options.CodeGenerationOptions.GenerateExternalModules ? "export " : "");
              moduleBuffer.IncreaseIndentation();
              moduleBuffer.AppendLine("");

              foreach (var type in module.ModuleMembers)
              {
            Render(moduleBuffer, (dynamic)type);
              }

              moduleBuffer.DecreaseIndentation();
              moduleBuffer.AppendLine("}}");
              moduleBuffer.AppendLine("");

              _sb.AppendLine(moduleBuffer.ToString());
        }
Ejemplo n.º 2
0
        private void Render(IndentedStringBuilder sb, CustomType type)
        {
            if (_processedTypes.Contains(type.ClrType))
              {
            return;
              }

              _processedTypes.Add(type.ClrType.IsGenericType ? type.ClrType.GetGenericTypeDefinition() : type.ClrType);

              ProcessBaseType(sb, type);

              var interfaceType = type as InterfaceType;

              sb.AppendLine("export {2} {0}{1} {3}{{", _typeNameGenerator.GetTypeName(type), RenderBaseType(type), interfaceType == null ? "class" : "interface", RenderInterfaces(type));
              sb.IncreaseIndentation();

              foreach (var p in type.Properties)
              {
            Render(sb, p);
              }

              if (_options.CodeGenerationOptions.AdditionalMembers != null)
              {
            foreach (var member in _options.CodeGenerationOptions.AdditionalMembers(type.ClrType))
            {
              sb.AppendLine(member);
            }
              }

              sb.DecreaseIndentation();
              sb.AppendLine("}}");
              sb.AppendLine("");
        }
Ejemplo n.º 3
0
        private void Render(IndentedStringBuilder sb, EnumType type)
        {
            sb.AppendLine("export enum {0} {{", type.ClrType.Name);
              sb.IncreaseIndentation();

              var values = Enum.GetValues(type.ClrType);
              var names = Enum.GetNames(type.ClrType);

              int i = 0;

              foreach (var val in values)
              {
            var name = names[i];
            i++;

            sb.AppendLine("{0} = {1},", name, Convert.ChangeType(val, typeof(int)));
              }

              sb.DecreaseIndentation();
              sb.AppendLine("}}");
              sb.AppendLine("");
        }