Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / ndp / fx / src / xsp / System / Web / Extensions / ui / WebResourceUtil.cs / 1 / WebResourceUtil.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.UI {
using System;
using System.Reflection;
using System.Diagnostics;
using System.Collections;
using System.Globalization;
using System.Web.UI;
using System.Web.Resources;
using System.Web.Util;
internal static class WebResourceUtil {
// Maps Pair(resourceName, assembly) to bool
private static readonly Hashtable _assemblyContainsWebResourceCache = Hashtable.Synchronized(new Hashtable());
// Returns true if the assembly contains a Web resource and an embedded resource with
// the sepecified name. Throws exception if assembly contains Web resource but no
// embedded resource, since this is always an error.
public static bool AssemblyContainsWebResource(Assembly assembly, string resourceName) {
// PERF: Special-case known resources in our own assembly
if (assembly == AssemblyCache.SystemWebExtensions) {
return SystemWebExtensionsContainsWebResource(resourceName);
}
// Getting and checking the custom attributes is expensive, so we cache the result
// of the lookup.
Pair key = new Pair(resourceName, assembly);
object assemblyContainsWebResource = _assemblyContainsWebResourceCache[key];
if (assemblyContainsWebResource == null) {
assemblyContainsWebResource = false;
object[] attrs = assembly.GetCustomAttributes(typeof(WebResourceAttribute), false);
foreach (WebResourceAttribute attr in attrs) {
// Resource names are always case-sensitive
if (String.Equals(attr.WebResource, resourceName, StringComparison.Ordinal)) {
if (assembly.GetManifestResourceStream(resourceName) != null) {
assemblyContainsWebResource = true;
break;
}
else {
// Always an error to contain Web resource but not embedded resource.
throw new InvalidOperationException(String.Format(
CultureInfo.CurrentUICulture,
AtlasWeb.WebResourceUtil_AssemblyDoesNotContainEmbeddedResource,
assembly, resourceName));
}
}
}
_assemblyContainsWebResourceCache[key] = assemblyContainsWebResource;
}
return (bool)assemblyContainsWebResource;
}
private static bool SystemWebExtensionsContainsWebResource(string resourceName) {
// PERF: Switching over the length is more performant than switching over the string itself
// or checking equality against each string. When switching over the string itself, the switch
// is compiled to a lookup in a static Dictionary, which is 5-10 times slower than
// switching over the length. Checking equality against each string ranges from equal performance
// to 10 times slower, depending on how early a match is found.
switch (resourceName.Length) {
case 16:
return resourceName == "MicrosoftAjax.js";
case 24:
return resourceName == "MicrosoftAjaxWebForms.js";
case 21:
return resourceName == "MicrosoftAjaxTimer.js";
case 22:
return resourceName == "MicrosoftAjax.debug.js";
case 30:
return resourceName == "MicrosoftAjaxWebForms.debug.js";
case 33:
return resourceName == "MicrosoftAjaxDataService.debug.js";
case 27:
return resourceName == "MicrosoftAjaxTimer.debug.js" ||
resourceName == "MicrosoftAjaxDataService.js";
default:
return false;
}
}
// Throws exception if the assembly does not contain a Web resource and an embedded resource
// with the specified name.
public static void VerifyAssemblyContainsReleaseWebResource(Assembly assembly, string releaseResourceName) {
if (!AssemblyContainsWebResource(assembly, releaseResourceName)) {
throw new InvalidOperationException(String.Format(
CultureInfo.CurrentUICulture,
AtlasWeb.WebResourceUtil_AssemblyDoesNotContainReleaseWebResource,
assembly, releaseResourceName));
}
}
// Throws exception if the assembly does not contain a Web resource and an embedded resource
// with the specified name.
public static void VerifyAssemblyContainsDebugWebResource(Assembly assembly, string debugResourceName) {
if (!AssemblyContainsWebResource(assembly, debugResourceName)) {
throw new InvalidOperationException(String.Format(
CultureInfo.CurrentUICulture,
AtlasWeb.WebResourceUtil_AssemblyDoesNotContainDebugWebResource,
assembly, debugResourceName));
}
}
}
}
// 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.Reflection;
using System.Diagnostics;
using System.Collections;
using System.Globalization;
using System.Web.UI;
using System.Web.Resources;
using System.Web.Util;
internal static class WebResourceUtil {
// Maps Pair(resourceName, assembly) to bool
private static readonly Hashtable _assemblyContainsWebResourceCache = Hashtable.Synchronized(new Hashtable());
// Returns true if the assembly contains a Web resource and an embedded resource with
// the sepecified name. Throws exception if assembly contains Web resource but no
// embedded resource, since this is always an error.
public static bool AssemblyContainsWebResource(Assembly assembly, string resourceName) {
// PERF: Special-case known resources in our own assembly
if (assembly == AssemblyCache.SystemWebExtensions) {
return SystemWebExtensionsContainsWebResource(resourceName);
}
// Getting and checking the custom attributes is expensive, so we cache the result
// of the lookup.
Pair key = new Pair(resourceName, assembly);
object assemblyContainsWebResource = _assemblyContainsWebResourceCache[key];
if (assemblyContainsWebResource == null) {
assemblyContainsWebResource = false;
object[] attrs = assembly.GetCustomAttributes(typeof(WebResourceAttribute), false);
foreach (WebResourceAttribute attr in attrs) {
// Resource names are always case-sensitive
if (String.Equals(attr.WebResource, resourceName, StringComparison.Ordinal)) {
if (assembly.GetManifestResourceStream(resourceName) != null) {
assemblyContainsWebResource = true;
break;
}
else {
// Always an error to contain Web resource but not embedded resource.
throw new InvalidOperationException(String.Format(
CultureInfo.CurrentUICulture,
AtlasWeb.WebResourceUtil_AssemblyDoesNotContainEmbeddedResource,
assembly, resourceName));
}
}
}
_assemblyContainsWebResourceCache[key] = assemblyContainsWebResource;
}
return (bool)assemblyContainsWebResource;
}
private static bool SystemWebExtensionsContainsWebResource(string resourceName) {
// PERF: Switching over the length is more performant than switching over the string itself
// or checking equality against each string. When switching over the string itself, the switch
// is compiled to a lookup in a static Dictionary, which is 5-10 times slower than
// switching over the length. Checking equality against each string ranges from equal performance
// to 10 times slower, depending on how early a match is found.
switch (resourceName.Length) {
case 16:
return resourceName == "MicrosoftAjax.js";
case 24:
return resourceName == "MicrosoftAjaxWebForms.js";
case 21:
return resourceName == "MicrosoftAjaxTimer.js";
case 22:
return resourceName == "MicrosoftAjax.debug.js";
case 30:
return resourceName == "MicrosoftAjaxWebForms.debug.js";
case 33:
return resourceName == "MicrosoftAjaxDataService.debug.js";
case 27:
return resourceName == "MicrosoftAjaxTimer.debug.js" ||
resourceName == "MicrosoftAjaxDataService.js";
default:
return false;
}
}
// Throws exception if the assembly does not contain a Web resource and an embedded resource
// with the specified name.
public static void VerifyAssemblyContainsReleaseWebResource(Assembly assembly, string releaseResourceName) {
if (!AssemblyContainsWebResource(assembly, releaseResourceName)) {
throw new InvalidOperationException(String.Format(
CultureInfo.CurrentUICulture,
AtlasWeb.WebResourceUtil_AssemblyDoesNotContainReleaseWebResource,
assembly, releaseResourceName));
}
}
// Throws exception if the assembly does not contain a Web resource and an embedded resource
// with the specified name.
public static void VerifyAssemblyContainsDebugWebResource(Assembly assembly, string debugResourceName) {
if (!AssemblyContainsWebResource(assembly, debugResourceName)) {
throw new InvalidOperationException(String.Format(
CultureInfo.CurrentUICulture,
AtlasWeb.WebResourceUtil_AssemblyDoesNotContainDebugWebResource,
assembly, debugResourceName));
}
}
}
}
// 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
- FilteredDataSetHelper.cs
- ConfigXmlReader.cs
- EntityContainerEntitySet.cs
- ClientFormsIdentity.cs
- OdbcConnectionHandle.cs
- BasicKeyConstraint.cs
- ListItemParagraph.cs
- ProfessionalColorTable.cs
- MaterialGroup.cs
- BooleanAnimationUsingKeyFrames.cs
- IERequestCache.cs
- MorphHelpers.cs
- SiteMapNodeCollection.cs
- ActivationServices.cs
- ContractReference.cs
- xdrvalidator.cs
- XhtmlTextWriter.cs
- CellCreator.cs
- StylusDevice.cs
- Propagator.ExtentPlaceholderCreator.cs
- FormViewInsertedEventArgs.cs
- ComIntegrationManifestGenerator.cs
- XPathBuilder.cs
- ColorIndependentAnimationStorage.cs
- ValidationHelper.cs
- XmlEncodedRawTextWriter.cs
- RenderData.cs
- WebControlParameterProxy.cs
- BaseTemplateCodeDomTreeGenerator.cs
- MemberDescriptor.cs
- SmiEventSink_DeferedProcessing.cs
- ConcurrencyBehavior.cs
- TypeUsage.cs
- GridViewSortEventArgs.cs
- DesignerProperties.cs
- GenericEnumConverter.cs
- ExpressionPrefixAttribute.cs
- PenCursorManager.cs
- MediaScriptCommandRoutedEventArgs.cs
- StylusCollection.cs
- FormViewCommandEventArgs.cs
- SqlAliaser.cs
- ToolboxItemFilterAttribute.cs
- CreateUserErrorEventArgs.cs
- StatusBarItemAutomationPeer.cs
- SystemThemeKey.cs
- RawUIStateInputReport.cs
- TextEffectCollection.cs
- OperationDescription.cs
- DomNameTable.cs
- XPathNode.cs
- OdbcConnectionPoolProviderInfo.cs
- TrackingExtract.cs
- Bezier.cs
- BooleanExpr.cs
- TrackBarRenderer.cs
- Positioning.cs
- ConnectionStringSettingsCollection.cs
- CommonXSendMessage.cs
- StyleBamlTreeBuilder.cs
- HexParser.cs
- Int32AnimationUsingKeyFrames.cs
- SignedPkcs7.cs
- InputMethodStateTypeInfo.cs
- SecurityRuntime.cs
- EventSinkHelperWriter.cs
- DataStorage.cs
- AsyncStreamReader.cs
- KeyedCollection.cs
- InternalUserCancelledException.cs
- CurrentChangedEventManager.cs
- RSAPKCS1SignatureDeformatter.cs
- ToolStripSplitButton.cs
- ContextMenuStrip.cs
- _NtlmClient.cs
- SqlProvider.cs
- TypedReference.cs
- SmiContextFactory.cs
- WinFormsSpinner.cs
- SelfIssuedAuthAsymmetricKey.cs
- XmlnsCache.cs
- DataControlPagerLinkButton.cs
- ViewStateModeByIdAttribute.cs
- BitVec.cs
- DelegateBodyWriter.cs
- PropertyGridEditorPart.cs
- ScrollableControlDesigner.cs
- ApplicationGesture.cs
- ChannelListenerBase.cs
- CommandLibraryHelper.cs
- BypassElementCollection.cs
- BlurEffect.cs
- VoiceObjectToken.cs
- DataGridItem.cs
- BackStopAuthenticationModule.cs
- LinkUtilities.cs
- RootBuilder.cs
- RequestCacheValidator.cs
- CodeSnippetTypeMember.cs
- CompositeCollection.cs