diff --git a/TopModel.Generator.Core/TemplateExtensions.cs b/TopModel.Generator.Core/TemplateExtensions.cs index 550e6c05..0513dd01 100644 --- a/TopModel.Generator.Core/TemplateExtensions.cs +++ b/TopModel.Generator.Core/TemplateExtensions.cs @@ -136,6 +136,22 @@ private static IEnumerable ExtractVariables(this string input) return regex.Matches(input).Cast(); } + private static string ResolveVariable(this string input, Domain domain, GeneratorConfigBase config, string? tag = null) + { + var transform = input.GetTransformation(); + var variable = input.Split(':').First(); + + return input.Split(':').First() switch + { + "mediaType" => transform(domain.MediaType ?? string.Empty), + "length" => transform(domain.Length?.ToString() ?? string.Empty), + "scale" => transform(domain.Scale?.ToString() ?? string.Empty), + "name" => transform(domain.Name ?? string.Empty), + "type" => transform(domain.Implementations.GetValueOrDefault(config.Language)?.Type ?? string.Empty), + var i => config.ResolveVariables(config.ResolveGlobalVariables($@"{{{i}}}").Trim('{', '}'), tag: tag) + }; + } + private static string ResolveVariable(this string input, IProperty c, string[] parameters, GeneratorConfigBase config, string? tag = null) { switch (c) @@ -376,22 +392,6 @@ private static string ResolveVariable(this string input, Endpoint e, string[] pa return result; } - private static string ResolveVariable(this string input, Domain domain, GeneratorConfigBase config, string? tag = null) - { - var transform = input.GetTransformation(); - var variable = input.Split(':').First(); - - return input.Split(':').First() switch - { - "mediaType" => transform(domain.MediaType ?? string.Empty), - "length" => transform(domain.Length?.ToString() ?? string.Empty), - "scale" => transform(domain.Scale?.ToString() ?? string.Empty), - "name" => transform(domain.Name ?? string.Empty), - "type" => transform(domain.Implementations.GetValueOrDefault(config.Language)?.Type ?? string.Empty), - var i => config.ResolveVariables(config.ResolveGlobalVariables($@"{{{i}}}").Trim('{', '}'), tag: tag) - }; - } - private static string ResolveVariable(this string input, Domain domainFrom, Domain domainTo, GeneratorConfigBase config, string? tag = null) { if (input.StartsWith("from."))