public static ClientClassTemplate Create(SyntaxTree tree, GeneratorConfig config) { var syntaxRoot = tree.GetRoot(); var namespaceNode = syntaxRoot .DescendantNodes() .OfType <NamespaceDeclarationSyntax>() .Single(); var interfaceNode = namespaceNode .DescendantNodes() .OfType <InterfaceDeclarationSyntax>() .Single(); var isServiceDefinition = interfaceNode.AttributeLists .SelectMany(al => al.Attributes) .Any(a => "RpcServiceDefinitionAttribute".StartsWith(a.Name.ToString())); if (!isServiceDefinition) { return(null); } var serviceNamespace = namespaceNode.Name.ToString(); var usingStrings = syntaxRoot .DescendantNodes() .OfType <UsingDirectiveSyntax>() .Select(u => u.Name.ToString()) .Concat(config.IncludeNamespaces.Split('|')) .Concat(new [] { serviceNamespace }) .Distinct() .OrderBy(s => s) .Select(s => $"using {s};") .ToArray(); var methods = interfaceNode .DescendantNodes() .OfType <MethodDeclarationSyntax>() .Select(m => ClientMethodTemplate.Create(m)) .ToList(); return(new ClientClassTemplate(methods, config) { RootNamespace = serviceNamespace.Replace("." + config.ServiceNamespaceSuffix, string.Empty), InterfaceName = interfaceNode.Identifier.Text, UsingStatements = string.Join(Environment.NewLine, usingStrings) }); }
public void AddMethod(ClientMethodTemplate method) { _methods.Add(method); }