Generating files for all Enums including referenced projects?
Closed this issue · 4 comments
Hi!
I might got that wrong, but I think there is a problem finding Enums using the $Enums variable when using no filtering or filtering for many files::
This will result in no files:
${
using Typewriter.Extensions.Types;
Template(Settings settings)
{
settings.IncludeCurrentProject();
settings.IncludeReferencedProjects();
settings.OutputFilenameFactory = file =>
{
string n = file.Enums.First().Namespace;
return $"../../{n.Replace(".","")}/{file.Name.Replace(".cs", ".ts").Trim('/')}";
};
}
static List<string> acceptedNamespaced = new List<string>() {
"NS1",
"NS2",
"NS3"
};
}
$Enums[
export enum $Name {
$Values[
/** $DocComment **/
$Name = $Value][,]
}
]
Adding a filter via .Contains doesnt change aynthing:
....
$Enums(x => acceptedNamespaced.Contains(x.Namespace))[
export enum $Name {
$Values[
/** $DocComment **/
$Name = $Value][,]
}
]
However: When I duplocate the code and filter by only one namspace it works...
...
$Enums(x => x.Namespace.StartsWith("NS1"))[
export enum $Name {
$Values[
/** $DocComment **/
$Name = $Value][,]
}
]
My goal is to generate for given namespaces. Am I doing something wrong here or is this a bug?
- Malte
hi I will check and get back to you
Could you please instead do something like this
${
using Typewriter.Extensions.Types;
Template(Settings settings)
{
settings.IncludeCurrentProject();
settings.IncludeReferencedProjects();
settings.OutputFilenameFactory = file =>
{
string n = file.Enums.First().Namespace;
return $"../../{n.Replace(".","")}/{file.Name.Replace(".cs", ".ts").Trim('/')}";
};
}
static HashSet<string> acceptedNamespaced = new HashSet<string>(
new List<string>{
"NS1",
"NS2",
"NS3"
});
bool IncludeEnums(Enum e){
return acceptedNamespaced.Contains(e.Namespace);
}
}
$Enums($IncludeEnums)[
export enum $Name {
$Values[
/** $DocComment **/
$Name = $Value][,]
}
]
also please take a look at sample https://github.com/AdaskoTheBeAsT/NetCoreTypewriterRecipes/blob/master/src/AngularWebApiSample2/ClientApp/apps/client-app/src/api/models/_AutogeneratedModels.tst
Thanks that worked for me. :-) Is it possible to let typewriter render into one single file? I saw a issue from 5 years ago at the main repo but it never got closed. If not I could try to make a PR for that if thats ok
cool that it is solved
I din't thought about implementing Typewriter render in one single file - if you want you can make PR - please put that option in settings - default should be as it is right now - separate files