// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
namespace Microsoft.AspNet.Routing
{
///
/// Information about the current routing path.
///
public class RouteData
{
private Dictionary _dataTokens;
private RouteValueDictionary _values;
///
/// Creates a new instance.
///
public RouteData()
{
// Perf: Avoid allocating DataTokens and RouteValues unless needed.
Routers = new List();
}
///
/// Creates a new instance with values copied from .
///
/// The other instance to copy.
public RouteData(RouteData other)
{
if (other == null)
{
throw new ArgumentNullException(nameof(other));
}
Routers = new List(other.Routers);
// Perf: Avoid allocating DataTokens and RouteValues unless we need to make a copy.
if (other._dataTokens != null)
{
_dataTokens = new Dictionary(other._dataTokens, StringComparer.OrdinalIgnoreCase);
}
if (other._values != null)
{
_values = new RouteValueDictionary(other._values);
}
}
///
/// Gets the data tokens produced by routes on the current routing path.
///
public IDictionary DataTokens
{
get
{
if (_dataTokens == null)
{
_dataTokens = new Dictionary(StringComparer.OrdinalIgnoreCase);
}
return _dataTokens;
}
}
///
/// Gets the list of instances on the current routing path.
///
public List Routers { get; }
///
/// Gets the set of values produced by routes on the current routing path.
///
public IDictionary Values
{
get
{
if (_values == null)
{
_values = new RouteValueDictionary();
}
return _values;
}
}
}
}