mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
docs: comptime method params (#22252)
This commit is contained in:
parent
c5837e4f89
commit
13fdc724a7
1 changed files with 25 additions and 1 deletions
24
doc/docs.md
24
doc/docs.md
|
@ -6065,6 +6065,30 @@ fn main() {
|
|||
// test2 returns string: foo
|
||||
```
|
||||
|
||||
#### <h4 id="comptime-method-params">.params</h4>
|
||||
|
||||
You can retrieve information about struct method params.
|
||||
|
||||
```v
|
||||
struct Test {
|
||||
}
|
||||
|
||||
fn (t Test) foo(arg1 int, arg2 string) {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
$for m in Test.methods {
|
||||
$for param in m.params {
|
||||
println('${typeof(param.typ).name}: ${param.name}')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Output:
|
||||
// int: arg1
|
||||
// string: arg2
|
||||
```
|
||||
|
||||
See [`examples/compiletime/reflection.v`](/examples/compiletime/reflection.v)
|
||||
for a more complete example.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue