Code:
/ DotNET / DotNET / 8.0 / untmp / Orcas / RTM / ndp / fx / src / xsp / System / Web / Extensions / ui / ScriptResourceInfo.cs / 2 / ScriptResourceInfo.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.UI { using System; using System.Collections; using System.Collections.Generic; using System.Globalization; using System.Reflection; using System.Text; using System.Web.Resources; using System.Web.Util; internal class ScriptResourceInfo { private string _contentType; private bool _performSubstitution; private string _scriptName; private string _scriptResourceName; private string _typeName; private bool _isDebug; private static readonly IDictionary _scriptCache = Hashtable.Synchronized(new Hashtable()); private static readonly IDictionary _duplicateScriptAttributesChecked = Hashtable.Synchronized(new Hashtable()); public static readonly ScriptResourceInfo Empty = new ScriptResourceInfo(); public ScriptResourceInfo() { _contentType = "application/x-javascript"; } public ScriptResourceInfo(ScriptResourceAttribute attr) : this() { _scriptName = attr.ScriptName; _scriptResourceName = attr.ScriptResourceName; _typeName = attr.TypeName; } public string ContentType { get { return _contentType; } set { _contentType = value; } } public bool IsDebug { get { return _isDebug; } set { _isDebug = value; } } public bool PerformSubstitution { get { return _performSubstitution; } set { _performSubstitution = value; } } public string ScriptName { get { return _scriptName; } set { _scriptName = value; } } public string ScriptResourceName { get { return _scriptResourceName; } } public string TypeName { get { return _typeName; } } public static ScriptResourceInfo GetInstance(Assembly assembly, string resourceName) { // The first time this API is called, check for attributes that point to the same script if (!_duplicateScriptAttributesChecked.Contains(assembly)) { Dictionaryscripts = new Dictionary (); foreach (ScriptResourceAttribute attr in assembly.GetCustomAttributes(typeof(ScriptResourceAttribute), false)) { string scriptName = attr.ScriptName; if (scripts.ContainsKey(scriptName)) { throw new InvalidOperationException( String.Format(CultureInfo.CurrentCulture, AtlasWeb.ScriptResourceHandler_DuplicateScriptResources, scriptName, assembly.GetName())); } scripts.Add(scriptName, true); } _duplicateScriptAttributesChecked[assembly] = true; } Pair cacheKey = new Pair (assembly, resourceName); ScriptResourceInfo resourceInfo = (ScriptResourceInfo)_scriptCache[cacheKey]; if (resourceInfo == null) { resourceInfo = ScriptResourceInfo.Empty; object[] attrs = assembly.GetCustomAttributes(typeof(ScriptResourceAttribute), false); // First look for a script resource attribute with that name for (int i = 0; i < attrs.Length; i++) { ScriptResourceAttribute sra = (ScriptResourceAttribute)attrs[i]; if (String.Equals(sra.ScriptName, resourceName, StringComparison.Ordinal)) { resourceInfo = new ScriptResourceInfo(sra); break; } } // Look for a web resource with that name, to get additional info if any attrs = assembly.GetCustomAttributes(typeof(WebResourceAttribute), false); for (int i = 0; i < attrs.Length; i++) { WebResourceAttribute wra = (WebResourceAttribute)attrs[i]; if (String.Equals(wra.WebResource, resourceName, StringComparison.Ordinal)) { if (resourceInfo == ScriptResourceInfo.Empty) { resourceInfo = new ScriptResourceInfo(); resourceInfo.ScriptName = resourceName; } resourceInfo.ContentType = wra.ContentType; resourceInfo.PerformSubstitution = wra.PerformSubstitution; break; } } resourceInfo.IsDebug = resourceName.EndsWith(".debug.js", StringComparison.OrdinalIgnoreCase); // Cache the results so we don't have to do this again _scriptCache[cacheKey] = resourceInfo; } return resourceInfo; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SingleAnimationBase.cs
- AccessedThroughPropertyAttribute.cs
- InheritablePropertyChangeInfo.cs
- Int32.cs
- OdbcPermission.cs
- MaskInputRejectedEventArgs.cs
- SwitchLevelAttribute.cs
- GridProviderWrapper.cs
- DataSetSchema.cs
- CompiledELinqQueryState.cs
- OpenTypeLayoutCache.cs
- XmlEntity.cs
- ChangeNode.cs
- DataBoundControlAdapter.cs
- BamlTreeNode.cs
- SqlCacheDependencyDatabase.cs
- InvalidProgramException.cs
- BehaviorEditorPart.cs
- AttachedProperty.cs
- LazyTextWriterCreator.cs
- Popup.cs
- SecurityState.cs
- Int64.cs
- ObjectParameterCollection.cs
- FlagsAttribute.cs
- SecUtil.cs
- UIPropertyMetadata.cs
- HtmlSelectionListAdapter.cs
- ImageCodecInfoPrivate.cs
- DictationGrammar.cs
- ConstraintStruct.cs
- CompiledELinqQueryState.cs
- Int32.cs
- Single.cs
- XPathDocumentBuilder.cs
- MissingSatelliteAssemblyException.cs
- ResolvedKeyFrameEntry.cs
- MouseGestureValueSerializer.cs
- RootProfilePropertySettingsCollection.cs
- LabelLiteral.cs
- EncryptedType.cs
- BufferedGraphicsManager.cs
- PropertyItemInternal.cs
- MimeFormatter.cs
- GridProviderWrapper.cs
- SmtpReplyReader.cs
- Attachment.cs
- StorageRoot.cs
- Parameter.cs
- x509utils.cs
- ControlCachePolicy.cs
- HeaderCollection.cs
- XmlKeywords.cs
- PropertyTab.cs
- RsaKeyGen.cs
- DesignerDeviceConfig.cs
- ImageBrush.cs
- externdll.cs
- PageTheme.cs
- SQLMembershipProvider.cs
- StateChangeEvent.cs
- MimeReflector.cs
- PlacementWorkspace.cs
- ObservableDictionary.cs
- TextBoxDesigner.cs
- DataGridTable.cs
- UnsafeNativeMethods.cs
- NativeMethods.cs
- OutputChannel.cs
- SystemGatewayIPAddressInformation.cs
- MDIWindowDialog.cs
- CachedBitmap.cs
- TabletDevice.cs
- FocusChangedEventArgs.cs
- WasHttpModulesInstallComponent.cs
- _ShellExpression.cs
- DataListItem.cs
- ConstructorExpr.cs
- AuthenticationSection.cs
- DrawListViewItemEventArgs.cs
- SignedPkcs7.cs
- TypeContext.cs
- TableRowsCollectionEditor.cs
- ManagementClass.cs
- ValuePatternIdentifiers.cs
- FunctionImportElement.cs
- SiblingIterators.cs
- WebPartEditorOkVerb.cs
- FileNotFoundException.cs
- PersistenceTypeAttribute.cs
- OLEDB_Enum.cs
- EditorServiceContext.cs
- PasswordRecovery.cs
- ToolBarOverflowPanel.cs
- StorageBasedPackageProperties.cs
- XsdValidatingReader.cs
- Transform.cs
- RepeaterItemCollection.cs
- ImpersonateTokenRef.cs
- Converter.cs