Ejemplo n.º 1
0
 /// <inheritdoc/>
 public bool ShowInInspector([NotNull] Type containingClassType, [CanBeNull] object containingClassInstance, [CanBeNull] MemberInfo classMember)
 {
     if (evaluator == null)
     {
         evaluator = EvaluationUtility.GenerateEvaluatorForBooleanExpression(expression);
     }
     return(evaluator.Evaluate(containingClassType, containingClassInstance, classMember));
 }
Ejemplo n.º 2
0
        public bool Evaluate([NotNull] Type containingClassType, [CanBeNull] object containingClassInstance, [CanBeNull] MemberInfo classMember)
        {
            object leftValue  = ParseValue(left, containingClassType, containingClassInstance, classMember);
            object rightValue = ParseValue(right, containingClassType, containingClassInstance, classMember);

                        #if DEV_MODE && DEBUG_ENABLED
            Debug.Log((classMember == null ? "" : classMember.Name) + ".Evalute " + (leftValue == null ? "null" : leftValue.ToString()) + " " + comparison + " " + (rightValue == null ? "null" : rightValue.ToString()));
                        #endif

            return(EvaluationUtility.Test(leftValue, comparison, rightValue));
        }
Ejemplo n.º 3
0
        public bool ShowInInspector([NotNull] Type containingClassType, [CanBeNull] object containingClassInstance, [CanBeNull] MemberInfo classMember)
        {
            if (alwaysShow)
            {
                return(true);
            }

            if (evaluatorExpression != null)
            {
                if (evaluator == null)
                {
                    evaluator = EvaluationUtility.GenerateEvaluatorForBooleanExpression(evaluatorExpression);
                }
                return(evaluator.Evaluate(containingClassType, containingClassInstance, classMember));
            }

            if (!string.IsNullOrEmpty(classMemberName))
            {
                var classMembers = containingClassType.GetMember(classMemberName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);

                int classMembersFound = classMembers.Length;

                if (classMembersFound == 0)
                {
                    Debug.LogError("HelpBoxAttribute class member by name \"" + classMemberName + "\" not found.");
                    return(true);
                }

                classMember = classMembers[0];
            }

            var    field = classMember as FieldInfo;
            object currentValue;
            Type   classMemberType;

            if (field is object)
            {
                classMemberType = field.FieldType;
                currentValue    = field.GetValue(field.IsStatic ? null : containingClassInstance);
            }
            else
            {
                var property = classMember as PropertyInfo;
                if (property is object)
                {
                    classMemberType = property.PropertyType;
                    var getAccessor = property.GetGetMethod();
                    currentValue = getAccessor.Invoke(getAccessor.IsStatic ? null : containingClassInstance, null);
                }
                else
                {
                    Debug.LogError("ShowInInspectorIfAttribute class member by name \"" + classMemberName + "\" was not a field or a property.");
                    return(true);
                }
            }

                        #if DEV_MODE
            Debug.Log("Show if \"" + classMemberName + "\" value (" + (currentValue == null ? "null" : currentValue.ToString()) + ") " + comparisonType + " " + (requiredValue == null ? "null" : requiredValue.ToString()));
                        #endif

            return(EvaluationUtility.Test(currentValue, comparisonType, requiredValue));
        }