Skip to content
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

GCop659 false alarm #289

Open
sungam3r opened this issue Feb 18, 2019 · 1 comment
Open

GCop659 false alarm #289

sungam3r opened this issue Feb 18, 2019 · 1 comment

Comments

@sungam3r
Copy link
Contributor

   public static void Test()
        {
            var regex = new Regex("blablabla");
            foreach (Match match in regex.Matches("bbb")) // GCop659 Use 'var' instead of explicit type
            {
                var group = match.Groups["ccc"];
                if (group == null)
                    Console.WriteLine("xxx");
            }
        }

After quick fix:

public static void Test()
        {
            var regex = new Regex("blablabla");
            foreach (var match in regex.Matches("bbb"))
            {
                var group = match.Groups["ccc"]; // CS1061	'object' does not contain a definition for 'Groups' and no accessible extension method 'Groups' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)	
                if (group == null)
                    Console.WriteLine("xxx");
            }
        }

GCop659 must take into account duck typing.

@watsonsong
Copy link

I met the same problem when using the XMLDocument~

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

No branches or pull requests

2 participants