private static T GetPlaceholderMatchedValue <T>(IStructuralMatchResult matchResult, string placeholderName)
            where T : class
        {
            object value = matchResult.GetMatch(placeholderName);

            if (value is T result)
            {
                return(result);
            }

            return(null);
        }
        private static IStructuralMatchResult TreeNodeMatched(
            IStructuralMatcher matcher,
            ITreeNode treeNode,
            ITreeNode initialTreeNode,
            object placeholdersBindingObject,
            PropertyInfo[] placeholderProperties)
        {
            IStructuralMatchResult matchResult = matcher.Match(treeNode);

            if (matchResult.Matched && matchResult.MatchedElement.Contains(initialTreeNode))
            {
                var propertyToMatchedObjectPairs = new List <(PropertyInfo property, object matchedObject)>();

                foreach (PropertyInfo property in placeholderProperties)
                {
                    object matchedObject = matchResult.GetMatch(property.Name);
                    if (property.PropertyType.IsInstanceOfType(matchedObject))
                    {
                        propertyToMatchedObjectPairs.Add((property, matchedObject));
                    }
                    else
                    {
                        return(StructuralMatchResult.NOT_MATCHED);
                    }
                }

                foreach ((PropertyInfo property, object matchedObject) in propertyToMatchedObjectPairs)
                {
                    property.SetValue(placeholdersBindingObject, matchedObject);
                }

                return(matchResult);
            }

            return(StructuralMatchResult.NOT_MATCHED);
        }