當前位置: 首頁>>代碼示例>>C#>>正文


C# Syntax.AccessorDeclarationSyntax類代碼示例

本文整理匯總了C#中Microsoft.CodeAnalysis.CSharp.Syntax.AccessorDeclarationSyntax的典型用法代碼示例。如果您正苦於以下問題:C# AccessorDeclarationSyntax類的具體用法?C# AccessorDeclarationSyntax怎麽用?C# AccessorDeclarationSyntax使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AccessorDeclarationSyntax類屬於Microsoft.CodeAnalysis.CSharp.Syntax命名空間,在下文中一共展示了AccessorDeclarationSyntax類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: IsInMethodDeclaration

        internal static bool IsInMethodDeclaration(int position, AccessorDeclarationSyntax accessorDecl)
        {
            Debug.Assert(accessorDecl != null);

            var body = accessorDecl.Body;
            SyntaxToken lastToken = body == null ? accessorDecl.SemicolonToken : body.CloseBraceToken;
            return IsBeforeToken(position, accessorDecl, lastToken);
        }
開發者ID:riversky,項目名稱:roslyn,代碼行數:8,代碼來源:LookupPosition.cs

示例2: VisitAccessorDeclaration

			/// <summary>
			/// Called when the visitor visits a AccessorDeclarationSyntax node.
			/// </summary>
			public override void VisitAccessorDeclaration(AccessorDeclarationSyntax node)
			{
				if (node.Body == null)
				{
					_counter++;
				}

				base.VisitAccessorDeclaration(node);
			}
開發者ID:jjrdk,項目名稱:ArchiMetrics,代碼行數:12,代碼來源:LinesOfCodeCalculator.cs

示例3: GetBackingFieldFromGetter

        private IFieldSymbol GetBackingFieldFromGetter(AccessorDeclarationSyntax getter)
        {
            if (getter.Body?.Statements.Count != 1) return null;

            var statement = getter.Body.Statements.Single() as ReturnStatementSyntax;
            if (statement?.Expression == null) return null;

            return _semanticModel.GetSymbolInfo(statement.Expression).Symbol as IFieldSymbol;
        }
開發者ID:CNinnovation,項目名稱:TechConference2016,代碼行數:9,代碼來源:AutoPropertyRewriter.cs

示例4: GetActions

        protected IEnumerable<CodeAction> GetActions(Document document, SyntaxNode root, MethodDeclarationSyntax methodNode, AccessorDeclarationSyntax getterNode)
        {
            if (methodNode != null)
                return GetActions(document, root, methodNode);

            if (getterNode != null)
                return GetActions(document, root, getterNode);

            return Enumerable.Empty<CodeAction>();
        }
開發者ID:alecor191,項目名稱:RefactoringEssentials,代碼行數:10,代碼來源:ContractEnsuresNotNullReturnRefactoringProvider.cs

示例5: VisitAccessorDeclaration

		public override void VisitAccessorDeclaration(AccessorDeclarationSyntax node)
		{
			if (!this.InsideFluentOrInitializerExample) return;
			var syntaxNode = node?.ChildNodes()?.LastOrDefault()?.WithAdditionalAnnotations() as BlockSyntax;
			if (syntaxNode == null) return;
			var line = node.SyntaxTree.GetLineSpan(node.Span).StartLinePosition.Line;
			var walker = new CodeWithDocumentationWalker(ClassDepth, line);
			walker.VisitBlock(syntaxNode);
			this.Blocks.AddRange(walker.Blocks);
		}
開發者ID:jeroenheijmans,項目名稱:elasticsearch-net,代碼行數:10,代碼來源:DocumentationFileWalker.cs

示例6: TryGetAccessors

        /// <summary>
        /// Retrieves the get and set accessor declarations of the specified property.
        /// Returns true if both get and set accessors exist; otherwise false.
        /// </summary>
        internal static bool TryGetAccessors(
            PropertyDeclarationSyntax property,
            out AccessorDeclarationSyntax getter,
            out AccessorDeclarationSyntax setter)
        {
            var accessors = property.AccessorList.Accessors;
            getter = accessors.FirstOrDefault(ad => ad.Kind() == SyntaxKind.GetAccessorDeclaration);
            setter = accessors.FirstOrDefault(ad => ad.Kind() == SyntaxKind.SetAccessorDeclaration);

            return accessors.Count == 2 && getter != null && setter != null;
        }
開發者ID:Rickinio,項目名稱:roslyn,代碼行數:15,代碼來源:ExpansionChecker.cs

