HttpLimitEntryCollection Class

Represents a collection of HttpLimitEntry objects.

Namespace: System.Net.Http.Headers

Assembly: System.Net.Http.Headers (in System.Net.Http.Headers.dll)

Syntax

public sealed class HttpLimitEntryCollection : IEnumerable<KeyValuePair<string, HttpLimitEntry>>, ICollection<KeyValuePair<string, HttpLimitEntry>>, IDictionary<string, HttpLimitEntry>, IDictionary

Remarks

The HttpLimitEntryCollection class is used to store and manage a set of HTTP limit entries. Each entry typically maps a header name to its corresponding limit configuration.

This collection provides dictionary-like access, allowing you to add, retrieve, and remove limit entries by their header name.

Fields

This class has no public fields.

Properties

Name Description
Item[string key] Gets or sets the HttpLimitEntry associated with the specified header name.
Count Gets the number of elements contained in the collection.
IsReadOnly Gets a value indicating whether the collection is read-only.
Keys Gets an ICollection object that contains the keys for the dictionary.
Values Gets an ICollection object that contains the values for the dictionary.

Methods

Name Description
Add(string key, HttpLimitEntry value) Adds an entry with the specified key and value to the collection.
Add(KeyValuePair<string, HttpLimitEntry> item) Adds an item to the collection.
Clear() Removes all entries from the collection.
Contains(string key) Determines whether the collection contains an entry with the specified key.
Contains(KeyValuePair<string, HttpLimitEntry> item) Determines whether the collection contains a specific item.
GetEnumerator() Returns an enumerator that iterates through the collection.
Remove(string key) Removes the entry with the specified key from the collection.
Remove(KeyValuePair<string, HttpLimitEntry> item) Removes the first occurrence of a specific item from the collection.
TryGetValue(string key, out HttpLimitEntry value) Attempts to get the HttpLimitEntry associated with the specified key.

Examples

Adding and Retrieving Limit Entries


using System;
using System.Net.Http.Headers;

public class Example
{
    public static void Main(string[] args)
    {
        // Create a new HttpLimitEntryCollection
        var limitCollection = new HttpLimitEntryCollection();

        // Create some HttpLimitEntry objects
        var contentLengthLimit = new HttpLimitEntry(5 * 1024 * 1024); // 5MB limit
        var headerLimit = new HttpLimitEntry(100); // 100 header entries limit

        // Add entries to the collection
        limitCollection.Add("Content-Length", contentLengthLimit);
        limitCollection.Add("X-Custom-Header", headerLimit);

        // Retrieve an entry
        if (limitCollection.TryGetValue("Content-Length", out HttpLimitEntry retrievedLimit))
        {
            Console.WriteLine($"Content-Length limit: {retrievedLimit.Max}");
        }

        // Iterate through the collection
        Console.WriteLine("\nAll limit entries:");
        foreach (var kvp in limitCollection)
        {
            Console.WriteLine($"- {kvp.Key}: Max={kvp.Value.Max}");
        }
    }
}