Пример #1
0
        private static IList <SyntaxNode> CreateGetHashCodeMethodStatements(
            ISyntaxFactoryService factory,
            Compilation compilation,
            INamedTypeSymbol containingType,
            IList <ISymbol> members,
            CancellationToken cancellationToken)
        {
            const string HashCodeName = "hashCode";

            // -1521134295
            var permuteValue = factory.CreateNegateExpression(
                factory.CreateConstantExpression(1521134295));

            var statements = new List <SyntaxNode>();

            var hashCodeNameExpression = factory.CreateIdentifierName(HashCodeName);

            var firstHashValue = ComputeHashValue(factory, compilation, members[0]);

            if (members.Count == 1)
            {
#if false
                return(this.S1.GetHashCode());
#endif
                statements.Add(factory.CreateReturnStatement(firstHashValue));
            }
            else
            {
#if false
                var hashCode = this.S1.GetHashCode();
#endif
                statements.Add(factory.CreateLocalDeclarationStatement(
                                   factory.CreateVariableDeclarator(HashCodeName, firstHashValue)));

                for (var i = 1; i < members.Count; i++)
                {
#if false
                    hashCode = hashCode * 0xA5555529 + value
#endif
                    statements.Add(factory.CreateExpressionStatement(
                                       factory.CreateAssignExpression(hashCodeNameExpression,
                                                                      factory.CreateAddExpression(
                                                                          factory.CreateMultiplyExpression(hashCodeNameExpression, permuteValue),
                                                                          ComputeHashValue(factory, compilation, members[i])))));
                }

#if false
                return(hashCode);
#endif
                statements.Add(factory.CreateReturnStatement(hashCodeNameExpression));
            }

            return(statements);
        }
        private static IList<SyntaxNode> CreateGetHashCodeMethodStatements(
            ISyntaxFactoryService factory,
            Compilation compilation,
            INamedTypeSymbol containingType,
            IList<ISymbol> members,
            CancellationToken cancellationToken)
        {
            const string HashCodeName = "hashCode";

            // -1521134295
            var permuteValue = factory.CreateNegateExpression(
                factory.CreateConstantExpression(1521134295));

            var statements = new List<SyntaxNode>();

            var hashCodeNameExpression = factory.CreateIdentifierName(HashCodeName);

            var firstHashValue = ComputeHashValue(factory, compilation, members[0]);
            if (members.Count == 1)
            {
#if false
                return this.S1.GetHashCode();
#endif
                statements.Add(factory.CreateReturnStatement(firstHashValue));
            }
            else
            {
#if false
                var hashCode = this.S1.GetHashCode();
#endif
                statements.Add(factory.CreateLocalDeclarationStatement(
                    factory.CreateVariableDeclarator(HashCodeName, firstHashValue)));

                for (var i = 1; i < members.Count; i++)
                {
#if false
                    hashCode = hashCode * 0xA5555529 + value
#endif
                    statements.Add(factory.CreateExpressionStatement(
                        factory.CreateAssignExpression(hashCodeNameExpression,
                            factory.CreateAddExpression(
                                factory.CreateMultiplyExpression(hashCodeNameExpression, permuteValue),
                                ComputeHashValue(factory, compilation, members[i])))));
                }

#if false
                return hashCode;
#endif
                statements.Add(factory.CreateReturnStatement(hashCodeNameExpression));
            }

            return statements;
        }