0

I'm trying to write a console application which uses the System.Type declaration of multiple files using .net core 1.1 framework.

My use case is that I start the application and set the cs file paths as parameter.

sampleApp.exe d:\downloads\SomeClassA.cs e:\sample\IExSample.cs

Then I want to use the types of the cs files in my application. Somehow like:

public static void Main(string[] args) {

    var types = new List<System.Type>();

    foreach (var arg in args) {

        // Here I need some help ;-)
        System.Type typeOfArg = ?;

        types.Add(typeOfArg);
    }

   // do more magic with filled type list
}
tobias-kutter
  • 269
  • 2
  • 10
  • Do you just want the type info, or do you want it compiled? Anyway look into Roslyn, see also http://stackoverflow.com/questions/37526165/compiling-and-running-code-at-runtime-in-net-core-1-0. – CodeCaster Jan 31 '17 at 09:09
  • I just want the type info and thanks @CodeCaster, I'll take a look – tobias-kutter Jan 31 '17 at 09:12
  • What do you want to do with the `Type` after you have gotten it from the file? Roslyn doesn't provide a method of getting a `Type` but if you simply want to get type information based on the classes/interfaces within the files then this would be possible using Roslyn. – Stephen Ross Jan 31 '17 at 10:20
  • I want to write a customized console-based TypeScript translator using the pankleks/TypeScriptBuilder framework and restructure the generated content. Due the framework needs `Type` as parameter I need a way to provide/generate this information. – tobias-kutter Jan 31 '17 at 11:10

1 Answers1

1

You won't be able to pass in the *.cs file and determine the type. You can gather metadata (type of classes, interfaces, base types, etc) using Roslyn. Here's a link that can help you. https://msdn.microsoft.com/en-us/magazine/mt790203.aspx

It uses T4 for templating to generate the javascipt code. You can use T4 in your project if you want to. But the underlying provider of metadata is done via Roslyn. Just extract the portion of the code that you are interested.

alltej
  • 6,787
  • 10
  • 46
  • 87