示例7: GetMessageArgument

 static string GetMessageArgument(AccessorDeclarationSyntax node)
 {
     switch (node.Kind())
     {
         case SyntaxKind.SetAccessorDeclaration:
             return GettextCatalog.GetString("setter");
         case SyntaxKind.AddAccessorDeclaration:
             return GettextCatalog.GetString("add accessor");
         case SyntaxKind.RemoveAccessorDeclaration:
             return GettextCatalog.GetString("remove accessor");
     }
     return null;
 }
開發者ID:pgrefviau,項目名稱:RefactoringEssentials,代碼行數:13,代碼來源:ValueParameterNotUsedAnalyzer.cs

示例8: VisitAccessorDeclaration

        public override void VisitAccessorDeclaration(AccessorDeclarationSyntax node)
        {
            if (node.Body != null && node.Parent is BasePropertyDeclarationSyntax)
              {
            var z = model.GetDeclaredSymbol(node.Parent as PropertyDeclarationSyntax);

            cb.AppendWithIndent(z.Type.ToCppType())
              .Append(" ")
              .Append(settings.GetPrefix)
              .Append(z.Name)
              .AppendLine("() const");
              }
              base.VisitAccessorDeclaration(node);
        }
開發者ID:Drakonoffnet,項目名稱:Blackmire,代碼行數:14,代碼來源:CppHeaderWalker.cs

示例9: CreateAccessorSymbol

        public static SourcePropertyAccessorSymbol CreateAccessorSymbol(
            NamedTypeSymbol containingType,
            SourcePropertySymbol property,
            DeclarationModifiers propertyModifiers,
            string propertyName,
            AccessorDeclarationSyntax syntax,
            PropertySymbol explicitlyImplementedPropertyOpt,
            string aliasQualifierOpt,
            bool isAutoPropertyAccessor,
            DiagnosticBag diagnostics)
        {
            Debug.Assert(syntax.Kind == SyntaxKind.GetAccessorDeclaration || syntax.Kind == SyntaxKind.SetAccessorDeclaration);

            bool isGetMethod = (syntax.Kind == SyntaxKind.GetAccessorDeclaration);
            bool isWinMd = property.IsCompilationOutputWinMdObj();
            string name;
            ImmutableArray<MethodSymbol> explicitInterfaceImplementations;
            if ((object)explicitlyImplementedPropertyOpt == null)
            {
                name = GetAccessorName(propertyName, isGetMethod, isWinMd);
                explicitInterfaceImplementations = ImmutableArray<MethodSymbol>.Empty;
            }
            else
            {
                MethodSymbol implementedAccessor = isGetMethod ? explicitlyImplementedPropertyOpt.GetMethod : explicitlyImplementedPropertyOpt.SetMethod;
                string accessorName = (object)implementedAccessor != null ? implementedAccessor.Name
                    : GetAccessorName(explicitlyImplementedPropertyOpt.MetadataName, isGetMethod, isWinMd); //Not name - could be indexer placeholder
                name = ExplicitInterfaceHelpers.GetMemberName(accessorName, explicitlyImplementedPropertyOpt.ContainingType, aliasQualifierOpt);
                explicitInterfaceImplementations =
                    (object)implementedAccessor == null ?
                        ImmutableArray<MethodSymbol>.Empty :
                        ImmutableArray.Create<MethodSymbol>(implementedAccessor);
            }

            var methodKind = isGetMethod ? MethodKind.PropertyGet : MethodKind.PropertySet;
            return new SourcePropertyAccessorSymbol(
                containingType,
                name,
                property,
                propertyModifiers,
                explicitInterfaceImplementations,
                syntax.Keyword.GetLocation(),
                syntax,
                methodKind,
                isAutoPropertyAccessor,
                diagnostics);
        }
開發者ID:riversky,項目名稱:roslyn,代碼行數:47,代碼來源:SourcePropertyAccessorSymbol.cs

示例10: FindIssuesInAccessor

        static bool FindIssuesInAccessor(SemanticModel semanticModel, AccessorDeclarationSyntax accessor)
        {
            var body = accessor.Body;
            if (!IsEligible(body))
                return false;

            if (body.Statements.Any())
            {
                var foundValueSymbol = semanticModel.LookupSymbols(body.Statements.First().SpanStart, null, "value").FirstOrDefault();
                if (foundValueSymbol == null)
                    return false;

                foreach (var valueRef in body.DescendantNodes().OfType<IdentifierNameSyntax>().Where(ins => ins.Identifier.ValueText == "value"))
                {
                    var valueRefSymbol = semanticModel.GetSymbolInfo(valueRef).Symbol;
                    if (foundValueSymbol.Equals(valueRefSymbol))
                        return false;
                }
            }

            return true;
        }
開發者ID:pgrefviau,項目名稱:RefactoringEssentials,代碼行數:22,代碼來源:ValueParameterNotUsedAnalyzer.cs

