-
Notifications
You must be signed in to change notification settings - Fork 7
Can I make aspect on Field setted? #1
Comments
Yes it's possible to create such aspect, but it would require to create additional modifications inside Aspect Processing. The generic problem is that Fields are not considered methods (which are supported atm.), so you need to scan all methods on all types in all assemblies in project and update field set method to implement similar event. It's really complicated... From the exact point of view the UAOP copies the method body into new method and replaces old method with new body that executes wrapper which later uses System.Reflection to invoke copied method (you can check assemblies using decompiler like DotPeek). This is not possible in fields, because field uses stfld stsfld ldfld and ldfld IL codes, which are not call/callvirt for methods (like Properties or Events). SOLUTION: public class Foo {
private string name;
public string Name { get; [Observable] set; }
} And then use [Observable] with OnMethodEnter/Exit Aspects, because set_Name is an method that is created by compiler during runtime so it can be modified by UAOP. This is the best solution rather than scanning all method bodies in all types ;) |
So your code should look like this: public class Foo
{
public string Name { get; [Observable] set; }
}
public class ObservableAttribute : Attribute, IMethodEnterAspect
{
public void OnMethodEnter(MethodExecutionArguments args)
{
Debug.Log("Foo has been set");
}
} Beware: this excutes BEFORE method name is changed. If you want to execute it AFTER, you need to use IMethodExitAspect with OnMethodExit implementable. |
…support Added support for multiple dll files injection
I'm considering such a attribute feature like this:
but I need a OnFieldSetted aspect, is it possible?
The text was updated successfully, but these errors were encountered: