This documentation is archived and is not being maintained.

StronglyTypedResourceBuilder.VerifyResourceName Method

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

Namespace: System.Resources.Tools
Assembly: System.Design (in system.design.dll)

public static string VerifyResourceName (
	string key,
	CodeDomProvider provider
)
public static String VerifyResourceName (
	String key, 
	CodeDomProvider provider
)
public static function VerifyResourceName (
	key : String, 
	provider : CodeDomProvider
) : String
Not applicable.

Parameters

key

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

provider

A CodeDomProvider object that specifies the target language to use.

Return Value

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

Exception typeCondition

ArgumentNullException

key or provider is a null reference (Nothing in Visual Basic).

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, a null reference (Nothing in Visual Basic) 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 '!'.

NoteNote:

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.

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0
Show: