Files
dotnet-bot adf899c629 Adding System.Data..., System.ServiceModel..., and System.Web...
Adding reference source for
System.Data
System.Data.DataSetExtensions
System.Data.Entity
System.Data.Entity.Design
System.Data.Linq
System.Data.SqlXml
System.ServiceModel
System.ServiceModel.Activation
System.ServiceModel.Activities
System.ServiceModel.Channels
System.ServiceModel.Discovery
System.ServiceModel.Internals
System.ServiceModel.Routing
System.ServiceModel.WasHosting
System.ServiceModel.Web
System.Web
System.Web.ApplicationServices
System.Web.DynamicData
System.Web.Entity
System.Web.Entity.Design
System.Web.Extensions
System.Web.Mobile
System.Web.Routing
System.Web.Services
System.Xml
System.Xml.Linq
2016-05-03 00:07:37 +02:00

48 lines
1.6 KiB
C#

namespace System.Web.ModelBinding {
using System;
using System.Collections.Generic;
using System.Globalization;
public class DictionaryValueProvider<TValue> : IValueProvider {
private readonly PrefixContainer _prefixes;
private readonly Dictionary<string, ValueProviderResult> _values = new Dictionary<string, ValueProviderResult>(StringComparer.OrdinalIgnoreCase);
public DictionaryValueProvider(IDictionary<string, TValue> dictionary, CultureInfo culture) {
if (dictionary == null) {
throw new ArgumentNullException("dictionary");
}
_prefixes = new PrefixContainer(dictionary.Keys);
AddValues(dictionary, culture);
}
private void AddValues(IDictionary<string, TValue> dictionary, CultureInfo culture) {
foreach (var entry in dictionary) {
object rawValue = entry.Value;
string attemptedValue = Convert.ToString(rawValue, culture);
_values[entry.Key] = new ValueProviderResult(rawValue, attemptedValue, culture);
}
}
public virtual bool ContainsPrefix(string prefix) {
if (prefix == null) {
throw new ArgumentNullException("prefix");
}
return _prefixes.ContainsPrefix(prefix);
}
public virtual ValueProviderResult GetValue(string key) {
if (key == null) {
throw new ArgumentNullException("key");
}
ValueProviderResult vpResult;
_values.TryGetValue(key, out vpResult);
return vpResult;
}
}
}