public AutomationElement GetUpdatedCache(CacheRequest request)
{
if (request == null)
{
throw new ArgumentNullException("request");
}
var updated = SourceManager.GetOrCreateAutomationElement(sourceElement);
if (request == CacheRequest.DefaultRequest)
{
return(updated);
}
if ((request.TreeScope & TreeScope.Element) == TreeScope.Element)
{
foreach (var property in request.CachedProperties)
{
updated.propertyCache [property.Id] =
new CachedValue(updated.GetCurrentPropertyValue(property),
updated.sourceElement.SupportsProperty(property));
}
updated.mode = request.AutomationElementMode;
updated.CacheRequest = request.Clone();
}
if ((request.TreeScope & TreeScope.Children) == TreeScope.Children ||
(request.TreeScope & TreeScope.Descendants) == TreeScope.Descendants)
{
// Modify scope to make sure children include
// themselves, and only include their own
// children if specified by original scope
var childRequest = request.Clone();
childRequest.TreeScope |= TreeScope.Element;
if ((request.TreeScope & TreeScope.Descendants) != TreeScope.Descendants)
{
childRequest.TreeScope ^= TreeScope.Children;
}
updated.cachedChildren = new List <AutomationElement> ();
var child = TreeWalker.RawViewWalker.GetFirstChild(updated, childRequest);
while (child != null)
{
if (childRequest.TreeFilter.AppliesTo(child))
{
child.cachedParent = updated;
updated.cachedChildren.Add(child);
}
child = TreeWalker.RawViewWalker.GetNextSibling(child, childRequest);
}
}
return(updated);
}