Export (0) Print
Expand All

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
)

Parameters

key
Type: System.String

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

provider
Type: System.CodeDom.Compiler.CodeDomProvider

A CodeDomProvider object that specifies the target language to use.

Return Value

Type: System.String
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.

ExceptionCondition
ArgumentNullException

key or provider is null.

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 '!'.

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.

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft