How to match specific modifiers of a method? #1058
Answered
by
HerringtonDarkholme
dotjpg3141
asked this question in
Q&A
-
How to match specific modifiers of a method? In this example I want to match all public methods. C# class Bar {
public static async void Fii() {
}
void Foo() {
}
} Rule: language: csharp
rule:
kind: method_declaration
has:
field: modifier
regex: ^public$ |
Beta Was this translation helpful? Give feedback.
Answered by
HerringtonDarkholme
Apr 17, 2024
Replies: 1 comment 4 replies
-
field and kind are different. https://ast-grep.github.io/advanced/core-concepts.html#kind-vs-field language: csharp
rule:
kind: method_declaration
has:
kind: modifier
regex: ^public$ |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
dotjpg3141
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
field and kind are different.
https://ast-grep.github.io/advanced/core-concepts.html#kind-vs-field
https://ast-grep.github.io/playground.html#eyJtb2RlIjoiQ29uZmlnIiwibGFuZyI6ImNzaGFycCIsInF1ZXJ5IjoiY29uc29sZS5sb2coJE1BVENIKSIsInJld3JpdGUiOiJsb2dnZXIubG9nKCRNQVRDSCkiLCJjb25maWciOiJsYW5ndWFnZTogY3NoYXJwXG5ydWxlOlxuICBraW5kOiBtZXRob2RfZGVjbGFyYXRpb25cbiAgaGFzOlxuICAgIGtpbmQ6IG1vZGlmaWVyXG4gICAgcmVnZXg6IF5wdWJsaWMkXG4gICAgIiwic291cmNlIjoiY2xhc3MgQmFyIHtcbiAgICBwdWJsaWMgc3RhdGljIGFzeW5jIHZvaWQgRmlpKCkge1xuICAgIH1cblxuICAgIHZvaWQgRm9vKCkge1xuICAgIH1cbn0ifQ==