Example #1
0
        public static bool SupportsType(Type type)
        {
            if (!type.IsValueType || string.IsNullOrEmpty(type.AssemblyQualifiedName) || type.FullName == SYSTEM_VOID)
            {
                return(false);
            }

            if (typeSupportCache.TryGetValue(type.AssemblyQualifiedName, out var info))
            {
                return(info.IsSupported);
            }

            var supported = false;

            var fields = type.GetFields(INSTANCE_FLAGS);

            if (fields.Length > 0)
            {
                if (fields.Any(it => !ParseUtility.CanParse(it.FieldType)))
                {
                    supported = false;
                    info      = new StructInfo(supported, null);
                }
                else
                {
                    supported = true;
                    info      = new StructInfo(supported, fields);
                }
            }

            typeSupportCache.Add(type.AssemblyQualifiedName, info);

            return(supported);
        }
Example #2
0
        public void SetKey(object key)
        {
            this.DictKey      = key;
            this.DisplayedKey = key.TryCast();

            var type = DisplayedKey.GetType();

            if (ParseUtility.CanParse(type))
            {
                KeyInputWanted   = true;
                KeyInputText     = ParseUtility.ToStringForInput(DisplayedKey, type);
                KeyInputTypeText = SignatureHighlighter.Parse(type, false);
            }
            else
            {
                KeyInputWanted = false;
                InspectWanted  = type != typeof(bool) && !type.IsEnum;
                KeyLabelText   = ToStringUtility.ToStringWithType(DisplayedKey, type, true);
            }
        }
Example #3
0
        public static bool CanParseArgs(ParameterInfo[] parameters)
        {
            foreach (var param in parameters)
            {
                var pType = param.ParameterType;

                if (pType.IsByRef && pType.HasElementType)
                {
                    pType = pType.GetElementType();
                }

                if (pType != null && ParseUtility.CanParse(pType))
                {
                    continue;
                }
                else
                {
                    return(false);
                }
            }
            return(true);
        }
Example #4
0
        public virtual void SetDataToCell(CacheObjectCell cell)
        {
            cell.NameLabel.text = NameLabelText;
            if (cell.HiddenNameLabel != null)
            {
                cell.HiddenNameLabel.Text = NameLabelTextRaw ?? string.Empty;
            }
            cell.ValueLabel.gameObject.SetActive(true);

            cell.SubContentHolder.gameObject.SetActive(SubContentShowWanted);
            if (IValue != null)
            {
                IValue.UIRoot.transform.SetParent(cell.SubContentHolder.transform, false);
                IValue.SetLayout();
            }

            bool evaluated = TryAutoEvaluateIfUnitialized(cell);

            if (cell.CopyButton != null)
            {
                bool hasEvaluated = State != ValueState.NotEvaluated && State != ValueState.Exception;
                cell.CopyButton.Component.gameObject.SetActive(hasEvaluated);
                cell.PasteButton.Component.gameObject.SetActive(hasEvaluated && this.CanWrite);
            }

            if (!evaluated)
            {
                return;
            }

            // The following only executes if the object has evaluated.
            // For members and properties with args, they will return by default now.

            switch (State)
            {
            case ValueState.Exception:
                SetValueState(cell, ValueStateArgs.Default);
                break;

            case ValueState.Boolean:
                SetValueState(cell, new ValueStateArgs(false, toggleActive: true, applyActive: CanWrite));
                break;

            case ValueState.Number:
                SetValueState(cell, new ValueStateArgs(false, typeLabelActive: true, inputActive: true, applyActive: CanWrite));
                break;

            case ValueState.String:
                if (LastValueWasNull)
                {
                    SetValueState(cell, new ValueStateArgs(true, subContentButtonActive: true));
                }
                else
                {
                    SetValueState(cell, new ValueStateArgs(true, false, SignatureHighlighter.StringOrange, subContentButtonActive: true));
                }
                break;

            case ValueState.Enum:
                SetValueState(cell, new ValueStateArgs(true, subContentButtonActive: CanWrite));
                break;

            case ValueState.Color:
            case ValueState.ValueStruct:
                if (ParseUtility.CanParse(LastValueType))
                {
                    SetValueState(cell, new ValueStateArgs(false, false, null, true, false, true, CanWrite, true, true));
                }
                else
                {
                    SetValueState(cell, new ValueStateArgs(true, inspectActive: true, subContentButtonActive: true));
                }
                break;

            case ValueState.Collection:
            case ValueState.Dictionary:
                SetValueState(cell, new ValueStateArgs(true, inspectActive: !LastValueWasNull, subContentButtonActive: !LastValueWasNull));
                break;

            case ValueState.Unsupported:
                SetValueState(cell, new ValueStateArgs(true, inspectActive: !LastValueWasNull));
                break;
            }

            cell.RefreshSubcontentButton();
        }
