private Task <RichGenerationResult> GenerateAsync(TypeDeclarationSyntax typeDeclaration, TransformationContext context, AttributeData attributeData) { if (!(context.ProcessingNode.Parent is NamespaceDeclarationSyntax namespaceDeclarationSyntax)) { throw new Exception($"Failed to determine namespace for type:'{context.ProcessingNode.Parent}'."); } #if DEBUG var attachDebuggerOnNode = attributeData.GetNamedArgumentValueOrDefault <bool>(nameof(ImplementInterfaceAttribute.AttachDebuggerOnNode)); if (attachDebuggerOnNode) { Debugger.Launch(); } #endif var descriptor = GetImplementationDescriptor(typeDeclaration, context, attributeData); var implementationMemberDeclaration = GetImplementation(descriptor); var @namespace = NamespaceDeclaration(namespaceDeclarationSyntax.Name) .AddMembers(implementationMemberDeclaration); var generatedMembers = new List <MemberDeclarationSyntax> { @namespace }; var result = new RichGenerationResult { Members = new SyntaxList <MemberDeclarationSyntax>(generatedMembers) }; return(Task.FromResult(result)); }
public static MetricsCollectorDescriptor ToMetricsCollectorDescriptor( this TypeDeclarationSyntax typeDeclarationSyntax, TransformationContext context, AttributeData attributeData) { var className = typeDeclarationSyntax.GetClassNameFromInterfaceDeclaration(false); var methodDeclarations = typeDeclarationSyntax.GetAllMethodDeclarations(context); var inheritedInterfaceTypes = attributeData.GetInheritedInterfaceTypes(); var metricsCollectorMethods = methodDeclarations.GetMetricsCollectorMethods(context); var contextName = attributeData.GetNamedArgumentValueOrDefault(nameof(GenerateMetricsCollectorAttribute.ContextName), className); return(new MetricsCollectorDescriptor(typeDeclarationSyntax, contextName, className, inheritedInterfaceTypes, metricsCollectorMethods)); }