public static IEnumerable <XamlMember> GetSortedConstructorArguments(this XamlType type)
        {
            var args = type.GetConstructorArguments().ToArray();

            foreach (var ci in type.UnderlyingType.GetConstructors().Where(c => c.GetParameters().Length == args.Length))
            {
                var pis = ci.GetParameters();
                if (args.Length != pis.Length)
                {
                    continue;
                }
                bool mismatch = false;
                foreach (var pi in pis)
                {
                    for (int i = 0; i < args.Length; i++)
                    {
                        if (!args.Any(a => a.ConstructorArgumentName() == pi.Name))
                        {
                            mismatch = true;
                        }
                    }
                }
                if (mismatch)
                {
                    continue;
                }
                return(args.OrderBy(c => pis.FindParameterWithName(c.ConstructorArgumentName()).Position));
            }
            return(null);
        }
        public static IEnumerable <XamlMember> GetSortedConstructorArguments(this XamlType type, IList <object> contents = null)
        {
            var constructors = type.UnderlyingType.GetTypeInfo().GetConstructors();

            if (contents != null && contents.Count > 0)
            {
                var context = type.SchemaContext;

                // find constructor that matches content type directly first, then by ones that can be converted by type
                var constructorArguments =
                    FindConstructorArguments(context, constructors, contents, (type1, type2) => type1.UnderlyingType.GetTypeInfo().IsAssignableFrom(type2.UnderlyingType.GetTypeInfo()))
                    ?? FindConstructorArguments(context, constructors, contents, (type1, type2) => type1.CanConvertFrom(type2));

                if (constructorArguments != null)
                {
                    return(constructorArguments);
                }
            }

            // find constructor based on ConstructorArgumentAttribute
            var args = type.GetConstructorArguments();

            foreach (var ci in constructors)
            {
                var pis = ci.GetParameters();
                if (args.Count != pis.Length)
                {
                    continue;
                }
                bool mismatch = false;
                foreach (var pi in pis)
                {
                    mismatch |= args.All(a => a.ConstructorArgumentName() != pi.Name);
                }
                if (mismatch)
                {
                    continue;
                }
                return(args.OrderBy(c => pis.FindParameterWithName(c.ConstructorArgumentName()).Position));
            }

            return(null);
        }