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, CSharpConversions.Get(context.Compilation));
                    AddCriterion(localResolveResult.Variable, criterion);
                }
            }
            else if (resolveResult is CSharpInvocationResolveResult)
            {
                var invocationResolveResult = (CSharpInvocationResolveResult)resolveResult;
                var parameterTypes          = invocationResolveResult.Arguments.Select(arg => arg.Type);
                var criterion = new SupportsIndexingCriterion(invocationResolveResult.Member.ReturnType, parameterTypes, CSharpConversions.Get(context.Compilation));
                AddCriterion(localResolveResult.Variable, criterion);
            }
        }
Esempio n. 2
0
		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, CSharpConversions.Get(context.Compilation));
					AddCriterion(localResolveResult.Variable, criterion);
				}
			} else if (resolveResult is CSharpInvocationResolveResult) {
				var invocationResolveResult = (CSharpInvocationResolveResult)resolveResult;
				var parameterTypes = invocationResolveResult.Arguments.Select(arg => arg.Type);
				var criterion = new SupportsIndexingCriterion(invocationResolveResult.Member.ReturnType, parameterTypes, CSharpConversions.Get(context.Compilation));
				AddCriterion(localResolveResult.Variable, criterion);
			}
		}