public IEnumerable <EventArgumentModel> GetExpandedArgument(EventArgumentModel argument, bool directArgumentAssignments = true) { if (argument.TypeTemplate != null) { foreach (var templateArgument in argument.TypeTemplate.Arguments) { var memberName = (argument.IsImplicit && !directArgumentAssignments) ? $"_{argument.Name}" : argument.Name; var assignment = templateArgument.Assignment?.Replace(@"$this", memberName); yield return(new EventArgumentModel( name: templateArgument.Name, type: templateArgument.Type, assignment: assignment) { TemplatedParentArgument = argument, CLRType = templateArgument.CLRType, IsImplicit = argument.IsImplicit, AssignedCLRType = templateArgument.Type, }); } } else { yield return(argument); } }
public void Append(EventArgumentModel argument) { var renderedArgument = _renderer(argument); Builder.Append($"{CurrentDelimiter}{renderedArgument}"); CurrentDelimiter = Delimiter; }
private static TypeTemplateModel CacheAndReturn(EventArgumentModel argument, TypeTemplateModel typeTemplateModel) { var cacheKey = GetCacheKey(argument); TypeTemplates[cacheKey] = typeTemplateModel; return(typeTemplateModel); }
public bool IsTemplateFor(EventArgumentModel argument) { var templateTypeName = GetTypeTemplateModel().Name; var templateTypeCLR = GetTypeTemplateModel().CLRType; var argumentTypeName = argument.Type ?? argument.CLRType; var argumentTypeCLR = argument.CLRType ?? argument.Type; if (templateTypeName.Equals(argumentTypeName, StringComparison.InvariantCultureIgnoreCase) || templateTypeCLR.Equals(argumentTypeCLR, StringComparison.InvariantCultureIgnoreCase)) { return(true); } return(false); }
public bool IsInheritedTemplateFor(EventArgumentModel argument) { var templateTypeCLR = GetTypeTemplateModel().CLRType ?? GetTypeTemplateModel().Name; var argumentTypeCLR = argument.CLRType ?? argument.Type; try { var argumentType = Type.GetType(argumentTypeCLR); var templateType = Type.GetType(templateTypeCLR); if (templateType?.IsAssignableFrom(argumentType) ?? false) { return(true); } } catch (Exception ex) { LogMessage($"Extension '{this.GetType().Name}' Failed to get type {argument.CLRType} - {ex.Message}"); } return(false); }
private static string GetCacheKey(EventArgumentModel argument) { var cacheKey = $"{argument.Type}/{argument.CLRType}"; return(cacheKey); }
public static TypeTemplateModel GetTypeTemplate(this BaseWithLogging caller, Project project, IEnumerable <TypeTemplateModel> templates, EventArgumentModel argument) { var cacheKey = GetCacheKey(argument); if (TypeTemplates.ContainsKey(cacheKey)) { return(TypeTemplates[cacheKey]); } var directTypeTemplate = templates.FirstOrDefault(t => t.Name.Equals(argument.Type, StringComparison.InvariantCultureIgnoreCase) || t.CLRType.Equals(argument.Type, StringComparison.InvariantCultureIgnoreCase)); if (directTypeTemplate != null) { return(CacheAndReturn(argument, directTypeTemplate)); } var typeTemplateExtensions = project.GetExtensions <ITypeTemplateDefinition>().ToArray(); foreach (var typeTemplateExtension in typeTemplateExtensions) { caller.PassAlongLoggers(typeTemplateExtension as IWithLogging); if (typeTemplateExtension.IsTemplateFor(argument)) { return(CacheAndReturn(argument, typeTemplateExtension.GetTypeTemplateModel())); } } foreach (var typeTemplateExtension in typeTemplateExtensions) { caller.PassAlongLoggers(typeTemplateExtension as IWithLogging); if (typeTemplateExtension.IsInheritedTemplateFor(argument)) { return(CacheAndReturn(argument, typeTemplateExtension.GetTypeTemplateModel())); } } return(null); }
public static TypeTemplateModel GetTypeTemplate(this IEnumerable <TypeTemplateModel> templates, EventArgumentModel argument) { return(templates.FirstOrDefault(t => t.Name.Equals(argument.Type, StringComparison.InvariantCultureIgnoreCase) || t.CLRType.Equals(argument.Type, StringComparison.InvariantCultureIgnoreCase))); }