public override TAbstractAnalysisValue VisitArrayInitializer(IArrayInitializerOperation operation, object argument)
        {
            var arrayCreation = (IArrayCreationOperation)operation.Parent;
            var elementType   = ((IArrayTypeSymbol)arrayCreation.Type).ElementType;

            for (int index = 0; index < operation.ElementValues.Length; index++)
            {
                AbstractIndex          abstractIndex      = AbstractIndex.Create((uint)index);
                IOperation             elementInitializer = operation.ElementValues[index];
                TAbstractAnalysisValue initializerValue   = Visit(elementInitializer, argument);
                SetAbstractValueForElementInitializer(arrayCreation, ImmutableArray.Create(abstractIndex), elementType, elementInitializer, initializerValue);
            }

            return(UnknownOrMayBeValue);
        }
        private static AbstractIndex CreateAbstractIndex(IOperation operation)
        {
            if (operation.ConstantValue.HasValue && operation.ConstantValue.Value is int index)
            {
                return(AbstractIndex.Create((uint)index));
            }
            // TODO: We need to find the abstract value for the entity to use it for indexing.
            // https://github.com/dotnet/roslyn-analyzers/issues/1577
            //else if (TryCreate(operation, out AnalysisEntity analysisEntity))
            //{
            //    return AbstractIndex.Create(analysisEntity);
            //}

            return(AbstractIndex.Create(operation));
        }
 private AbstractIndex CreateAbstractIndex(IOperation operation)
 {
     if (operation.ConstantValue.HasValue && operation.ConstantValue.Value is int index)
     {
         return(AbstractIndex.Create((uint)index));
     }
     else if (TryCreate(operation, out AnalysisEntity analysisEntity))
     {
         return(AbstractIndex.Create(analysisEntity));
     }
     else
     {
         return(AbstractIndex.Create(operation));
     }
 }
        public override TAbstractAnalysisValue VisitCollectionElementInitializer(ICollectionElementInitializerOperation operation, object argument)
        {
            var         objectCreation        = operation.GetAncestor <IObjectCreationOperation>(OperationKind.ObjectCreation);
            ITypeSymbol collectionElementType = operation.AddMethod?.Parameters.FirstOrDefault()?.Type;

            if (collectionElementType != null)
            {
                var index = (uint)argument;
                for (int i = 0; i < operation.Arguments.Length; i++, index++)
                {
                    AbstractIndex          abstractIndex      = AbstractIndex.Create(index);
                    IOperation             elementInitializer = operation.Arguments[i];
                    TAbstractAnalysisValue argumentValue      = Visit(elementInitializer, argument: null);
                    SetAbstractValueForElementInitializer(objectCreation, ImmutableArray.Create(abstractIndex), collectionElementType, elementInitializer, argumentValue);
                }
            }
            else
            {
                var _ = base.VisitCollectionElementInitializer(operation, argument: null);
            }

            return(UnknownOrMayBeValue);
        }
Exemple #5
0
 public override bool Equals(AbstractIndex other)
 {
     return(other is ConstantValueIndex otherIndex &&
            Index == otherIndex.Index);
 }
 public override bool Equals(AbstractIndex other)
 {
     return(other is OperationBasedIndex otherIndex &&
            Operation.Equals(otherIndex.Operation));
 }
Exemple #7
0
 public override bool Equals(AbstractIndex other)
 {
     return(other is AnalysisEntityBasedIndex otherIndex &&
            AnalysisEntity.Equals(otherIndex.AnalysisEntity));
 }