This namespace defines invokers. Invokers are objects that generate syntax to invoke methods or access properties, fields, or events.
Example
The following aspect displays the value of all fields and automatic properties.
1using Metalama.Framework.Aspects;
2using System;
3
4namespace Doc.PrintFieldValues;
5
6internal class PrintFieldValuesAttribute : OverrideMethodAspect
7{
8 public override dynamic? OverrideMethod()
9 {
10 foreach ( var fieldOrProperty in meta.Target.Type.FieldsAndProperties )
11 {
12 if ( fieldOrProperty is { IsImplicitlyDeclared: false, IsAutoPropertyOrField: true } )
13 {
14 var value = fieldOrProperty.Value;
15 Console.WriteLine( $"{fieldOrProperty.Name}={value}" );
16 }
17 }
18
19 return meta.Proceed();
20 }
21}
1namespace Doc.PrintFieldValues;
2
3internal class Foo
4{
5 private readonly int _a;
6
7 public string? B { get; set; }
8
9 private static readonly int _c;
10
11 [PrintFieldValues]
12 public void Bar() { }
13}
1using System;
2
3namespace Doc.PrintFieldValues;
4
5internal class Foo
6{
7 private readonly int _a;
8
9 public string? B { get; set; }
10
11 private static readonly int _c;
12
13 [PrintFieldValues]
14 public void Bar()
15 {
16 var value = _a;
17 Console.WriteLine($"_a={value}");
18 var value_1 = _c;
19 Console.WriteLine($"_c={value_1}");
20 var value_2 = B;
21 Console.WriteLine($"B={value_2}");
22 }
23}
Namespace members
Interfaces
IConstructorInvoker
Allows generating run-time code that invokes a constructor when you have its compile-time IConstructor representation.
IEventInvoker
Allows generating run-time code that adds handlers to, removes handlers from, or raises an event when you have its compile-time IEvent representation.
IFieldOrPropertyInvoker
Allows generating run-time code that accesses a field or property when you have its compile-time IFieldOrProperty representation.
IIndexerInvoker
Allows generating run-time code that accesses indexer items when you have the compile-time IIndexer representation.
IMethodInvoker
Allows generating run-time code that invokes a method when you have its compile-time IMethod representation.
Enums
InvokerOptions
Options that influence the behavior of invokers, i.e. IMethodInvoker, IFieldOrPropertyInvoker, IEventInvoker or IIndexerInvoker.