Skip to content

Replace ArrayList from FrameworkElement with List<TemplateKey> #10700

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,9 @@ public FindResourceHelper(object name)


// Find a data template (or table template) resource
internal static object FindTemplateResourceFromAppOrSystem(DependencyObject target, ArrayList keys, int exactMatch, ref int bestMatch)
internal static object FindTemplateResourceFromAppOrSystem(DependencyObject target, List<TemplateKey> keys, int exactMatch, ref int bestMatch)
{
object resource = null;
int k;

// Comment out below three lines code.
// For now, we will always get the resource from Application level
Expand All @@ -86,7 +85,7 @@ internal static object FindTemplateResourceFromAppOrSystem(DependencyObject targ
if (app != null)
{
// If the element is rooted to a Window and App exists, defer to App.
for (k = 0; k < bestMatch; ++k)
for (int k = 0; k < bestMatch; k++)
{
object appResource = Application.Current.FindResourceInternal(keys[k]);
if (appResource != null)
Expand All @@ -105,7 +104,7 @@ internal static object FindTemplateResourceFromAppOrSystem(DependencyObject targ
if (bestMatch >= exactMatch)
{
// Try the system resource collection.
for (k = 0; k < bestMatch; ++k)
for (int k = 0; k < bestMatch; k++)
{
object sysResource = SystemResources.FindResourceInternal(keys[k]);
if (sysResource != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1404,30 +1404,26 @@ internal static object FindResourceInTree(
internal static object FindTemplateResourceInternal(DependencyObject target, object item, Type templateType)
{
// Data styling doesn't apply to UIElement (bug 1007133).
if (item == null || (item is UIElement))
if (item is null or UIElement)
{
return null;
}

Type type;
object dataType = ContentPresenter.DataTypeForItem(item, target, out type);

ArrayList keys = new ArrayList();
object dataType = ContentPresenter.DataTypeForItem(item, target, out Type type);

// construct the list of acceptable keys, in priority order
int exactMatch = -1; // number of entries that count as an exact match

// add compound keys for the dataType and all its base types
List<TemplateKey> keys = new();

// number of entries that count as an exact match
int exactMatch = -1;

while (dataType != null)
{
object key = null;
if (templateType == typeof(ItemContainerTemplate))
key = new ItemContainerTemplateKey(dataType);
keys.Add(new ItemContainerTemplateKey(dataType));
else if (templateType == typeof(DataTemplate))
key = new DataTemplateKey(dataType);

if (key != null)
keys.Add(key);
keys.Add(new DataTemplateKey(dataType));

// all keys added for the given item type itself count as an exact match
if (exactMatch == -1)
Expand All @@ -1436,7 +1432,7 @@ internal static object FindTemplateResourceInternal(DependencyObject target, obj
if (type != null)
{
type = type.BaseType;
if (type == typeof(Object)) // don't search for Object - perf
if (type == typeof(object)) // don't search for Object - perf
type = null;
}

Expand All @@ -1461,14 +1457,14 @@ internal static object FindTemplateResourceInternal(DependencyObject target, obj
}

// Search the parent chain for a [Data|Table]Template in a ResourceDictionary.
private static object FindTemplateResourceInTree(DependencyObject target, ArrayList keys, int exactMatch, ref int bestMatch)
private static object FindTemplateResourceInTree(DependencyObject target, List<TemplateKey> keys, int exactMatch, ref int bestMatch)
{
Debug.Assert(target != null, "Don't call FindTemplateResource with a null target object");

ResourceDictionary table;
object resource = null;

FrameworkObject fo = new FrameworkObject(target);
FrameworkObject fo = new(target);
Debug.Assert(fo.IsValid, "Don't call FindTemplateResource with a target object that is neither a FrameworkElement nor a FrameworkContentElement");

while (fo.IsValid)
Expand All @@ -1482,9 +1478,9 @@ private static object FindTemplateResourceInTree(DependencyObject target, ArrayL
// Fetch the ResourceDictionary
// for the given target element
table = GetInstanceResourceDictionary(fo.FE, fo.FCE);
if( table != null )
if (table != null)
{
candidate = FindBestMatchInResourceDictionary( table, keys, exactMatch, ref bestMatch );
candidate = FindBestMatchInResourceDictionary(table, keys, exactMatch, ref bestMatch);
if (candidate != null)
{
resource = candidate;
Expand All @@ -1501,9 +1497,9 @@ private static object FindTemplateResourceInTree(DependencyObject target, ArrayL
// -------------------------------------------

table = GetStyleResourceDictionary(fo.FE, fo.FCE);
if( table != null )
if (table != null)
{
candidate = FindBestMatchInResourceDictionary( table, keys, exactMatch, ref bestMatch );
candidate = FindBestMatchInResourceDictionary(table, keys, exactMatch, ref bestMatch);
if (candidate != null)
{
resource = candidate;
Expand All @@ -1520,9 +1516,9 @@ private static object FindTemplateResourceInTree(DependencyObject target, ArrayL
// -------------------------------------------

table = GetThemeStyleResourceDictionary(fo.FE, fo.FCE);
if( table != null )
if (table != null)
{
candidate = FindBestMatchInResourceDictionary( table, keys, exactMatch, ref bestMatch );
candidate = FindBestMatchInResourceDictionary(table, keys, exactMatch, ref bestMatch);
if (candidate != null)
{
resource = candidate;
Expand All @@ -1539,9 +1535,9 @@ private static object FindTemplateResourceInTree(DependencyObject target, ArrayL
// -------------------------------------------

table = GetTemplateResourceDictionary(fo.FE, fo.FCE);
if( table != null )
if (table != null)
{
candidate = FindBestMatchInResourceDictionary( table, keys, exactMatch, ref bestMatch );
candidate = FindBestMatchInResourceDictionary(table, keys, exactMatch, ref bestMatch);
if (candidate != null)
{
resource = candidate;
Expand Down Expand Up @@ -1580,16 +1576,14 @@ private static object FindTemplateResourceInTree(DependencyObject target, ArrayL

// Given a ResourceDictionary and a set of keys, try to find the best
// match in the resource dictionary.
private static object FindBestMatchInResourceDictionary(
ResourceDictionary table, ArrayList keys, int exactMatch, ref int bestMatch)
private static object FindBestMatchInResourceDictionary(ResourceDictionary table, List<TemplateKey> keys, int exactMatch, ref int bestMatch)
{
object resource = null;
int k;

// Search target element's ResourceDictionary for the resource
if (table != null)
{
for (k = 0; k < bestMatch; ++k)
for (int k = 0; k < bestMatch; k++)
{
object candidate = table[keys[k]];
if (candidate != null)
Expand Down Expand Up @@ -3135,17 +3129,11 @@ internal bool InvalidateAutomationAncestorsCoreHelper(Stack<DependencyObject> br
return continueInvalidation;
}

internal static bool InvalidateAutomationIntermediateElements(
DependencyObject mergePoint,
DependencyObject modelTreeNode)
internal static bool InvalidateAutomationIntermediateElements(DependencyObject mergePoint, DependencyObject modelTreeNode)
{
UIElement e = null;
ContentElement ce = null;
UIElement3D e3d = null;

while (modelTreeNode != null && modelTreeNode != mergePoint)
{
if (!UIElementHelper.InvalidateAutomationPeer(modelTreeNode, out e, out ce, out e3d))
if (!UIElementHelper.InvalidateAutomationPeer(modelTreeNode, out _, out _, out _))
{
return false;
}
Expand Down