private MethodDeclarationSyntax _CreateOutputClassWithMethod(TypeDefinition typeDefinition, PropertyDefinition propertyDefinition) { var _validationStatement = _CreatePropertyValidationStatement(propertyDefinition, _property => NameHelper.TextToMethodParameterName(_property.Name)); var _typeCtorArguments = _CreatePropertyArgumentList( typeDefinition, _property => (_property.Name == propertyDefinition.Name ? NameHelper.TextToMethodParameterName(propertyDefinition.Name) : NameHelper.TextToPublicPropertyName(_property.Name))); var _createTypeInstanceStatement = _CreateDeclareVariableAndCreateTypeInstanceStatement(typeDefinition, _typeCtorArguments, SyntaxFactory.Identifier("_instance")); var _typeValidationStatement = _CreateTypeValidationStatement(typeDefinition, SyntaxFactory.IdentifierName("_instance")); var _returnTypeInstanceStatement = SyntaxFactory.ReturnStatement(SyntaxFactory.IdentifierName("_instance")); return(SyntaxFactory .MethodDeclaration( SyntaxFactory.IdentifierName(typeDefinition.Name), NameHelper.TextToPublicMethodIdentifier("With" + propertyDefinition.Name)) .AddParameterListParameters(SyntaxFactory .Parameter(NameHelper.TextToMethodParameterIdentifier(propertyDefinition.Name)) .WithType(SyntaxFactory.IdentifierName(propertyDefinition.Type))) .AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword)) .WithBody(SyntaxFactory.Block() .AddStatements(_validationStatement) .AddStatements(_createTypeInstanceStatement) .AddStatements(_typeValidationStatement) .AddStatements(_returnTypeInstanceStatement))); }
private MethodDeclarationSyntax _CreateOutputClassCreateMethod(TypeDefinition typeDefinition) { var _propertyValidationStatements = _CreatePropertyValidationStatements(typeDefinition, _property => NameHelper.TextToMethodParameterName(_property.Name)); var _typeCtorArguments = _CreatePropertyArgumentList(typeDefinition, _property => (_property.DefaultValuePropertyName ?? NameHelper.TextToMethodParameterName(_property.Name))); var _createTypeInstanceStatement = _CreateDeclareVariableAndCreateTypeInstanceStatement(typeDefinition, _typeCtorArguments, SyntaxFactory.Identifier("_instance")); var _typeValidationStatement = _CreateTypeValidationStatement(typeDefinition, SyntaxFactory.IdentifierName("_instance")); var _returnTypeInstanceStatement = SyntaxFactory.ReturnStatement(SyntaxFactory.IdentifierName("_instance")); return(SyntaxFactory .MethodDeclaration(SyntaxFactory.IdentifierName(typeDefinition.Name), NameHelper.TextToPublicMethodIdentifier("Create")) .AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword), SyntaxFactory.Token(SyntaxKind.StaticKeyword)) .WithParameterList(SyntaxFactory.ParameterList(SyntaxFactory.SeparatedList(typeDefinition.Properties .Where(_property => _property.DefaultValuePropertyName == null) .Select(_property => SyntaxFactory .Parameter(NameHelper.TextToMethodParameterIdentifier(_property.Name)) .WithType(SyntaxFactory.IdentifierName(_property.Type)))))) .WithBody(SyntaxFactory.Block() .AddStatements(_propertyValidationStatements) .AddStatements(_createTypeInstanceStatement) .AddStatements(_typeValidationStatement) .AddStatements(_returnTypeInstanceStatement))); }
private ConstructorDeclarationSyntax _CreateOutputClassMainCtor(TypeDefinition typeDefinition) { return(SyntaxFactory .ConstructorDeclaration(SyntaxFactory.Identifier(typeDefinition.Name)) .AddModifiers(SyntaxFactory.Token(SyntaxKind.PrivateKeyword)) .WithParameterList(SyntaxFactory.ParameterList(SyntaxFactory.SeparatedList(typeDefinition.Properties .Select(_property => SyntaxFactory .Parameter(NameHelper.TextToMethodParameterIdentifier(_property.Name)) .WithType(SyntaxFactory.IdentifierName(_property.Type)))))) .WithBody(SyntaxFactory .Block(typeDefinition.Properties .Select(_property => SyntaxFactory .ExpressionStatement(SyntaxFactory .AssignmentExpression( SyntaxKind.SimpleAssignmentExpression, SyntaxFactory.IdentifierName(NameHelper.TextToPublicPropertyIdentifier(_property.Name)), SyntaxFactory.IdentifierName(NameHelper.TextToMethodParameterIdentifier(_property.Name)))))))); }