static void Validate(UriTemplatePathPartiallyEquivalentSet pes, bool allowDuplicateEquivalentUriTemplates) { // A set with 0 or 1 items is valid by definition if (pes.Items.Count < 2) { return; } // Assert all paths are partially-equivalent for (int i = 0; i < pes.Items.Count - 1; ++i) { Fx.Assert(pes.Items[i].Key.IsPathPartiallyEquivalentAt(pes.Items[i + 1].Key, pes.SegmentsCount), "all elements of a PES must be path partially-equivalent"); } // We will check that the queries disambiguate only for templates, which are // matched completely at the segments count; templates, which are match at // that point due to terminal defaults, will be ruled out. UriTemplate[] a = new UriTemplate[pes.Items.Count]; int arrayIndex = 0; foreach (KeyValuePair <UriTemplate, object> kvp in pes.Items) { if (pes.SegmentsCount < kvp.Key.segments.Count) { continue; } Fx.Assert(arrayIndex < a.Length, "We made enough room for all the items"); a[arrayIndex++] = kvp.Key; } // Ensure that queries disambiguate (if needed) : if (arrayIndex > 0) { UriTemplateHelpers.DisambiguateSamePath(a, 0, arrayIndex, allowDuplicateEquivalentUriTemplates); } }
private static void Validate(UriTemplatePathPartiallyEquivalentSet pes, bool allowDuplicateEquivalentUriTemplates) { if (pes.Items.Count >= 2) { for (int i = 0; i < (pes.Items.Count - 1); i++) { } UriTemplate[] array = new UriTemplate[pes.Items.Count]; int b = 0; foreach (KeyValuePair <UriTemplate, object> pair in pes.Items) { if (pes.SegmentsCount >= pair.Key.segments.Count) { array[b++] = pair.Key; } } if (b > 0) { UriTemplateHelpers.DisambiguateSamePath(array, 0, b, allowDuplicateEquivalentUriTemplates); } } }