Closed colinwurtz closed 6 years ago
Hi @colinwurtz, Try something like this:
string Imports(Class c)
{
var props = c.Properties.Where(p => !p.Attributes.Any(a => String.Equals(a.name, "TypeScriptIgnore", StringComparison.OrdinalIgnoreCase)));
IEnumerable<Type> types = props
.Select(p => p.Type)
.SelectMany(t => t.IsGeneric ? t.TypeArguments : new[] { t } as IEnumerable<Type>)
.Where(t => !t.IsPrimitive || t.IsEnum)
.Where(t => !t.Attributes.Any(a => String.Equals(a.name, "TypeScriptIgnore", StringComparison.OrdinalIgnoreCase)))
.Distinct();
return string.Join(Environment.NewLine, types.Select(t => $"import {{ {t.Name} }} from './{t.Name}';").Distinct());
}
That worked... thank you!
First of all, thanks for the awesome work on this, Typewriter has saved me an immense amount of time and effort.
I used the technique outlined in #166 to generate imports for custom types, but am struggling to figure out how to generate my imports line for a
Dictionary<int,customtype>
scenario.My DTO/C# class is defined below. The Imports function in my .tst file is not picking up that it needs to import the
Status
type, similar to how it importedProjectDTO
.tst file
Produces this file:
Is there a way to get to the type of the dictionary's values within the .tst file?
Cross posted to stack overflow here: https://stackoverflow.com/questions/52322098/how-do-i-import-types-defined-in-a-c-sharp-dictionary