5

Decompilation of MarkupExtension class looks like this:

[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, it could have been implemented as an interface, but instead it's a class. Why did the WPF team designed it this way? Moreover, in Silverlight it is an interface.

joozek
  • 2,143
  • 2
  • 21
  • 32
  • You are right in this case it has no benefit because the MarkupExtension class here has no state of functionality implemented. – Chevul Ervin Sep 18 '13 at 12:14
  • 1
    Why is this question on hold? It just has one good answer (even if factually wrong it is not opinion-based), and one bad (o-b). The question itself is not about one's opinion, but about the reason for particular design decision. – joozek Sep 19 '13 at 08:56
  • @downvoter care to explain? – joozek Sep 19 '13 at 10:17

1 Answers1

0

In .NET you've NGEN ( Native generator ), which lets you to compile IL code into machine code which is suitable for the specific machine that is running your application. ( You can not use this tool to compile your IL code to machine code for all computers, this tool has dependency on CPU, OS and ... ]. Your application's performance will be boosted too much because of this tool.

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

In Silverlight you've no NGEN, you've no attribute named [TargetedPatchingOptOut]

Good luck

Yaser Moradi
  • 3,267
  • 3
  • 24
  • 50
  • Incorrect and irrelevant. This attribute is used to inline code to make *targeted patching* impossible. In case of empty code blocks, it effectively removes all the code. A constructor from .NET framework with this attribute becomes *nothing*. – Athari Sep 18 '13 at 17:29
  • @Athari I'm not going to say that your idea is wrong, but could you please provide me a link ? – Yaser Moradi Sep 18 '13 at 17:46
  • 3
    [MSDN: System.Runtime.TargetedPatchingOptOutAttribute Class](http://msdn.microsoft.com/en-us/library/system.runtime.targetedpatchingoptoutattribute.aspx), [StackOverflow: TargetedPatchingOptOut: “Performance critical to inline across NGen image boundaries”?](http://stackoverflow.com/q/6109745/293099). Inlining an empty method is removing a call to it. See also [Improvements to NGen in .NET Framework 4](http://blogs.msdn.com/b/clrcodegeneration/archive/2009/05/03/improvements-to-ngen-in-.net-framework-4.aspx) – Athari Sep 18 '13 at 18:55