コード例 #1
0
        protected SyntaxNode CreatePropertyDeclaration(SyntaxNode containerNode, string name, bool generateGetter, bool generateSetter, EnvDTE.vsCMAccess access, ITypeSymbol type)
        {
            var destination = CodeModelService.GetDestination(containerNode);

            IMethodSymbol getMethod = null;

            if (generateGetter)
            {
                getMethod = CodeGenerationSymbolFactory.CreateMethodSymbol(
                    attributes: default(ImmutableArray <AttributeData>),
                    accessibility: Accessibility.NotApplicable,
                    modifiers: new DeclarationModifiers(),
                    returnType: null,
                    returnsByRef: false,
                    explicitInterfaceSymbol: null,
                    name: "get_" + name,
                    typeParameters: default(ImmutableArray <ITypeParameterSymbol>),
                    parameters: default(ImmutableArray <IParameterSymbol>),
                    statements: ImmutableArray.Create(CodeModelService.CreateReturnDefaultValueStatement(type)));
            }

            IMethodSymbol setMethod = null;

            if (generateSetter)
            {
                setMethod = CodeGenerationSymbolFactory.CreateMethodSymbol(
                    attributes: default(ImmutableArray <AttributeData>),
                    accessibility: Accessibility.NotApplicable,
                    modifiers: new DeclarationModifiers(),
                    returnType: null,
                    returnsByRef: false,
                    explicitInterfaceSymbol: null,
                    name: "set_" + name,
                    typeParameters: default(ImmutableArray <ITypeParameterSymbol>),
                    parameters: default(ImmutableArray <IParameterSymbol>));
            }

            var newPropertySymbol = CodeGenerationSymbolFactory.CreatePropertySymbol(
                attributes: default(ImmutableArray <AttributeData>),
                accessibility: CodeModelService.GetAccessibility(access, SymbolKind.Field, destination),
                modifiers: new DeclarationModifiers(),
                type: type,
                returnsByRef: false,
                explicitInterfaceSymbol: null,
                name: name,
                parameters: default(ImmutableArray <IParameterSymbol>),
                getMethod: getMethod,
                setMethod: setMethod);

            return(CodeGenerationService.CreatePropertyDeclaration(
                       newPropertySymbol, destination,
                       options: GetCodeGenerationOptions(access, containerNode.SyntaxTree.Options)));
        }