Edit

Share via


StronglyTypedResourceBuilder.VerifyResourceName Method

Definition

Generates a valid resource string based on the specified input string and code provider.

public:
 static System::String ^ VerifyResourceName(System::String ^ key, System::CodeDom::Compiler::CodeDomProvider ^ provider);
public static string VerifyResourceName (string key, System.CodeDom.Compiler.CodeDomProvider provider);
public static string? VerifyResourceName (string key, System.CodeDom.Compiler.CodeDomProvider provider);
static member VerifyResourceName : string * System.CodeDom.Compiler.CodeDomProvider -> string
Public Shared Function VerifyResourceName (key As String, provider As CodeDomProvider) As String

Parameters

key
String

The string to verify and, if necessary, convert to a valid resource name.

provider
CodeDomProvider

A CodeDomProvider object that specifies the target language to use.

Returns

A valid resource name derived from the key parameter. Any invalid tokens are replaced with the underscore (_) character, or null if the derived string still contains invalid characters according to the language specified by the provider parameter.

Exceptions

key or provider is null.

Remarks

If the key parameter is a valid string of characters, that string is returned. If the key parameter is an invalid string or a string that contains invalid characters, the VerifyResourceName method attempts to generate a valid string based on the key and provider parameters. If a valid string can be generated, that string is returned; otherwise, null is returned.

If the key parameter is an empty string (""), a string that consists of a single underscore character (_) is returned. If the key parameter is not an empty string, the VerifyResourceName method compares each character in the string to a set of invalid tokens based on the language specified by the provider parameter. Any invalid character in the string is replaced with an underscore character. The characters that will be replaced with an underscore are as follows:

' ' (space), U+00A0 (non-breaking space), '.' (period), ',' (comma), ';' (semicolon), '|', '~', '@', '#', '%', '^', '&', '*', '+', '-', '/', '\', '<', '>', '?', '[', ']', '(', ')', '{', '}', '"' (quote), ''' (apostrophe), ':', and '!'.

Note

Strongly typed resources do not allow the use of language keywords (such as if, for, and so on) as resource key names. However, the System.CodeDom design pattern allows the use of language keywords by prefixing the keyword with the underscore character. The VerifyResourceName method calls the CreateValidIdentifier method to enforce this design. For example, if you use a resource name that is the same as a language keyword, such as for, the name appears as _for in the generated strongly typed resource class.

Applies to