Example #5
0
        protected string GetValueLabel()
        {
            string label = "";

            switch (State)
            {
            case ValueState.NotEvaluated:
                return($"<i>{NOT_YET_EVAL} ({SignatureHighlighter.Parse(FallbackType, true)})</i>");

            case ValueState.Exception:
                return($"<i><color=red>{LastException.ReflectionExToString()}</color></i>");

            // bool and number dont want the label for the value at all
            case ValueState.Boolean:
            case ValueState.Number:
                return(null);

            // and valuestruct also doesnt want it if we can parse it
            case ValueState.ValueStruct:
                if (ParseUtility.CanParse(LastValueType))
                {
                    return(null);
                }
                break;

            // string wants it trimmed to max 200 chars
            case ValueState.String:
                if (!LastValueWasNull)
                {
                    return($"\"{ToStringUtility.PruneString(Value as string, 200, 5)}\"");
                }
                break;

            // try to prefix the count of the collection for lists and dicts
            case ValueState.Collection:
                if (!LastValueWasNull)
                {
                    if (Value is IList iList)
                    {
                        label = $"[{iList.Count}] ";
                    }
                    else if (Value is ICollection iCol)
                    {
                        label = $"[{iCol.Count}] ";
                    }
                    else
                    {
                        label = "[?] ";
                    }
                }
                break;

            case ValueState.Dictionary:
                if (!LastValueWasNull)
                {
                    if (Value is IDictionary iDict)
                    {
                        label = $"[{iDict.Count}] ";
                    }
                    else
                    {
                        label = "[?] ";
                    }
                }
                break;
            }

            // Cases which dont return will append to ToStringWithType

            return(label += ToStringUtility.ToStringWithType(Value, FallbackType, true));
        }
Example #6
0
        public void OnBorrowed(EvaluateWidget evaluator, ParameterInfo paramInfo)
        {
            this.evaluator = evaluator;
            this.paramInfo = paramInfo;

            this.paramType = paramInfo.ParameterType;
            if (paramType.IsByRef)
            {
                paramType = paramType.GetElementType();
            }

            this.argNameLabel.text =
                $"{SignatureHighlighter.Parse(paramType, false)} <color={SignatureHighlighter.LOCAL_ARG}>{paramInfo.Name}</color>";

            if (ParseUtility.CanParse(paramType) || typeof(Type).IsAssignableFrom(paramType))
            {
                usingBasicLabel = false;

                this.inputField.Component.gameObject.SetActive(true);
                this.basicLabelHolder.SetActive(false);
                this.typeCompleter.Enabled = typeof(Type).IsAssignableFrom(paramType);
                this.enumCompleter.Enabled = paramType.IsEnum;
                this.enumHelperButton.Component.gameObject.SetActive(paramType.IsEnum);

                if (!typeCompleter.Enabled)
                {
                    if (paramType == typeof(string))
                    {
                        inputField.PlaceholderText.text = "...";
                    }
                    else
                    {
                        inputField.PlaceholderText.text = $"eg. {ParseUtility.GetExampleInput(paramType)}";
                    }
                }
                else
                {
                    inputField.PlaceholderText.text = "Enter a Type name...";
                    this.typeCompleter.BaseType     = typeof(object);
                    this.typeCompleter.CacheTypes();
                }

                if (enumCompleter.Enabled)
                {
                    enumCompleter.EnumType = paramType;
                    enumCompleter.CacheEnumValues();
                }
            }
            else
            {
                // non-parsable, and not a Type
                usingBasicLabel = true;

                this.inputField.Component.gameObject.SetActive(false);
                this.basicLabelHolder.SetActive(true);
                this.typeCompleter.Enabled = false;
                this.enumCompleter.Enabled = false;
                this.enumHelperButton.Component.gameObject.SetActive(false);

                SetDisplayedValueFromPaste();
            }
        }
        public virtual void SetDataToCell(CacheObjectCell cell)
        {
            cell.NameLabel.text = NameLabelText;
            cell.ValueLabel.gameObject.SetActive(true);

            cell.SubContentHolder.gameObject.SetActive(SubContentShowWanted);
            if (IValue != null)
            {
                IValue.UIRoot.transform.SetParent(cell.SubContentHolder.transform, false);
                IValue.SetLayout();
            }

            if (SetCellEvaluateState(cell))
            {
                return;
            }

            switch (State)
            {
            case ValueState.Exception:
                SetValueState(cell, ValueStateArgs.Default);
                break;

            case ValueState.Boolean:
                SetValueState(cell, new ValueStateArgs(false, toggleActive: true, applyActive: CanWrite));
                break;

            case ValueState.Number:
                SetValueState(cell, new ValueStateArgs(false, typeLabelActive: true, inputActive: true, applyActive: CanWrite));
                break;

            case ValueState.String:
                if (LastValueWasNull)
                {
                    SetValueState(cell, new ValueStateArgs(true, subContentButtonActive: true));
                }
                else
                {
                    SetValueState(cell, new ValueStateArgs(true, false, SignatureHighlighter.StringOrange, subContentButtonActive: true));
                }
                break;

            case ValueState.Enum:
                SetValueState(cell, new ValueStateArgs(true, subContentButtonActive: CanWrite));
                break;

            case ValueState.Color:
            case ValueState.ValueStruct:
                if (ParseUtility.CanParse(LastValueType))
                {
                    SetValueState(cell, new ValueStateArgs(false, false, null, true, false, true, CanWrite, true, true));
                }
                else
                {
                    SetValueState(cell, new ValueStateArgs(true, inspectActive: true, subContentButtonActive: true));
                }
                break;

            case ValueState.Collection:
            case ValueState.Dictionary:
                SetValueState(cell, new ValueStateArgs(true, inspectActive: !LastValueWasNull, subContentButtonActive: !LastValueWasNull));
                break;

            case ValueState.Unsupported:
                SetValueState(cell, new ValueStateArgs(true, inspectActive: !LastValueWasNull));
                break;
            }

            cell.RefreshSubcontentButton();
        }