Click or drag to resize

ResourceManagementClient.GetResourceByKey Method (String, String, Object, IEnumerable<String>)

Gets a resource from the resource management service using a unique attribute and value combination, retrieving the specified 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,
	IEnumerable<string> attributesToGet
)

Parameters

objectType
Type: System.String
The type of object to retrieve
attributeName
Type: System.String
The name of the attribute used as the key
value
Type: System.Object
The value of the attribute
attributesToGet
Type: System.Collections.Generic.IEnumerable<String>
The list of attributes to retrieve

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