private static ConstructorDeclarationSyntax CreateConstructor(string identifierText, IEnumerable <MemberDeclarationSyntax> members)
        {
            var parameters = new List <ParameterSyntax>();
            var statements = new List <ExpressionStatementSyntax>();

            foreach (MemberDeclarationSyntax member in members)
            {
                string name          = GetIdentifier(member).ValueText;
                string parameterName = Identifier.ToCamelCase(name);

                statements.Add(ExpressionStatement(
                                   SimpleAssignmentExpression(
                                       IdentifierName(name),
                                       IdentifierName(parameterName))));

                parameters.Add(Parameter(
                                   default(SyntaxList <AttributeListSyntax>),
                                   default(SyntaxTokenList),
                                   GetType(member),
                                   Identifier(parameterName),
                                   default(EqualsValueClauseSyntax)));
            }

            return(ConstructorDeclaration(
                       default(SyntaxList <AttributeListSyntax>),
                       ModifierFactory.Public(),
                       Identifier(identifierText),
                       ParameterList(SeparatedList(parameters)),
                       default(ConstructorInitializerSyntax),
                       Block(statements)));
        }
        private IEnumerable <MemberDeclarationSyntax> CreateMembers(IEnumerable <RefactoringInfo> refactorings)
        {
            yield return(ConstructorDeclaration("RefactoringsOptionsPage")
                         .WithModifiers(ModifierFactory.Public())
                         .WithBody(Block(refactorings.Select(refactoring =>
            {
                return ExpressionStatement(
                    SimpleAssignmentExpression(
                        IdentifierName(refactoring.Identifier),
                        (refactoring.IsEnabledByDefault) ? TrueLiteralExpression() : FalseLiteralExpression()));
            }))));

            yield return(MethodDeclaration(VoidType(), "Apply")
                         .WithModifiers(ModifierFactory.Public())
                         .WithBody(
                             Block(refactorings.Select(refactoring =>
            {
                return ExpressionStatement(
                    InvocationExpression(
                        "SetIsEnabled",
                        ArgumentList(
                            Argument(
                                SimpleMemberAccessExpression(
                                    IdentifierName("RefactoringIdentifiers"),
                                    IdentifierName(refactoring.Identifier))),
                            Argument(IdentifierName(refactoring.Identifier)))));
            }))));

            foreach (RefactoringInfo info in refactorings)
            {
                yield return(CreateRefactoringProperty(info));
            }
        }
Exemplo n.º 3
0
        public override MemberDeclarationSyntax CreateDeclaration()
        {
            PropertyKind propertyKind = (SupportsCSharp6)
                ? PropertyKind.ReadOnlyAutoProperty
                : PropertyKind.AutoPropertyWithPrivateSet;

            return(PropertyDeclaration(propertyKind, ModifierFactory.Public(), Type, Name));
        }
 private PropertyDeclarationSyntax CreateRefactoringProperty(RefactoringInfo refactoring)
 {
     return(PropertyDeclaration(BoolType(), refactoring.Identifier)
            .WithAttributeLists(
                AttributeList(Attribute("Category", IdentifierName("RefactoringCategory"))),
                AttributeList(Attribute("DisplayName", StringLiteralExpression(refactoring.Title))),
                AttributeList(Attribute("Description", StringLiteralExpression(CreateDescription(refactoring)))),
                AttributeList(Attribute("TypeConverter", TypeOfExpression(IdentifierName("EnabledDisabledConverter")))))
            .WithModifiers(ModifierFactory.Public())
            .WithAccessorList(
                AccessorList(
                    AutoImplementedGetter(),
                    AutoImplementedSetter())));
 }