Exemplo n.º 1
0
        private static BlockSyntax CreateAddSyntax(IList <PropertyDeclarationSyntax> properties)
        {
            // var hash = new HashCode();
            var declaration = VariableDeclaration.Create("hash", nameof(HashCode));

            var addExpressions = properties.Select(CreateAddInvocation).Cast <StatementSyntax>().ToList();

            // return hash.ToHashCode();
            var returnStatement = ReturnStatement(
                InvocationExpression(AccessMemberSyntax.Create("hash.ToHashCode")));

            var statements = new StatementSyntax[addExpressions.Count + 2];

            statements[0] = declaration;
            addExpressions.CopyTo(statements, 1);
            statements[^ 1] = returnStatement;