public static bool IsInExpressionArgument(this IOperation operation)
    {
        var semanticModel = operation.SemanticModel;

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

        foreach (var op in operation.Ancestors().OfType <IArgumentOperation>())
        {
            if (op.Parameter == null)
            {
                continue;
            }

            var type = op.Parameter.Type;
            if (type.InheritsFrom(semanticModel.Compilation.GetTypeByMetadataName("System.Linq.Expressions.Expression")))
            {
                return(true);
            }
        }

        return(false);
    }
Exemplo n.º 2
0
        private static bool CanBeAsync(IOperation operation)
        {
            if (operation.Ancestors().Any(op => op is ILockOperation))
            {
                return(false);
            }

            return(true);
        }
        public static bool IsInQueryableExpressionArgument(this IOperation operation)
        {
            foreach (var invocationOperation in operation.Ancestors().OfType <IInvocationOperation>())
            {
                var type = invocationOperation.TargetMethod.ContainingType;
                if (type.IsEqualTo(operation.SemanticModel.Compilation.GetTypeByMetadataName("System.Linq.Queryable")))
                {
                    return(true);
                }
            }

            return(false);
        }
 public static bool IsInNameofOperation(this IOperation operation)
 {
     return(operation.Ancestors().OfType <INameOfOperation>().Any());
 }