Beispiel #1
0
        public static void Main(string[] args)
        {
            Directory.CreateDirectory(TargetDirectory);

            var scripter = new Scripter()
                           .UsingFormatter(new TsFormatter
            {
                EnumsAsString = true
            });

            scripter
            .WithTypeMapping(TsPrimitive.String, typeof(Guid))
            .WithTypeMapping(TsPrimitive.String, typeof(TimeSpan))
            .WithTypeMapping(new TsInterface(new TsName("Array")), typeof(HashSet <>))
            .WithTypeMapping(new TsInterface(new TsName("Array")), typeof(List <>))
            .WithTypeMapping(TsPrimitive.Any, typeof(RavenJObject))
            .WithTypeMapping(TsPrimitive.Any, typeof(RavenJValue))
            .WithTypeMapping(TsPrimitive.Any, typeof(TreePage))
            .WithTypeMapping(TsPrimitive.String, typeof(DateTime))
            .WithTypeMapping(new TsArray(TsPrimitive.Any, 1), typeof(RavenJArray))
            .WithTypeMapping(TsPrimitive.Any, typeof(RavenJToken))
            .WithTypeMapping(TsPrimitive.Any, typeof(BlittableJsonReaderObject));

            scripter = ConfigureTypes(scripter);
            Directory.Delete(TargetDirectory, true);
            Directory.CreateDirectory(TargetDirectory);
            scripter
            .SaveToDirectory(TargetDirectory);
        }
        public static void Open()
        {
            Compilation compilation;
            var         msWorkspace = MSBuildWorkspace.Create();

            msWorkspace.WorkspaceFailed += (object sender, WorkspaceDiagnosticEventArgs e) =>
            {
                Debug.WriteLine(e.Diagnostic.ToString());
            };
            string solutionPath = @"C:\Users\u045992\source\Projects\TestedLibrary\TestedLibrary.sln";

            try
            {
                var solution = msWorkspace.OpenSolutionAsync(solutionPath).Result;


                var proj = solution.Projects.Single(p => p.Name == "TargetLibrary");


                compilation = proj.GetCompilationAsync().Result;

                //CreateMetaDataTypescript();
                var typeByMetadataName = compilation.GetTypeByMetadataName(typeof(Guid).FullName);

                Scripter scripter = new Scripter(compilation);
                scripter.TypeFilter = t => t.Name != "IExtensibleDataObject" && t.Name != "ClientBase";
                scripter.WithTypeMapping(new TsExternalReference(nameof(DayOfWeek), "TypeScriptModels.ts"),
                                         typeof(DayOfWeek));
                GetAllSymbolsVisitor visitor = new GetAllSymbolsVisitor(scripter);
                visitor.Visit(compilation.Assembly.GlobalNamespace);
                scripter.SaveToDirectory(@"c:\temp\TypeScriptOutput");
            }
            catch (Exception)
            {
            }
        }