Esempio n. 1
0
        public Expose Get(string memberName)
        {
            var pi = Type.GetProperty(memberName, Flag | BindingFlags.GetProperty);

            if (pi != null)
            {
                return(Expose.FromObject(pi.GetValue(Value)));
            }
            var fi = Type.GetField(memberName, Flag | BindingFlags.GetField);

            if (fi != null)
            {
                return(Expose.FromObject(fi.GetValue(Value)));
            }

            // Get with indexer
            try
            {
                return(Get(new [] { memberName }));
            }
            catch
            {
                throw new MissingMemberException(Type.Name, memberName);
            }
        }
Esempio n. 2
0
        public Expose Get(object [] index)
        {
            var pi = Type.GetProperty(Type.GetCustomAttribute <DefaultMemberAttribute> ().MemberName, index.Select(x => x.GetType()).ToArray());

            if (pi != null)
            {
                return(Expose.FromObject(pi.GetValue(Value, index)));
            }

            throw new MissingMemberException(Type.Name, "Indexer");
        }
Esempio n. 3
0
        public Expose Call(string methodName, params object [] args)
        {
            args = args.Select(x => x is Expose ? ((Expose)x).Value : x).ToArray();

            // Find method
            if (TryInvoke(methodName, Value, Type.GetMethods(Flag | BindingFlags.InvokeMethod), args, out Expose result))
            {
                return(result);
            }

            // Find event
            var fi = Type.GetField(methodName, Flag | BindingFlags.SetField);

            if (fi != null)
            {
                var del = fi.GetValue(Value) as MulticastDelegate;
                if (del != null && IsInvokable(del.Method, args))
                {
                    object lastResult = null;
                    foreach (var h in del.GetInvocationList())
                    {
                        lastResult = h.Method.Invoke(h.Target, args);
                    }
                    return(Expose.FromObject(lastResult));
                }
            }

            // Find operator method
            args = new [] { Value }.Concat(args).ToArray();
            if (TryInvoke(methodName, null, Type.GetMethods(Flag | BindingFlags.InvokeMethod), args, out result))
            {
                return(result);
            }

            // Find extension method
            if (Value != null &&
                TryInvoke(methodName, null, s_extensionMethods.Where(x => Is(Type, x.Key)).SelectMany(x => x.Value), null, args, out result))
            {
                if (
                    TryInvoke(methodName, null, s_extensionMethods.Where(x => Is(Type, x.Key)).SelectMany(x => x.Value), null, args, out result) ||
                    TryInvoke(methodName, null, s_extensionMethods.Where(x => Is(Type, x.Key)).SelectMany(x => x.Value), new [] { Type }, args, out result)
                    )
                {
                    return(result);
                }
            }

            throw new MissingMemberException(Type.Name, methodName);
        }
Esempio n. 4
0
        /// <summary>
        /// Initializes UI.
        /// </summary>
        void InitializeUI()
        {
            if (phase != Phase.Initialize)
            {
                return;
            }

            if (!DocumentActions.IsResourceReady() || !InstallPackageWindow.IsResourceReady() || !GitButton.IsResourceReady())
            {
                return;
            }

            root = UIUtils.GetRoot(this).Q("container");

            // Document actions.
            documentActions = new DocumentActions(root.Q("detailActions"));

            // Install package window.
            var installPackageWindow = new InstallPackageWindow();

            root.Add(installPackageWindow);

            // Add button to open InstallPackageWindow
            var addButton = root.Q("toolbarAddButton") ?? root.Q("moreAddOptionsButton");
            var gitButton = new GitButton(installPackageWindow.Open);

            addButton.parent.Insert(addButton.parent.IndexOf(addButton) + 1, gitButton);

#if UNITY_2018
            var space = new VisualElement();
            space.style.flexGrow = 1;
            addButton.parent.Insert(addButton.parent.IndexOf(addButton), space);
#endif

            // Update git packages on load packages
            var    packageList = Expose.FromObject(root.Q("packageList"));
            Action onLoad      = packageList["OnLoaded"].As <Action>();
            onLoad += OnPackageListLoaded;
            packageList["OnLoaded"] = Expose.FromObject(onLoad);

#if UNITY_2019_1_OR_NEWER
            var updateButton = root.Q("packageToolBar").Q <Button>("update");
#else
            OnPackageListLoaded();
            var updateButton = root.Q("updateCombo").Q <Button>("update");
#endif

            var detailView = Expose.FromObject(root.Q("detailsGroup"));

            // Override click action.
            Action actionUpdate = () =>
            {
#if UNITY_2019_1_OR_NEWER
                var exTargetPackage = detailView["TargetVersion"];
#else
                var exTargetPackage = detailView["SelectedPackage"];
#endif
                if (exTargetPackage["Origin"].As <int>() == 99)
                {
                    var    packageId       = exTargetPackage["Info"]["m_PackageId"].As <string>();
                    string packageIdPrefix = regInstallVersion.Replace(packageId, "");
                    string refName         = exTargetPackage["Version"].ToString().Replace("0.0.0-", "");
                    exTargetPackage["_PackageId"] = Expose.FromObject(packageIdPrefix + "#" + refName);
                }

                detailView.Call("UpdateClick");
            };
            Expose.FromObject(updateButton.clickable)["clicked"] = Expose.FromObject(actionUpdate);

            phase = Phase.Idle;
        }