public static PartitionKeyHashRanges Create(IEnumerable <PartitionKeyHashRange> partitionKeyHashRanges)
        {
            CreateOutcome createStatus = PartitionKeyHashRanges.TryCreate(
                partitionKeyHashRanges,
                out PartitionKeyHashRanges partitionedSortedEffectiveRanges);

            switch (createStatus)
            {
            case CreateOutcome.DuplicatePartitionKeyRange:
                throw new ArgumentException($"{nameof(partitionKeyHashRanges)} must not have duplicate values.");

            case CreateOutcome.EmptyPartitionKeyRange:
                throw new ArgumentException($"{nameof(partitionKeyHashRanges)} must not have an empty range.");

            case CreateOutcome.NoPartitionKeyRanges:
                throw new ArgumentException($"{nameof(partitionKeyHashRanges)} must not be empty.");

            case CreateOutcome.NullPartitionKeyRanges:
                throw new ArgumentNullException(nameof(partitionKeyHashRanges));

            case CreateOutcome.RangesAreNotContiguous:
                throw new ArgumentException($"{nameof(partitionKeyHashRanges)} must have contiguous ranges.");

            case CreateOutcome.RangesOverlap:
                throw new ArgumentException($"{nameof(partitionKeyHashRanges)} must not overlapping ranges.");

            case CreateOutcome.Success:
                return(partitionedSortedEffectiveRanges);

            default:
                throw new ArgumentOutOfRangeException($"Unknown {nameof(CreateOutcome)}: {createStatus}.");
            }
        }
Example #2
0
            public static TryCatch <PartitionKeyHashRanges> Create(IEnumerable <PartitionKeyHashRange> partitionKeyHashRanges)
            {
                CreateOutcome createStatus = PartitionKeyHashRanges.TryCreate(
                    partitionKeyHashRanges,
                    out PartitionKeyHashRanges partitionedSortedEffectiveRanges);

                return(createStatus switch
                {
                    CreateOutcome.DuplicatePartitionKeyRange => TryCatch <PartitionKeyHashRanges> .FromException(
                        new ArgumentException($"{nameof(partitionKeyHashRanges)} must not have duplicate values.")),
                    CreateOutcome.EmptyPartitionKeyRange => TryCatch <PartitionKeyHashRanges> .FromException(
                        new ArgumentException($"{nameof(partitionKeyHashRanges)} must not have an empty range.")),
                    CreateOutcome.NoPartitionKeyRanges => TryCatch <PartitionKeyHashRanges> .FromException(
                        new ArgumentException($"{nameof(partitionKeyHashRanges)} must not be empty.")),
                    CreateOutcome.NullPartitionKeyRanges => TryCatch <PartitionKeyHashRanges> .FromException(
                        new ArgumentNullException(nameof(partitionKeyHashRanges))),
                    CreateOutcome.RangesAreNotContiguous => TryCatch <PartitionKeyHashRanges> .FromException(
                        new ArgumentException($"{nameof(partitionKeyHashRanges)} must have contiguous ranges.")),
                    CreateOutcome.RangesOverlap => TryCatch <PartitionKeyHashRanges> .FromException(
                        new ArgumentException($"{nameof(partitionKeyHashRanges)} must not overlapping ranges.")),
                    CreateOutcome.Success => TryCatch <PartitionKeyHashRanges> .FromResult(partitionedSortedEffectiveRanges),
                    _ => throw new ArgumentOutOfRangeException($"Unknown {nameof(CreateOutcome)}: {createStatus}."),
                });