public SupportsIndexingCriterion(IType returnType, IEnumerable <IType> argumentTypes, AlConversions conversions, bool isWriteAccess = false)
        {
            if (returnType == null)
            {
                throw new ArgumentNullException("returnType");
            }
            if (argumentTypes == null)
            {
                throw new ArgumentNullException("argumentTypes");
            }
            if (conversions == null)
            {
                throw new ArgumentNullException("conversions");
            }

            this.returnType    = returnType;
            this.argumentTypes = argumentTypes.ToList();
            this.conversions   = conversions;
            this.isWriteAccess = isWriteAccess;
        }
Пример #2
0
 public GatherVisitor(BaseRefactoringContext ctx)
     : base(ctx)
 {
     conversion = new AlConversions(ctx.Compilation);
 }
        public override void VisitIndexerExpression(IndexerExpression indexerExpression)
        {
            base.VisitIndexerExpression(indexerExpression);

            var localResolveResult = context.Resolve(indexerExpression.Target) as LocalResolveResult;

            if (localResolveResult == null)
            {
                return;
            }
            var resolveResult = context.Resolve(indexerExpression);

            if (localResolveResult == null)
            {
                return;
            }
            var parent = indexerExpression.Parent;

            while (parent is ParenthesizedExpression)
            {
                parent = parent.Parent;
            }
            if (parent is DirectionExpression)
            {
                // The only types which are indexable and where the indexing expression
                // results in a variable is an actual array type
                AddCriterion(localResolveResult.Variable, new IsArrayTypeCriterion());
            }
            else if (resolveResult is ArrayAccessResolveResult)
            {
                var arrayResolveResult = (ArrayAccessResolveResult)resolveResult;
                var arrayType          = arrayResolveResult.Array.Type as ArrayType;
                if (arrayType != null)
                {
                    var parameterTypes = arrayResolveResult.Indexes.Select(index => index.Type);
                    var criterion      = new SupportsIndexingCriterion(arrayType.ElementType, parameterTypes, AlConversions.Get(context.Compilation));
                    AddCriterion(localResolveResult.Variable, criterion);
                }
            }
            else if (resolveResult is AlInvocationResolveResult)
            {
                var invocationResolveResult = (AlInvocationResolveResult)resolveResult;
                var parameterTypes          = invocationResolveResult.Arguments.Select(arg => arg.Type);
                var criterion = new SupportsIndexingCriterion(invocationResolveResult.Member.ReturnType, parameterTypes, AlConversions.Get(context.Compilation));
                AddCriterion(localResolveResult.Variable, criterion);
            }
        }