Пример #1
0
        private static void Main(string[] args)
        {
            var context = new GeneratorContext()
            {
                NameFormatter = type => type.IsEnum ? type.Name : "I" + type.Name,
                TightOptional = false,
                ModelsPath    = "./models",
            };
            var genModels  = new BackendModelsGenerator(context);
            var genBackend = new BackendGenerator(context)
            {
                Header =
                {
                    "import { call } from 'redux-saga/effects';",
                    "import { apiCall } from './api';",
                },
            };

            // context.ReferencedTypes.Add(typeof());

            var backend = genBackend.Generate(Assembly.GetExecutingAssembly());

            File.WriteAllText("backend.ts", backend);
            Console.WriteLine(backend);

            var models = genModels.Generate();

            File.WriteAllText("models.ts", models);
            Console.WriteLine(models);
        }
Пример #2
0
        public void Backend()
        {
            _ctxBackend.ReferencedTypes.Clear();
            var gen    = new BackendGenerator(_ctxBackend);
            var result = gen.Generate(Assembly.GetExecutingAssembly());

            result = result.Replace("\n", "").Trim();
            Assert.IsTrue(result.Contains("import {TClass,TOther,} from \"./models\";"));
            Assert.IsTrue(result.Contains("Post(arg: TOther) {return (yield call(apiCall, `/Test/Post`, {anonymous: true,body: arg,method: \"POST\",})) as TClass;}"));
            Assert.IsTrue(result.Contains("Get(arg: string, opt: number) {return (yield call(apiCall, `/Test/Get/${arg}/${opt}`, {anonymous: true,})) as TClass;}"));
            Assert.IsTrue(result.Contains("export let Backend = {Test: "));
        }