ScriptResourceAttribute Classe
Definição
Define um recurso em um assembly para ser usado de um arquivo de script de cliente.Defines a resource in an assembly to be used from a client script file. Essa classe não pode ser herdada.This class cannot be inherited.
public ref class ScriptResourceAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple=true)]
public sealed class ScriptResourceAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple=true)>]
type ScriptResourceAttribute = class
inherit Attribute
Public NotInheritable Class ScriptResourceAttribute
Inherits Attribute
- Herança
- Atributos
Exemplos
O exemplo a seguir mostra um ScriptResourceAttribute atributo para um arquivo de script chamado CheckAnswer.js que usa recursos dos arquivos de recurso VerificationResources.The following example shows a ScriptResourceAttribute attribute for a script file named CheckAnswer.js that uses resources from the VerificationResources resource files. O nome Answer é usado para fazer referência a esses recursos.The name Answer is used to reference these resources.
[assembly: System.Web.UI.WebResource("LocalizingScriptResources.CheckAnswer.js", "application/x-javascript")]
[assembly: System.Web.UI.ScriptResource("LocalizingScriptResources.CheckAnswer.js", "LocalizingScriptResources.VerificationResources", "Answer")]
<Assembly: System.Web.UI.WebResource("LocalizingScriptResources.CheckAnswer.js", "application/x-javascript")>
<Assembly: System.Web.UI.ScriptResource("LocalizingScriptResources.CheckAnswer.js", "LocalizingScriptResources.VerificationResources", "Answer")>
O exemplo a seguir mostra como usar os recursos no script de cliente.The following example shows how to use the resources in client script. As chaves de recurso ( Correct e Incorrect ) são prefixadas com Answer para identificar a definição de recurso de script que contém os valores.The resource keys (Correct and Incorrect) are prefixed with Answer to identify the script resource definition that contains the values.
function CheckAnswer()
{
var firstInt = $get('firstNumber').innerText;
var secondInt = $get('secondNumber').innerText;
var userAnswer = $get('userAnswer');
if ((Number.parseLocale(firstInt) + Number.parseLocale(secondInt)) == userAnswer.value)
{
alert(Answer.Correct);
return true;
}
else
{
alert(Answer.Incorrect);
return false;
}
}
Comentários
A ScriptResourceAttribute classe é válida somente quando você a usa em declarações de assembly.The ScriptResourceAttribute class is valid only when you use it in assembly declarations. Você o usa para habilitar um recurso de script inserido especificado em um assembly.You use it to enable a specified embedded script resource in an assembly. Você pode definir o nome da biblioteca de script incorporado, o nome do arquivo de recurso para a biblioteca de script e o nome que é usado em um arquivo de script para recuperar os valores de recurso.You can define the name of the embedded script library, the name of the resource file for the script library, and the name that is used in a script file for retrieving the resource values. A ScriptManager classe usa as propriedades no ScriptResourceAttribute para determinar o nome de recurso correto para uma biblioteca de scripts.The ScriptManager class uses the properties in ScriptResourceAttribute to determine the correct resource name for a script library. A TypeName propriedade é usada com uma chave de recurso para especificar um recurso.The TypeName property is used with a resource key to specify a resource.
Observação
A ScriptResourceAttribute classe pode ser usada somente para identificar recursos baseados em texto para arquivos JavaScript.The ScriptResourceAttribute class can be used only to identify text-based resources for JavaScript files. Para associar um arquivo de imagem localizada (binário) a uma cultura específica, considere armazenar apenas sua URL como um recurso localizado que, em seguida, seja resolvido e carregado no script.To associate a localized image (binary) file with a particular culture, consider storing only its URL as a localized resource, which then be resolved and loaded in script.
Construtores
| ScriptResourceAttribute(String) |
Inicializa uma nova instância da classe ScriptResourceAttribute.Initializes a new instance of the ScriptResourceAttribute class. |
| ScriptResourceAttribute(String, String, String) |
Inicializa uma nova instância da classe ScriptResourceAttribute.Initializes a new instance of the ScriptResourceAttribute class. |
Propriedades
| ScriptName |
Obtém o nome da biblioteca de script.Gets the name of the script library. |
| ScriptResourceName |
Obsoleto.
Obtém o nome do arquivo de recurso da biblioteca de script.Gets the name of the resource file for the script library. |
| StringResourceClientTypeName |
Obtém o nome do tipo de cliente a ser criado para os valores no arquivo do recurso.Gets the name of the client type to create for the values in the resource file. |
| StringResourceName |
Obtém o nome do arquivo de recurso da biblioteca de script.Gets the name of the resource file for the script library. |
| TypeId |
Quando implementado em uma classe derivada, obtém um identificador exclusivo para este Attribute.When implemented in a derived class, gets a unique identifier for this Attribute. (Herdado de Attribute) |
| TypeName |
Obsoleto.
Obtém o nome usado ao recuperar os valores no arquivo do recurso.Gets the name that is used when retrieving the values in the resource file. |
Métodos
| Equals(Object) |
Retorna um valor que indica se essa instância é igual a um objeto especificado.Returns a value that indicates whether this instance is equal to a specified object. (Herdado de Attribute) |
| GetHashCode() |
Retorna o código hash para a instância.Returns the hash code for this instance. (Herdado de Attribute) |
| GetType() |
Obtém o Type da instância atual.Gets the Type of the current instance. (Herdado de Object) |
| IsDefaultAttribute() |
Quando substituído em uma classe derivada, indica se o valor dessa instância é o valor padrão para a classe derivada.When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class. (Herdado de Attribute) |
| Match(Object) |
Quando substituído em uma classe derivada, retorna um valor que indica se essa instância é igual a um objeto especificado.When overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Herdado de Attribute) |
| MemberwiseClone() |
Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object. (Herdado de Object) |
| ToString() |
Retorna uma cadeia de caracteres que representa o objeto atual.Returns a string that represents the current object. (Herdado de Object) |
Implantações explícitas de interface
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
Mapeia um conjunto de nomes para um conjunto correspondente de identificadores de expedição.Maps a set of names to a corresponding set of dispatch identifiers. (Herdado de Attribute) |
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
Recupera as informações de tipo para um objeto, que pode ser usado para obter as informações de tipo para uma interface.Retrieves the type information for an object, which can be used to get the type information for an interface. (Herdado de Attribute) |
| _Attribute.GetTypeInfoCount(UInt32) |
Retorna o número de interfaces de informações do tipo que um objeto fornece (0 ou 1).Retrieves the number of type information interfaces that an object provides (either 0 or 1). (Herdado de Attribute) |
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
Fornece acesso a propriedades e métodos expostos por um objeto.Provides access to properties and methods exposed by an object. (Herdado de Attribute) |