コード例 #1
0
        public EnvDTE.CodeVariable AddEnumMember(SyntaxNode containerNode, string name, object value, object position)
        {
            if (value is not null and not string)
            {
                throw Exceptions.ThrowEInvalidArg();
            }

            var semanticModel = GetSemanticModel();

            var type = (ITypeSymbol?)semanticModel.GetDeclaredSymbol(containerNode);

            if (type == null)
            {
                throw Exceptions.ThrowEInvalidArg();
            }

            var newField = CreateFieldDeclaration(containerNode, CodeModelService.GetUnescapedName(name), EnvDTE.vsCMAccess.vsCMAccessPublic, type);

            if (value != null)
            {
                newField = CodeModelService.AddInitExpression(newField, (string)value);
            }

            var insertionIndex = CodeModelService.PositionVariantToMemberInsertionIndex(position, containerNode, fileCodeModel: this);

            newField = InsertMember(containerNode, newField, insertionIndex);

            return((EnvDTE.CodeVariable)CreateInternalCodeMember(this.State, fileCodeModel: this, node: newField));
        }
コード例 #2
0
        internal void UpdateInitExpression(SyntaxNode node, string initExpression)
        {
            node = CodeModelService.GetNodeWithInitializer(node);
            var updatedNode = CodeModelService.AddInitExpression(node, initExpression);

            if (node != updatedNode)
            {
                UpdateNode(node, updatedNode);
            }
        }