internal static bool TryInt()

in src/PSDocs/Common/ExpressionHelpers.cs [145:170]


        internal static bool TryInt(object o, bool convert, out int value)
        {
            o = GetBaseObject(o);
            if (o is int ivalue)
            {
                value = ivalue;
                return true;
            }
            if (o is long lvalue && lvalue <= int.MaxValue && lvalue >= int.MinValue)
            {
                value = (int)lvalue;
                return true;
            }
            else if (o is JToken token && token.Type == JTokenType.Integer)
            {
                value = token.Value<int>();
                return true;
            }
            else if (convert && TryString(o, out string s) && int.TryParse(s, out ivalue))
            {
                value = ivalue;
                return true;
            }
            value = default(int);
            return false;
        }