public IEnumerable <SyntaxNode> GetNodes(SyntaxGenerator gen) { var required = Values.Select(SyntaxExts.ToLiteral); var optional = Properties.ToDictionary(k => k.Key, v => SyntaxExts.ToLiteral(v.Value)); var assigns = SyntaxExts.ToSyntaxNodes(optional); var args = required.Concat(assigns); yield return(gen.Attribute(Name, attributeArguments: args)); }
public IEnumerable <SyntaxNode> GetNodes(SyntaxGenerator gen) { var acc = Visibility.ToAccessibility(); var mod = Modifier.ToDeclare(); var type = SyntaxFactory.ParseTypeName(ReturnType); var stats = SyntaxExts.GetNodesFromCode(Body); var meth = (MethodDeclarationSyntax)gen.MethodDeclaration(Name, gen.GetParamNodes(this), accessibility: acc, modifiers: mod, returnType: type, statements: stats); yield return(meth.WithAttributeLists(gen.GetAttrsNodes(this).ToList())); }
public IEnumerable <SyntaxNode> GetNodes(SyntaxGenerator gen) { var type = SyntaxFactory.ParseTypeName(Type); var parms = gen.GetParamNodes(this).OfType <ParameterSyntax>(); var indx = SyntaxFactory.IndexerDeclaration(type) .WithModifiers(Visibility.ToKeyword().ToList()) .AddParameterListParameters(parms.ToArray()); var isAuto = Getter == null && Setter == null; if (isAuto || Getter != null) { var get = SyntaxFactory.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration); if (isAuto || Getter == null) { get = get.WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken)); } else { get = get.WithBody(SyntaxExts.GetBlockFromCode(Getter)); } indx = indx.AddAccessorListAccessors(get); } if (isAuto || Setter != null) { var set = SyntaxFactory.AccessorDeclaration(SyntaxKind.SetAccessorDeclaration); if (isAuto || Setter == null) { set = set.WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken)); } else { set = set.WithBody(SyntaxExts.GetBlockFromCode(Setter)); } indx = indx.AddAccessorListAccessors(set); } yield return(indx); }