.NET — How to extend the code?

Robin Ding
1 min readSep 8, 2021

Couple of ways to extend your code or others code

Solution Pros Cons Dependency Injection ToDo ToDo AOP (Aspect-Oriented Programming) ToDo ToDo Reflection The classes in the System.Reflection namespace, together with System.Type, enable you to obtain information about loaded assemblies and the types defined within them, such as classes, interfaces, and value types (that is, structures and enumerations). You can also use reflection to create type instances at run time, and to invoke and access them. For topics about specific aspects of reflection, see Related Topics at the end of this overview. ToDo Emit MetaData and MSIL — Reflection.Emit

Define lightweight global methods at run time, using the DynamicMethod class, and execute them using delegates.

Define assemblies at run time and then run them and/or save them to disk.

Define assemblies at run time, run them, and then unload them and allow garbage collection to reclaim their resources.

Define modules in new assemblies at run time and then run and/or save them to disk.

Define types in modules at run time, create instances of these types, and invoke their methods.

Define symbolic information for defined modules that can be used by tools such as debuggers and code profilers.

ToDo ECMA IL Manipulation — Mono.Cecil Cecil is a library written by Jb Evain to generate and inspect programs and libraries in the ECMA CIL format. With Cecil, you can load existing managed assemblies, browse all the contained types, modify them on the fly and save back to the disk the modified assembly. ToDo

--

--