Пример #1
0
 public void TranslateController()
 {
     using (var sw = new StreamWriter(File.Create(tsFile))) {
         ITypeScriptTranslator translator = new TypeScriptPipelineTranslator(sw);
         translator.Translate(typeof(SampleController));
         sw.Flush();
     }
 }
        public string Translate(Type tp, TypeScriptPipelineTranslator translator)
        {
            if (tp.IsGenericType)
            {
                return(translator.Translate(tp.GetGenericArguments().First()));
            }

            return("any");
        }
        public string Translate(Type tp, TypeScriptPipelineTranslator translator)
        {
            if (!headerIncluded)
            {
                headerIncluded = true;
                translator.Writer.Write(new TypeScriptControllersFileHeaderTemplate().TransformText());
            }

            ApiService            svc      = new ApiService(tp);
            ApiControllerTemplate template = new ApiControllerTemplate();

            template.Service    = svc;
            template.Translator = translator;
            translator.Writer.Write(template.TransformText());
            return(tp.FullName);
        }
        public virtual string Translate(Type tp, TypeScriptPipelineTranslator translator)
        {
            String name;
            String fullName;
            Type   toTranslate;

            toTranslate = tp;

            if (tp.IsArray)
            {
                return(translator.Translate(tp.GetElementType()) + "[]");
            }

            if (tp == typeof(void))
            {
                return("void");
            }

            if (tp.IsGenericType)
            {
                name     = tp.Name.Split('`').First() + "<" + String.Join(", ", tp.GetGenericArguments().Select(x => translator.Translate(x))) + ">";
                fullName = tp.Namespace + "." + name;
                if (!tp.IsGenericTypeDefinition)
                {
                    translator.Translate(tp.GetGenericTypeDefinition());
                    return(fullName);
                }
            }
            else
            {
                name     = tp.Name;
                fullName = tp.FullName;
            }

            if (tp == typeof(Object))
            {
                return("any");
            }

            translator.RegisterType(tp.FullName, fullName);
            PropertiesOnlyTemplate templ = new PropertiesOnlyTemplate(name, toTranslate, translator, tp.Namespace.StartsWith("System"));

            translator.Writer.Write(templ.TransformText());
            return(fullName);
        }
 public string Translate(Type tp, TypeScriptPipelineTranslator translator)
 {
     return("any");
 }
 public void Prepare(TypeScriptPipelineTranslator translator)
 {
     translator.AddTailTranslator(this);
 }
        public string Translate(Type tp, TypeScriptPipelineTranslator translator)
        {
            String listType = translator.Translate(tp.GetGenericArguments().First());

            return("Array<" + listType + ">");
        }
Пример #8
0
        public string Translate(Type tp, TypeScriptPipelineTranslator translator)
        {
            String eleType = translator.Translate(tp.GetElementType());

            return(eleType + "[]");
        }
Пример #9
0
 public override string Translate(Type tp, TypeScriptPipelineTranslator translator)
 {
     return(base.Translate(typeof(IComparable), translator));
 }