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

66 lines
2.5 KiB
C#

//------------------------------------------------------------------------------
// <copyright file="DynamicModuleRegistry.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web {
using System;
using System.Collections.Generic;
using System.Globalization;
internal sealed class DynamicModuleRegistry {
private const string _moduleNameFormat = "__DynamicModule_{0}_{1}";
private readonly List<DynamicModuleRegistryEntry> _entries = new List<DynamicModuleRegistryEntry>();
private bool _entriesReadonly;
private readonly object _lockObj = new object();
public void Add(Type moduleType) {
if (moduleType == null) {
throw new ArgumentNullException("moduleType");
}
if (!typeof(IHttpModule).IsAssignableFrom(moduleType)) {
string message = String.Format(CultureInfo.CurrentCulture, SR.GetString(SR.DynamicModuleRegistry_TypeIsNotIHttpModule), moduleType);
throw new ArgumentException(message, "moduleType");
}
lock (_lockObj) {
if (_entriesReadonly) {
// modules have already been initialized, e.g. Application_Start has already run
throw new InvalidOperationException(SR.GetString(SR.DynamicModuleRegistry_ModulesAlreadyInitialized));
}
_entries.Add(new DynamicModuleRegistryEntry(MakeUniqueModuleName(moduleType), moduleType.AssemblyQualifiedName));
}
}
public ICollection<DynamicModuleRegistryEntry> LockAndFetchList() {
lock (_lockObj) {
// once the list has been returned, it must be immutable
_entriesReadonly = true;
return _entries;
}
}
private static string MakeUniqueModuleName(Type moduleType) {
// returns a unique name for this module
return String.Format(CultureInfo.InvariantCulture, _moduleNameFormat, moduleType.AssemblyQualifiedName, Guid.NewGuid());
}
}
internal struct DynamicModuleRegistryEntry {
public readonly string Name;
public readonly string Type;
public DynamicModuleRegistryEntry(string name, string type) {
Name = name;
Type = type;
}
}
}