Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / Extensions / UI / AssemblyCache.cs / 1305376 / AssemblyCache.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.UI {
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Reflection;
using System.Web.Configuration;
using System.Web.Script;
// Caches Assembly APIs to improve performance
internal static class AssemblyCache {
// PERF: Cache reference to System.Web.Extensions assembly. Use ScriptManager since it's guaranteed to be in S.W.E
public static readonly Assembly SystemWebExtensions = typeof(ScriptManager).Assembly;
public static readonly Assembly SystemWeb = typeof(Page).Assembly;
private static CompilationSection _compilationSection;
internal static bool _useCompilationSection = true;
// Maps string (assembly name) to Assembly
private static readonly Hashtable _assemblyCache = Hashtable.Synchronized(new Hashtable());
// Maps assembly to Version
// internal so it can be manipulated by the unit test suite
internal static readonly Hashtable _versionCache = Hashtable.Synchronized(new Hashtable());
// Maps an assembly to its ajax framework assembly attribute. If it doesn't have one, it maps it to a null value
private static readonly ConcurrentDictionary _ajaxAssemblyAttributeCache =
new ConcurrentDictionary();
private static CompilationSection CompilationSection {
get {
if (_compilationSection == null) {
_compilationSection = RuntimeConfig.GetAppConfig().Compilation;
}
return _compilationSection;
}
}
public static Version GetVersion(Assembly assembly) {
Debug.Assert(assembly != null);
Version version = (Version)_versionCache[assembly];
if (version == null) {
// use new AssemblyName() instead of assembly.GetName() so it works in medium trust
version = new AssemblyName(assembly.FullName).Version;
_versionCache[assembly] = version;
}
return version;
}
public static Assembly Load(string assemblyName) {
Debug.Assert(!String.IsNullOrEmpty(assemblyName));
Assembly assembly = (Assembly)_assemblyCache[assemblyName];
if (assembly == null) {
// _useCompilationSection must be set to false in a unit test environment since there
// is no http runtime, and therefore no trust level is set.
if (_useCompilationSection) {
assembly = CompilationSection.LoadAssembly(assemblyName, true);
}
else {
assembly = Assembly.Load(assemblyName);
}
_assemblyCache[assemblyName] = assembly;
}
return assembly;
}
public static bool IsAjaxFrameworkAssembly(Assembly assembly) {
return (GetAjaxFrameworkAssemblyAttribute(assembly) != null);
}
public static AjaxFrameworkAssemblyAttribute GetAjaxFrameworkAssemblyAttribute(Assembly assembly) {
Debug.Assert(assembly != null);
AjaxFrameworkAssemblyAttribute ajaxFrameworkAssemblyAttribute = null;
if (!_ajaxAssemblyAttributeCache.TryGetValue(assembly, out ajaxFrameworkAssemblyAttribute)) {
foreach (Attribute attribute in assembly.GetCustomAttributes(false)) {
if (attribute is AjaxFrameworkAssemblyAttribute) {
ajaxFrameworkAssemblyAttribute = (AjaxFrameworkAssemblyAttribute)attribute;
break;
}
}
_ajaxAssemblyAttributeCache.TryAdd(assembly, ajaxFrameworkAssemblyAttribute);
}
return ajaxFrameworkAssemblyAttribute;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.UI {
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Reflection;
using System.Web.Configuration;
using System.Web.Script;
// Caches Assembly APIs to improve performance
internal static class AssemblyCache {
// PERF: Cache reference to System.Web.Extensions assembly. Use ScriptManager since it's guaranteed to be in S.W.E
public static readonly Assembly SystemWebExtensions = typeof(ScriptManager).Assembly;
public static readonly Assembly SystemWeb = typeof(Page).Assembly;
private static CompilationSection _compilationSection;
internal static bool _useCompilationSection = true;
// Maps string (assembly name) to Assembly
private static readonly Hashtable _assemblyCache = Hashtable.Synchronized(new Hashtable());
// Maps assembly to Version
// internal so it can be manipulated by the unit test suite
internal static readonly Hashtable _versionCache = Hashtable.Synchronized(new Hashtable());
// Maps an assembly to its ajax framework assembly attribute. If it doesn't have one, it maps it to a null value
private static readonly ConcurrentDictionary _ajaxAssemblyAttributeCache =
new ConcurrentDictionary();
private static CompilationSection CompilationSection {
get {
if (_compilationSection == null) {
_compilationSection = RuntimeConfig.GetAppConfig().Compilation;
}
return _compilationSection;
}
}
public static Version GetVersion(Assembly assembly) {
Debug.Assert(assembly != null);
Version version = (Version)_versionCache[assembly];
if (version == null) {
// use new AssemblyName() instead of assembly.GetName() so it works in medium trust
version = new AssemblyName(assembly.FullName).Version;
_versionCache[assembly] = version;
}
return version;
}
public static Assembly Load(string assemblyName) {
Debug.Assert(!String.IsNullOrEmpty(assemblyName));
Assembly assembly = (Assembly)_assemblyCache[assemblyName];
if (assembly == null) {
// _useCompilationSection must be set to false in a unit test environment since there
// is no http runtime, and therefore no trust level is set.
if (_useCompilationSection) {
assembly = CompilationSection.LoadAssembly(assemblyName, true);
}
else {
assembly = Assembly.Load(assemblyName);
}
_assemblyCache[assemblyName] = assembly;
}
return assembly;
}
public static bool IsAjaxFrameworkAssembly(Assembly assembly) {
return (GetAjaxFrameworkAssemblyAttribute(assembly) != null);
}
public static AjaxFrameworkAssemblyAttribute GetAjaxFrameworkAssemblyAttribute(Assembly assembly) {
Debug.Assert(assembly != null);
AjaxFrameworkAssemblyAttribute ajaxFrameworkAssemblyAttribute = null;
if (!_ajaxAssemblyAttributeCache.TryGetValue(assembly, out ajaxFrameworkAssemblyAttribute)) {
foreach (Attribute attribute in assembly.GetCustomAttributes(false)) {
if (attribute is AjaxFrameworkAssemblyAttribute) {
ajaxFrameworkAssemblyAttribute = (AjaxFrameworkAssemblyAttribute)attribute;
break;
}
}
_ajaxAssemblyAttributeCache.TryAdd(assembly, ajaxFrameworkAssemblyAttribute);
}
return ajaxFrameworkAssemblyAttribute;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- CodeTypeDeclarationCollection.cs
- TextBox.cs
- RequestCachePolicyConverter.cs
- TCPListener.cs
- GraphicsPathIterator.cs
- EntityDataSourceContainerNameConverter.cs
- AgileSafeNativeMemoryHandle.cs
- DynamicPropertyHolder.cs
- StringCollection.cs
- FuncTypeConverter.cs
- FileLevelControlBuilderAttribute.cs
- BrushMappingModeValidation.cs
- DBConnectionString.cs
- KeyPressEvent.cs
- ModelPropertyCollectionImpl.cs
- BitArray.cs
- TemplatedWizardStep.cs
- arclist.cs
- SoapAttributeOverrides.cs
- Vector3DConverter.cs
- DependencyPropertyValueSerializer.cs
- ReferencedCollectionType.cs
- ObjectDataSourceView.cs
- DecoderReplacementFallback.cs
- FormsAuthentication.cs
- DataGridViewRowsRemovedEventArgs.cs
- CatalogPartCollection.cs
- FlowDocumentPage.cs
- ToggleProviderWrapper.cs
- GuidelineCollection.cs
- dbdatarecord.cs
- SystemDiagnosticsSection.cs
- PersonalizationAdministration.cs
- ModelPropertyCollectionImpl.cs
- SecurityIdentifierConverter.cs
- GPStream.cs
- VersionPair.cs
- GroupDescription.cs
- ConfigurationSection.cs
- UserControlParser.cs
- ViewgenGatekeeper.cs
- FormatConvertedBitmap.cs
- ValidatorCollection.cs
- BooleanSwitch.cs
- GridViewPageEventArgs.cs
- WindowsListBox.cs
- ObfuscateAssemblyAttribute.cs
- TraceShell.cs
- GenericPrincipal.cs
- EncryptedPackage.cs
- FloaterParagraph.cs
- ExchangeUtilities.cs
- ContractComponent.cs
- ListItemCollection.cs
- MobileSysDescriptionAttribute.cs
- DataList.cs
- XmlSchemaType.cs
- WebPart.cs
- DebugViewWriter.cs
- FilteredDataSetHelper.cs
- CustomSignedXml.cs
- WebPartEditorCancelVerb.cs
- ProxyManager.cs
- TypeConvertions.cs
- NativeWindow.cs
- pingexception.cs
- StringCollection.cs
- MasterPageCodeDomTreeGenerator.cs
- MailSettingsSection.cs
- EnumerableRowCollection.cs
- HeaderCollection.cs
- NameSpaceExtractor.cs
- BindingOperations.cs
- ProgressChangedEventArgs.cs
- RuleSettings.cs
- TrustManagerMoreInformation.cs
- CompositeDesignerAccessibleObject.cs
- HyperlinkAutomationPeer.cs
- RoleGroup.cs
- Attributes.cs
- RadioButton.cs
- WebPartMenuStyle.cs
- HtmlTableRow.cs
- MethodExpr.cs
- HtmlMeta.cs
- WebMessageFormatHelper.cs
- ComponentSerializationService.cs
- DesignTimeSiteMapProvider.cs
- namescope.cs
- RoleServiceManager.cs
- DesignerFrame.cs
- CardSpacePolicyElement.cs
- Token.cs
- Number.cs
- TrackingServices.cs
- NameObjectCollectionBase.cs
- XmlMtomWriter.cs
- SiteMapSection.cs
- PropertyChangingEventArgs.cs
- NameValuePair.cs