示例#1
0
        protected override Action <ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress)
        {
            if (!(myVariableDeclaration is ILocalVariableDeclaration localVariableDeclaration && localVariableDeclaration.TypeUsage == null))
            {
                var newType = TypeFactory.CreateArrayType(TypeFactory.CreateArrayType(myType.ElementType, 1, NullableAnnotation.NotNullable),
                                                          1, myType.NullableAnnotation);
                myVariableDeclaration.SetType(newType);
            }


            var factory = CSharpElementFactory.GetInstance(myVariableDeclaration);

            if (myArrayCreationExpression != null)
            {
                if (myArrayCreationExpression.Initializer == null)
                {
                    ConvertArrayCreationWithoutInitializer(factory);
                }
                else
                {
                    ConvertArrayCreation(factory);
                }
            }

            ConvertUsages(factory);

            return(null);
        }
示例#2
0
        /// <summary>
        /// Swap variable declaration to built in type.
        /// </summary>
        /// <param name="variableDeclaration">
        /// The variable declaration.
        /// </param>
        private static void SwapVariableDeclarationToBuiltInType(IVariableDeclaration variableDeclaration)
        {
            if (variableDeclaration is ILocalVariableDeclaration)
            {
                ProcessLocalVariableDeclaration((ILocalVariableDeclaration)variableDeclaration);
            }
            else if (variableDeclaration is IForeachVariableDeclaration)
            {
                ProcessForeachVariableDeclaration((IForeachVariableDeclaration)variableDeclaration);
            }
            else
            {
                IDeclaredElement declaredElement = variableDeclaration.DeclaredElement;
                ITypeOwner       typeOwner       = (ITypeOwner)declaredElement;

                if (typeOwner != null)
                {
                    using (WriteLockCookie.Create(true))
                    {
                        variableDeclaration.SetType(typeOwner.Type);
                    }
                }
            }
        }
        /// <summary>
        /// Swap variable declaration to built in type.
        /// </summary>
        /// <param name="variableDeclaration">
        /// The variable declaration.
        /// </param>
        private static void SwapVariableDeclarationToBuiltInType(IVariableDeclaration variableDeclaration)
        {
            if (variableDeclaration is ILocalVariableDeclaration)
            {
                ProcessLocalVariableDeclaration((ILocalVariableDeclaration)variableDeclaration);
            }
            else if (variableDeclaration is IForeachVariableDeclaration)
            {
                ProcessForeachVariableDeclaration((IForeachVariableDeclaration)variableDeclaration);
            }
            else
            {
                IDeclaredElement declaredElement = variableDeclaration.DeclaredElement;
                ITypeOwner typeOwner = (ITypeOwner)declaredElement;

                if (typeOwner != null)
                {
                    using (WriteLockCookie.Create(true))
                    {
                        variableDeclaration.SetType(typeOwner.Type);
                    }
                }
            }
        }