예제 #1
0
            private ISymbol GenerateMethod(
                Compilation compilation,
                IMethodSymbol method,
                Accessibility accessibility,
                DeclarationModifiers modifiers,
                bool generateAbstractly,
                bool useExplicitInterfaceSymbol,
                string memberName,
                CancellationToken cancellationToken)
            {
                var syntaxFacts = this.Document.GetLanguageService <ISyntaxFactsService>();

                var updatedMethod = method.EnsureNonConflictingNames(
                    this.State.ClassOrStructType, syntaxFacts, cancellationToken);

                updatedMethod = updatedMethod.RemoveInaccessibleAttributesAndAttributesOfType(
                    accessibleWithin: this.State.ClassOrStructType,
                    removeAttributeType: compilation.ComAliasNameAttributeType());

                return(CodeGenerationSymbolFactory.CreateMethodSymbol(
                           updatedMethod,
                           accessibility: accessibility,
                           modifiers: modifiers,
                           explicitInterfaceSymbol: useExplicitInterfaceSymbol ? updatedMethod : null,
                           name: memberName,
                           statements: generateAbstractly ? null : new[] { CreateStatement(compilation, updatedMethod, cancellationToken) }));
            }
            private ISymbol GenerateMethod(
                Compilation compilation,
                IMethodSymbol method,
                Accessibility accessibility,
                DeclarationModifiers modifiers,
                bool generateAbstractly,
                bool useExplicitInterfaceSymbol,
                string memberName,
                CancellationToken cancellationToken)
            {
                var syntaxFacts = this.Document.GetLanguageService<ISyntaxFactsService>();

                var updatedMethod = method.EnsureNonConflictingNames(
                    this.State.ClassOrStructType, syntaxFacts, cancellationToken);

                updatedMethod = updatedMethod.RemoveAttributeFromParametersAndReturnType(compilation.ComAliasNameAttributeType());

                return CodeGenerationSymbolFactory.CreateMethodSymbol(
                    updatedMethod,
                    accessibility: accessibility,
                    modifiers: modifiers,
                    explicitInterfaceSymbol: useExplicitInterfaceSymbol ? updatedMethod : null,
                    name: memberName,
                    statements: generateAbstractly ? null : new[] { CreateStatement(compilation, updatedMethod, cancellationToken) });
            }
