Why MarkupExtension is a class in wpf

Decompiling the MarkupExtension class is as follows:

[TypeForwardedFrom("WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")] public abstract class MarkupExtension { [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] protected MarkupExtension() { } public abstract object ProvideValue(IServiceProvider serviceProvider); } 

As you can see, this could be implemented as an interface, but instead it is a class. Why did the WPF team design it this way ? In addition, Silverlight has an interface .

+4
source share
1 answer

In .NET, you have NGEN (your own generator), which allows you to compile IL code into machine code that is suitable for the particular machine on which your application is running. (You cannot use this tool to compile your IL code for machine code for all computers, this tool depends on the processor, OS and ...]. Thanks to this tool, the performance of your application will be too much increased.

The [TargetedPatchingOptOut] attribute, which is used in the WPF (.NET) version code, is intended for the NGEN tool, and this attribute should be used on top of the constructor here, so the interface is not suitable here.

In Silverlight, you donโ€™t have NGEN, you donโ€™t have an attribute named [TargetedPatchingOptOut]

Good luck.

+1
source

Source: https://habr.com/ru/post/1502791/


All Articles