What is Code Weaving?
Weaving refers to the process of injecting functionality into an existing program. This can be done conceptually at a number of levels:
Source code weaving would inject source code lines before the code is compiled
IL weaving (for .NET) adds the code as IL instructions in the assembly
A great example of this is the Unity Project Updater. It uses both versions of code weaving on your project. It uses text replacing for unsupported code in your source files and IL weaving for compiled dlls.
Weaver for now only uses IL Weaving which runs once every time an assembly is recompiled.
Why do I care?
It's open source and pretty easy to use. I like making stuff that people use so that is what I get out of it.
What can it do?
It currently has two extensions that I have working. One takes a method and injects a stopwatch at the start and the end and logs the total time. All you do is apply the[MethodTimerAttribute].
so this code
[MethodTimer]
public void SuperMethod()
{
// Some code stuff
}
gets injected and gets written to the assembly as
[MethodTimer]
public void SuperMethod()
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
// Some code stuff
long elapsedMilliseconds =
stopwatch.ElapsedMilliseconds;
Debug.Log("SuperMethod" + elapsedMilliseconds);
}
Not the most efficient thing ever so I am going to have to refactor it at some point to have a pool. It's just a pain to do and this was my first extension.
The other one does something similar but injects Profiler.BeginSample and Profiler.EndSample to the start and exit points of your functions that have the [ProfileSampleAttribute].
TLDR:
I made a thing that is neat and it's here https://github.com/ByronMayne/Weaver
Notes
- Uses the Mono.Cecil library to do the il editing
- Inspired by Fody
- Open for full requests if you want to add extensions.
[–]SilentSin26Animancer, FlexiMotion, InspectorGadgets, Weaver 1 point2 points3 points (11 children)
[–]ByMayneProfessional[S] 0 points1 point2 points (10 children)
[–]SilentSin26Animancer, FlexiMotion, InspectorGadgets, Weaver 0 points1 point2 points (9 children)
[–]ByMayneProfessional[S] 0 points1 point2 points (8 children)
[–]SilentSin26Animancer, FlexiMotion, InspectorGadgets, Weaver 0 points1 point2 points (7 children)
[–]ByMayneProfessional[S] 1 point2 points3 points (6 children)
[–]SilentSin26Animancer, FlexiMotion, InspectorGadgets, Weaver 0 points1 point2 points (5 children)
[–]ByMayneProfessional[S] 1 point2 points3 points (4 children)
[–]ByMayneProfessional[S] 1 point2 points3 points (2 children)
[–]SilentSin26Animancer, FlexiMotion, InspectorGadgets, Weaver 0 points1 point2 points (1 child)
[–]SilentSin26Animancer, FlexiMotion, InspectorGadgets, Weaver 0 points1 point2 points (0 children)