frhagn / Typewriter

Automatic TypeScript template generation from C# source files
http://frhagn.github.io/Typewriter
Apache License 2.0
537 stars 132 forks source link

generate import for custom type from another file #312

Closed daniellaillouz closed 5 years ago

daniellaillouz commented 5 years ago

in my c# code there is variable type of another class that declared in another file.

I have to generate import statement to those classes also have multiple classes in the same file.

I tried to do this:

string Imports(Class c, File f)
{
    IEnumerable<String> classes = f.Classes.Select(p=> p.name);

    IEnumerable<Type> types = c.Properties
        .Select(p => p.Type)
        .Where(t =>((!t.IsPrimitive  || t.IsEnum) && !classes.Contains(t.name)))
        .Select(t => t.IsGeneric ? t.TypeArguments.First() : t)
        .Where(t => t.Name != c.Name && t.Name != "DbGeography")
        .Distinct();
    return string.Join(Environment.NewLine, types.Select(t => $"import {{ {t.Name} }} from './misc';").Distinct());
}

$Classes(*DTO)[
$Imports

export interface $Name {
    $Properties[
    // $LoudName
    $name: $Type;]
}]

but its not working, any idea?