Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fody code weaving made fun.

Similar presentations


Presentation on theme: "Fody code weaving made fun."— Presentation transcript:

1 Fody code weaving made fun

2 Tomasz Pluskiewicz Wrocław MakoLab S.A. @tpluscode About me

3 About code weaving About Fody Examples Questions Agenda

4 What is code weaving? „Generate” additional code to:
Add boilerplate code automatically Implement Aspect-Oriented Programming Obfuscation Build killer APIs What is code weaving?

5 How can I weave? Source code weaving Compile-time weaving
Runtime weaving How can I weave?

6 The tools Emitting MSIL Dynamic proxies AOP Roslyn Refelction.Emit
Mono.Cecil Dynamic proxies Castle, LinFu, Unity, Impromptu Interface AOP PostSharp, Afterthought Roslyn The tools

7 PostSharp Simple but less flexibile
Requires runtime reference to PostSharp Requires Visual Studio extension Aspects in embedded resources Full functionality is not free PostSharp

8 IL weaving (with Cecil)
IL is difficult Need to update PDBs MSBuild integration IL weaving (with Cecil)

9 Fodies are small passerine birds belonging to the genus Foudia in the weaver family Ploceidae
- wikipedia/Fody

10 Weaver Code

11 Fody Many pre-built weavers Uses Mono.Cecil
Integrates into build process Works on build servers Leaves no references Well… depending on the plugin Versatile: .NET Silverlight 4 & 5 Mono, MonoTouch, MonoDroid Windows Phone 7 & 8 (also Metro) Portable Class Library Fody

12 Community weavers Almost 70 packages on NuGet NullGuard
PropertyChanged Costura Anotar ModuleInit Freezable MethodDecorator InfoOf ToString Community weavers

13 Demo

14 Custom weaving Emitting IL is still required (duh!) However Fody
Injects weavers to build pipeline Loads assemblies Rewrites PDBs Reapplies strong name Writes to MSBuild build log Custom weaving

15 Writing a weaver Assembly with .Fody suffix ILMerge references
Pulic ModuleWeaver class Mutltiple deployment options In-solution $(SolutionDir)/Tools NuGet package Learn from existing weavers (example follows) Fody wiki Writing a weaver

16 Demo

17 Gotchas Don’t use Visual Studio plugin
Weaver order sometimes does matter Debugging unavailable code LogInfo requires detailed MSBuild output Tools -> Projects and Solutions -> Build and Run Remember to update Fody package Gotchas

18 Links https://github.com/Fody/
Links

19 Questions?

20

21 The end – wake up now 


Download ppt "Fody code weaving made fun."

Similar presentations


Ads by Google