Skip to content

Add expression based CodeMatch.LoadField/StoreField #756

@normanr

Description

@normanr

Is your feature request related to a problem? Please describe.
It would be nice to be able to match load/save of fields with an expression, instead of a FieldInfo.

Describe the solution you'd like
I think something like CodeMatch.LoadsField(() => default(MyClass).Field or CodeMatch.LoadsField(() => MyStaticClass.StaticField) would be nice (and for CodeMatch.StoresField too).

Describe alternatives you've considered
I think the alternative is to use something like CodeMatch.LoadsField(typeof(MyClass).Field(nameof(MyClass.Field))) or CodeMatch.LoadsField(typeof(MyStaticClass).Field(nameof(MyStaticClass.StaticField))), but the typeof and repetition of the class name make the code harder to read.

Additional context
There's already a LambdaExpression/Expression<Action> matcher for CodeMatch.Calls. It would just require SymbolExtensions to support extracting the Member FieldInfo from the MemberExpression

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions