In some of my smoke tests, I'm using Mono Cecil to parse the opcodes of my assemblies. I then perform some operations to validate code quality, etc. However, I don't really care about generated code in designers because there isn't much I can do about that, so I will exclude the InitializeComponent
method. This worked fine for WinForms, but doesn't appear to work for xaml. In other words, I'm still processing the instructions in xaml (i.e. Events being subscribed to). I know xaml is "compiled" into baml and not IL, but Mono Cecil is apparently still able to get the OpCodes from baml).
I read here and here that in xaml, the InitializeComponent
calls the Application.LoadComponent
method, so I tried to exclude that as well, but I was still processing the xaml instructions. I specifically am checking for event handler subscription.
My Question: Are there any other "under the hood" methods that are called when compiling the xaml other than InitializeComponent
or LoadComponent
? In other words, how can I distinguish instructions that come from the code-behind (xaml.cs) vs xaml?
So, digging through MSDN, I found this little gem.
Apparently, the IComponentConnector is what handles both the InitializeComponent as well as the Connect (which handles the event subscription). So there's a little lesson about WPF vs Winforms, events are set up in InitializeComponent.
So, the method to exclude is:
System.Windows.Markup.IComponentConnector.Connect();