Click or drag to resize

ResourceManagementClientGetResourceByKey Method (String, String, Object, CultureInfo)

Gets a resource from the resource management service using a unique attribute and value combination, retrieving all attributes for the resource

Namespace:  Lithnet.ResourceManagement.Client
Assembly:  Lithnet.ResourceManagement.Client (in Lithnet.ResourceManagement.Client.dll) Version: 1.0.6435.24467
Syntax
public ResourceObject GetResourceByKey(
	string objectType,
	string attributeName,
	Object value,
	CultureInfo locale
)

Parameters

objectType
Type: SystemString
The type of object to retrieve
attributeName
Type: SystemString
The name of the attribute used as the key
value
Type: SystemObject
The value of the attribute
locale
Type: System.GlobalizationCultureInfo
The culture to use to request a localized version of the object

Return Value

Type: ResourceObject
A resource that matches the specified criteria, or null of no object was found
Exceptions
ExceptionCondition
TooManyResultsExceptionThe method will throw this exception when more that one match was found for the specified criteria
Examples
The following example shows how get a user by its AccountName attribute
Example
public ResourceObject GetPersonByUsername(string username)
{
    ResourceManagementClient client = new ResourceManagementClient();

    // Specify the list of attributes that we are interested in
    List<string> attributesToGet = new List<string>() { "DisplayName", "FirstName", "LastName" };

    try
    {
        ResourceObject resource = client.GetResourceByKey("Person", "AccountName", username, attributesToGet);

        if (resource == null)
        {
            // The resource was not found, throw an exception
            throw new ResourceNotFoundException();
        }

        return resource;
    }
    catch (TooManyResultsException)
    {
        // More than one match was found
        throw;
    }
}
See Also