예제 #3
0
            private ISymbol GenerateProperty(
                Compilation compilation,
                IPropertySymbol property,
                Accessibility accessibility,
                DeclarationModifiers modifiers,
                bool generateAbstractly,
                bool useExplicitInterfaceSymbol,
                string memberName,
                CancellationToken cancellationToken)
            {
                var factory = this.Document.GetLanguageService <SyntaxGenerator>();
                var comAliasNameAttribute = compilation.ComAliasNameAttributeType();

                var getAccessor = property.GetMethod == null
                    ? null
                    : CodeGenerationSymbolFactory.CreateAccessorSymbol(
                    property.GetMethod.RemoveInaccessibleAttributesAndAttributesOfType(
                        accessibleWithin: this.State.ClassOrStructType,
                        removeAttributeType: comAliasNameAttribute),
                    attributes: null,
                    accessibility: accessibility,
                    explicitInterfaceSymbol: useExplicitInterfaceSymbol ? property.GetMethod : null,
                    statements: GetGetAccessorStatements(compilation, property, generateAbstractly, cancellationToken));

                var setAccessor = property.SetMethod == null
                    ? null
                    : CodeGenerationSymbolFactory.CreateAccessorSymbol(
                    property.SetMethod.RemoveInaccessibleAttributesAndAttributesOfType(
                        accessibleWithin: this.State.ClassOrStructType,
                        removeAttributeType: comAliasNameAttribute),
                    attributes: null,
                    accessibility: accessibility,
                    explicitInterfaceSymbol: useExplicitInterfaceSymbol ? property.SetMethod : null,
                    statements: GetSetAccessorStatements(compilation, property, generateAbstractly, cancellationToken));

                var syntaxFacts    = Document.GetLanguageService <ISyntaxFactsService>();
                var parameterNames = NameGenerator.EnsureUniqueness(
                    property.Parameters.Select(p => p.Name).ToList(), isCaseSensitive: syntaxFacts.IsCaseSensitive);

                var updatedProperty = property.RenameParameters(parameterNames);

                updatedProperty = updatedProperty.RemoveAttributeFromParameters(comAliasNameAttribute);

                // TODO(cyrusn): Delegate through throughMember if it's non-null.
                return(CodeGenerationSymbolFactory.CreatePropertySymbol(
                           updatedProperty,
                           accessibility: accessibility,
                           modifiers: modifiers,
                           explicitInterfaceSymbol: useExplicitInterfaceSymbol ? property : null,
                           name: memberName,
                           getMethod: getAccessor,
                           setMethod: setAccessor));
            }
            private ISymbol GenerateProperty(
                Compilation compilation,
                IPropertySymbol property,
                Accessibility accessibility,
                DeclarationModifiers modifiers,
                bool generateAbstractly,
                bool useExplicitInterfaceSymbol,
                string memberName,
                CancellationToken cancellationToken)
            {
                var factory = this.Document.GetLanguageService<SyntaxGenerator>();
                var comAliasNameAttribute = compilation.ComAliasNameAttributeType();

                var getAccessor = property.GetMethod == null
                    ? null
                    : CodeGenerationSymbolFactory.CreateAccessorSymbol(
                        property.GetMethod.RemoveInaccessibleAttributesAndAttributesOfType(
                            accessibleWithin: this.State.ClassOrStructType,
                            removeAttributeType: comAliasNameAttribute),
                        attributes: null,
                        accessibility: accessibility,
                        explicitInterfaceSymbol: useExplicitInterfaceSymbol ? property.GetMethod : null,
                        statements: GetGetAccessorStatements(compilation, property, generateAbstractly, cancellationToken));

                var setAccessor = property.SetMethod == null
                    ? null
                    : CodeGenerationSymbolFactory.CreateAccessorSymbol(
                        property.SetMethod.RemoveInaccessibleAttributesAndAttributesOfType(
                            accessibleWithin: this.State.ClassOrStructType,
                            removeAttributeType: comAliasNameAttribute),
                        attributes: null,
                        accessibility: accessibility,
                        explicitInterfaceSymbol: useExplicitInterfaceSymbol ? property.SetMethod : null,
                        statements: GetSetAccessorStatements(compilation, property, generateAbstractly, cancellationToken));

                var syntaxFacts = Document.GetLanguageService<ISyntaxFactsService>();
                var parameterNames = NameGenerator.EnsureUniqueness(
                    property.Parameters.Select(p => p.Name).ToList(), isCaseSensitive: syntaxFacts.IsCaseSensitive);

                var updatedProperty = property.RenameParameters(parameterNames);

                updatedProperty = updatedProperty.RemoveAttributeFromParameters(comAliasNameAttribute);

                // TODO(cyrusn): Delegate through throughMember if it's non-null.
                return CodeGenerationSymbolFactory.CreatePropertySymbol(
                    updatedProperty,
                    accessibility: accessibility,
                    modifiers: modifiers,
                    explicitInterfaceSymbol: useExplicitInterfaceSymbol ? property : null,
                    name: memberName,
                    getMethod: getAccessor,
                    setMethod: setAccessor);
            }
 /// <summary>
 /// Lists compiler attributes that we want to remove.
 /// The TupleElementNames attribute is compiler generated (it is used for naming tuple element names).
 /// We never want to place it in source code.
 /// Same thing for the Dynamic attribute.
 /// </summary>
 private INamedTypeSymbol[] AttributesToRemove(Compilation compilation)
 {
     return new[] { compilation.ComAliasNameAttributeType(), compilation.TupleElementNamesAttributeType(),
         compilation.DynamicAttributeType() };
 }
 /// <summary>
 /// Lists compiler attributes that we want to remove.
 /// The TupleElementNames attribute is compiler generated (it is used for naming tuple element names).
 /// We never want to place it in source code.
 /// Same thing for the Dynamic attribute.
 /// </summary>
 private INamedTypeSymbol[] AttributesToRemove(Compilation compilation)
 {
     return(new[] { compilation.ComAliasNameAttributeType(), compilation.TupleElementNamesAttributeType(),
                    compilation.DynamicAttributeType() });
 }
예제 #7
0
            private ISymbol GenerateMethod(
                Compilation compilation,
                IMethodSymbol method,
                Accessibility accessibility,
                DeclarationModifiers modifiers,
                bool generateAbstractly,
                bool useExplicitInterfaceSymbol,
                string memberName,
                CancellationToken cancellationToken)
            {
                var updatedMethod = method.EnsureNonConflictingNames(
                    this.State.ClassOrStructType, cancellationToken);

                updatedMethod = updatedMethod.RemoveAttributeFromParametersAndReturnType(compilation.ComAliasNameAttributeType());

                return(CodeGenerationSymbolFactory.CreateMethodSymbol(
                           updatedMethod,
                           accessibility: accessibility,
                           modifiers: modifiers,
                           explicitInterfaceSymbol: useExplicitInterfaceSymbol ? updatedMethod : null,
                           name: memberName,
                           statements: generateAbstractly ? null : new[] { CreateStatement(compilation, updatedMethod, cancellationToken) }));
            }