private int GenerateConstraintId <TEvent>(IConstraintInfo constraint)
        {
            var eventType = typeof(TEvent);

            var hash = (eventType.FullName + JsonSerializer.Serialize(constraint.GetConstraint())).GetHashCode();

            if (!eventConstraints.ContainsKey(eventType))
            {
                AddConstraint <TEvent>(constraint);
                return(hash);
            }

            var existing = eventConstraints[eventType].FirstOrDefault(c => c.Id == hash);

            if (existing == null)
            {
                AddConstraint <TEvent>(constraint);
            }

            return(hash);
        }
Ejemplo n.º 2
0
        public int GenerateConstraintId <TEvent>(IConstraintInfo constraint)
        {
            var eventType = typeof(TEvent);

            if (!eventConstraints.ContainsKey(eventType))
            {
                return(GenerateNewConstraintId <TEvent>(constraint));
            }


            var existing = eventConstraints[eventType].FirstOrDefault(c => comparer.Compare(constraint.GetConstraint(), c.GetConstraint()));

            return(existing != null ? existing.Id : GenerateNewConstraintId <TEvent>(constraint));
        }