Beispiel #1
0
        public static bool IsBurstPossibleArgumentString([NotNull] ICSharpArgument argument)
        {
            var unused         = argument.Expression; // for debug
            var expressionType = argument.GetExpressionType();
            var type           = expressionType.ToIType();

            // if expression is type A -> then everything that returns from it is A.
            // if in burst context there are managed variables(like string) -> it will be highlighted
            // assume there are no
            // then there are only IStringLiteralOwner, fixedString and IInvocationExpression
            return(type.IsString() || IsFixedString(type));
        }
        private static bool CheckIfDestructureNeeded(ICSharpArgument argument)
        {
            bool CheckIfBaseToStringUsed(IType type)
            {
                if (type.IsObject())
                {
                    return(false);
                }

                if (type.IsPredefinedNumeric())
                {
                    return(false);
                }

                if (type.IsString())
                {
                    return(false);
                }

                if (type.IsGuid())
                {
                    return(false);
                }

                var classType = type.GetClassType();

                if (classType == null)
                {
                    return(false);
                }

                if (classType.Methods.Any(m => m.IsOverridesObjectToString()))
                {
                    return(false);
                }

                return(true);
            }

            // ReSharper disable once StyleCop.SA1305
            var iType = argument.GetExpressionType().ToIType();

            if (iType == null)
            {
                return(false);
            }

            if (iType.IsNullable())
            {
                var nullable = iType.GetNullableUnderlyingType();
                if (nullable == null)
                {
                    return(false);
                }

                return(CheckIfBaseToStringUsed(nullable));
            }

            if (iType is IDeclaredType declaredType)
            {
                if (Equals(declaredType.GetClrName(), GenericDictionaryFqn))
                {
                    var argumentType = declaredType.GetFirstGenericArgumentType();

                    return(argumentType != null && CheckIfBaseToStringUsed(argumentType));
                }

                var genericType = CollectionTypeUtil.GetElementTypesForGenericEnumerable(declaredType);
                if (genericType.Count == 1)
                {
                    return(CheckIfBaseToStringUsed(genericType.Single()));
                }
            }

            return(CheckIfBaseToStringUsed(iType));
        }