static Type CreateType()
        {
            Type t = ReflectionAccessor.GetType(CefSharpWindowManagerTypeFullName);

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

            var reference = new List <string>();

            reference.Add("System.dll");
            foreach (var asm in AppDomain.CurrentDomain.GetAssemblies())
            {
                switch (asm.GetName().Name)
                {
                case "CefSharp":
                case "CefSharp.Core":
                case "CefSharp.Wpf":
                    reference.Add(asm.Location);
                    break;
                }
            }
            Compile(reference.ToArray(), Resources.CefSharpWindowManager);
            return(ReflectionAccessor.GetType(CefSharpWindowManagerTypeFullName));
        }
        public static object GetMainFrame(object browser)
        {
            var browserAcs = new ReflectionAccessor(browser);

            foreach (var e in browserAcs.InvokeMethod <IEnumerable>("GetFrameIdentifiers"))
            {
                var frame    = browserAcs.InvokeMethodByType <object>("GetFrame", e);
                var frameAcs = new ReflectionAccessor(frame);
                if (frameAcs.GetProperty <bool>("IsMain"))
                {
                    return(frame);
                }
            }
            return(null);
        }
        static object[] GetChildren(object browser, object parentFrame, List <string> frameNames)
        {
            var browserAcs = new ReflectionAccessor(browser);

            var allFrames = new List <object>();

            foreach (var e in browserAcs.InvokeMethod <IEnumerable>("GetFrameIdentifiers"))
            {
                allFrames.Add(browserAcs.InvokeMethodByType <object>("GetFrame", e));
            }

            var parentFrameIdentifier = new ReflectionAccessor(parentFrame).GetProperty <long>("Identifier");
            var children = new List <ReflectionAccessor>();

            foreach (var frame in allFrames)
            {
                var frameAcs = new ReflectionAccessor(frame);
                var parent   = frameAcs.GetProperty <object>("Parent");
                if (parent == null)
                {
                    continue;
                }

                var parentAcs = new ReflectionAccessor(parent);
                if (parentAcs.GetProperty <long>("Identifier") == parentFrameIdentifier)
                {
                    children.Add(frameAcs);
                }
            }

            //sort
            //For names with names on dom, use the order of appearance.
            children = children.OrderBy(e => e.GetProperty <string>("Name")).ToList();
            if (children.Count < frameNames.Count)
            {
                return(children.ToArray());
            }

            var sortedChildren = new object[children.Count];

            for (int i = 0; i < children.Count; i++)
            {
                var e     = children[i];
                var index = frameNames.IndexOf(e.GetProperty <string>("Name"));
                if (index == -1)
                {
                    continue;
                }
                sortedChildren[index] = e.Object;
                children[i]           = null;
            }

            int j = 0;

            for (int i = 0; i < children.Count; i++)
            {
                var e = children[i];
                if (e == null)
                {
                    continue;
                }

                for (; j < sortedChildren.Length; j++)
                {
                    if (sortedChildren[j] == null)
                    {
                        sortedChildren[j] = e.Object;
                        j++;
                        break;
                    }
                }
            }
            return(sortedChildren);
        }