示例11: CreateAccessorSymbol

        public static SourcePropertyAccessorSymbol CreateAccessorSymbol(
            NamedTypeSymbol containingType,
            SourcePropertySymbol property,
            DeclarationModifiers propertyModifiers,
            string propertyName,
            AccessorDeclarationSyntax syntax,
            PropertySymbol explicitlyImplementedPropertyOpt,
            string aliasQualifierOpt,
            bool isAutoPropertyAccessor,
            DiagnosticBag diagnostics)
        {
            Debug.Assert(syntax.Kind() == SyntaxKind.GetAccessorDeclaration || syntax.Kind() == SyntaxKind.SetAccessorDeclaration);

            bool isGetMethod = (syntax.Kind() == SyntaxKind.GetAccessorDeclaration);
            string name;
            ImmutableArray<MethodSymbol> explicitInterfaceImplementations;
            GetNameAndExplicitInterfaceImplementations(
                explicitlyImplementedPropertyOpt,
                propertyName,
                property.IsCompilationOutputWinMdObj(),
                aliasQualifierOpt,
                isGetMethod,
                out name,
                out explicitInterfaceImplementations);

            var methodKind = isGetMethod ? MethodKind.PropertyGet : MethodKind.PropertySet;
            return new SourcePropertyAccessorSymbol(
                containingType,
                name,
                property,
                propertyModifiers,
                explicitInterfaceImplementations,
                syntax.Keyword.GetLocation(),
                syntax,
                methodKind,
                isAutoPropertyAccessor,
                diagnostics);
        }
開發者ID:SoumikMukherjeeDOTNET,項目名稱:roslyn,代碼行數:38,代碼來源:SourcePropertyAccessorSymbol.cs

示例12: TryGetFieldFromGetter

        private static bool TryGetFieldFromGetter(AccessorDeclarationSyntax getter, SemanticModel semanticModel, out IFieldSymbol getterField)
        {
            getterField = null;
            if (getter.Body == null ||
                getter.Body.Statements.Count != 1)
            {
                return false;
            }

            var statement = getter.Body.Statements[0] as ReturnStatementSyntax;
            if (statement == null ||
                statement.Expression == null)
            {
                return false;
            }

            return TryGetField(statement.Expression, semanticModel.GetDeclaredSymbol(getter).ContainingType,
                semanticModel, out getterField);
        }
開發者ID:duncanpMS,項目名稱:sonarlint-vs,代碼行數:19,代碼來源:PropertyToAutoProperty.cs

示例13: TryGetFieldFromSetter

        private static bool TryGetFieldFromSetter(AccessorDeclarationSyntax setter, SemanticModel semanticModel, out IFieldSymbol setterField)
        {
            setterField = null;
            if (setter.Body == null ||
                setter.Body.Statements.Count != 1)
            {
                return false;
            }

            var statement = setter.Body.Statements[0] as ExpressionStatementSyntax;
            var assignment = statement?.Expression as AssignmentExpressionSyntax;
            if (assignment == null ||
                !assignment.IsKind(SyntaxKind.SimpleAssignmentExpression))
            {
                return false;
            }

            var parameter = semanticModel.GetSymbolInfo(assignment.Right).Symbol as IParameterSymbol;
            if (parameter == null ||
                parameter.Name != "value" ||
                !parameter.IsImplicitlyDeclared)
            {
                return false;
            }

            return TryGetField(assignment.Left, semanticModel.GetDeclaredSymbol(setter).ContainingType,
                semanticModel, out setterField);
        }
開發者ID:duncanpMS,項目名稱:sonarlint-vs,代碼行數:28,代碼來源:PropertyToAutoProperty.cs

示例14: GetModifierKinds

 private static IEnumerable<SyntaxKind> GetModifierKinds(AccessorDeclarationSyntax accessor)
 {
     return accessor.Modifiers.Select(m => m.Kind());
 }
開發者ID:duncanpMS,項目名稱:sonarlint-vs,代碼行數:4,代碼來源:PropertyToAutoProperty.cs

示例15: IsMultiline

 private static bool IsMultiline(AccessorDeclarationSyntax accessorDeclaration)
 {
     var lineSpan = accessorDeclaration.GetLineSpan();
     return lineSpan.StartLinePosition.Line != lineSpan.EndLinePosition.Line;
 }
開發者ID:EdwinEngelen,項目名稱:StyleCopAnalyzers,代碼行數:5,代碼來源:SA1516ElementsMustBeSeparatedByBlankLine.cs


注:本文中的Microsoft.CodeAnalysis.CSharp.Syntax.AccessorDeclarationSyntax類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。