File: src\Framework\System\Windows\Markup\Baml2006\WpfKnownTypeInvoker.cs
Project: wpf\PresentationFramework.csproj (PresentationFramework)
using System;
using System.Collections.Generic;
using System.Xaml;
using System.Xaml.Schema;
 
namespace System.Windows.Baml2006
{
    class WpfKnownTypeInvoker : XamlTypeInvoker
    {
        WpfKnownType _type;
 
        public WpfKnownTypeInvoker(WpfKnownType type)
            : base(type)
        {
            _type = type;
        }
 
        public override object CreateInstance(object[] arguments)
        {
            if ((arguments == null || arguments.Length == 0) && _type.DefaultConstructor != null)
            {
                return _type.DefaultConstructor.Invoke();
            }
            else if (_type.IsMarkupExtension)
            {
                Baml6ConstructorInfo ctorInfo;
                if(!_type.Constructors.TryGetValue(arguments.Length, out ctorInfo))
                {
                    throw new InvalidOperationException(SR.Get(SRID.PositionalArgumentsWrongLength));
                }
                return ctorInfo.Constructor(arguments);
            }
            else
            {
                return base.CreateInstance(arguments);
            }
        }
 
    }
}