Skip to content

Update CloneProvider.cs to support regex ignores#23

Open
aktxyz wants to merge 1 commit into
replaysMike:masterfrom
aktxyz:patch-1
Open

Update CloneProvider.cs to support regex ignores#23
aktxyz wants to merge 1 commit into
replaysMike:masterfrom
aktxyz:patch-1

Conversation

@aktxyz

@aktxyz aktxyz commented Jul 3, 2025

Copy link
Copy Markdown

found this helpful for a project

@aktxyz

aktxyz commented Jul 3, 2025

Copy link
Copy Markdown
Author

had some issues in the PR version ... this is what I am actually using ... sorry about that
somehow caching the regex's would be a nice performance boost

        private bool IgnoreObjectName(string name, string path, CloneConfiguration configuration, ICollection<string> ignorePropertiesOrPaths, IEnumerable<CustomAttributeData> attributes = null)
        {
            if (ignorePropertiesOrPaths == null || ignorePropertiesOrPaths.Count == 0)
                return false;

            if (ignorePropertiesOrPaths?.Contains(name) == true || ignorePropertiesOrPaths?.Contains(path) == true)
                return true;

#if FEATURE_CUSTOM_ATTRIBUTES
            if (attributes?.Any(x => configuration.IgnorePropertiesWithAttributes?.Contains(x.AttributeType.Name) == true) == true)
                return true;
#else
            if (attributes?.Any(x => configuration.IgnorePropertiesWithAttributes?.Contains(x.Constructor.DeclaringType.Name) == true) == true)
                return true;
#endif

            if (ignorePropertiesOrPaths != null)
            {
                var ignorePropertiesOrPathsRe = ignorePropertiesOrPaths.Select(x => (x.Length > 2 && x.StartsWith("/") && x.EndsWith("/")) ? x.Substring(1, x.Length - 2) : "").Where(x => x.Length > 0).ToList();
                foreach (var re in ignorePropertiesOrPathsRe)
                {
                    var rx = new System.Text.RegularExpressions.Regex(re);
                    if (!String.IsNullOrEmpty(name) && rx.IsMatch(name))
                        return true;
                    if (!String.IsNullOrEmpty(path) && rx.IsMatch(path))
                        return true;
                }
            }

            return false;
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant