FullInspector.InspectedMethod.Invoke C# (CSharp) Method

Invoke() public method

Invoke the method. This function will never fail.
public Invoke ( object instance ) : void
instance object
return void
        public void Invoke(object instance)
        {
            try {
                object[] args = null;

                // support default parameter methods
                var methodParams = Method.GetParameters();
                if (methodParams.Length != 0) {
                    args = new object[methodParams.Length];

                    // NOTE: Based on documentation, it looks like the value
                    //       you're actually supposed to use to get default
                    // arguments is Type.Missing, but there appears to be an
                    // issue in mono where that is not supported. Instead we will
                    // just fetch the default parameter values and send them.
                    for (int i = 0; i < args.Length; ++i) {
                        args[i] = methodParams[i].DefaultValue;
                    }
                }

                Method.Invoke(instance, args);
            }
            catch (Exception e) {
                Debug.LogException(e);
            }
        }

Usage Example

コード例 #1
0
ファイル: tkButton.cs プロジェクト: smbss1/fullinspector
            public Button(string methodName)
            {
                InspectedMethod foundMethod = null;

                foreach (var method in InspectedType.Get(typeof(T)).GetMethods(InspectedMemberFilters.All))
                {
                    if (method.Method.Name == methodName)
                    {
                        foundMethod = method;
                    }
                }

                if (foundMethod != null)
                {
                    _label   = (fiGUIContent)foundMethod.DisplayLabel;
                    _enabled = true;
                    _onClick = (o, c) => foundMethod.Invoke(o);
                }
                else
                {
                    Debug.LogError("Unable to find method " + methodName + " on " + typeof(T).CSharpName());
                    _label   = new fiGUIContent(methodName + " (unable to find on " + typeof(T).CSharpName() + ")");
                    _enabled = false;
                    _onClick = (o, c) => { };
                }
            }