public void GetAttribute()
        {
            var attrs = new Attribute[] { new ActionNameAttribute("test", ActionFlags.Execute), new ActionNameAttribute("fail") };
            var attr = attrs.GetAttribute<ActionNameAttribute>();

            Assert.IsNotNull(attr);
            Assert.AreEqual(ActionFlags.Execute, attr.Action);
            Assert.AreEqual("test", attr.Name);
        }
Esempio n. 2
0
        public BaseDrawer Initialize(EditorMember member, Attribute[] attributes, BaseGUI gui, EditorRecord prefs)
        {
            if (attributes == null)
                attributes = Empty;

            if (this.prefs == null)
                this.prefs = prefs;

            this.member     = member;
            this.attributes = attributes;
            this.gui        = gui;

            if (_dynamicFormatter != null)
            {
                _formatArgs[0] = member.Value;
                displayText = _dynamicFormatter(rawTarget, _formatArgs);
            }

            if (_hasInit)
            {
#if DBG
                Log(this + " is Already initialized");
#endif
                return this;
            }
#if DBG
            Log("Initializing: " + this);
#endif
            var displayAttr = attributes.GetAttribute<DisplayAttribute>();
            if (displayAttr != null && MemberDrawersHandler.IsApplicableAttribute(memberType, displayAttr, attributes))
            {
                var hasCustomFormat = !string.IsNullOrEmpty(displayAttr.FormatMethod);
                var formatMethod = hasCustomFormat ? displayAttr.FormatMethod : ("Format" + member.Name);
                var method = targetType.GetMemberFromAll(formatMethod, Flags.StaticInstanceAnyVisibility) as MethodInfo;
                if (method == null)
                {
                    if (hasCustomFormat)
                        Debug.Log("Couldn't find format method: " + displayAttr.FormatMethod);
                }
                else
                {
                    if (method.ReturnType != typeof(string) && method.GetParameters().Length > 0)
                        Debug.Log("Format Method should return a string and take no parameters: " + method);
                    else
                    {
                        _dynamicFormatter = method.DelegateForCall<object, string>();
                        _formatArgs[0] = member.Value;
                        displayText = _dynamicFormatter(rawTarget, _formatArgs);
                    }
                }
            }

            _hasInit = true;
            InternalInitialize();
            Initialize();
            return this;
        }