当前位置: 首页>>代码示例>>C#>>正文


C# INamedTypeSymbol.GetMembers方法代码示例

本文整理汇总了C#中INamedTypeSymbol.GetMembers方法的典型用法代码示例。如果您正苦于以下问题:C# INamedTypeSymbol.GetMembers方法的具体用法?C# INamedTypeSymbol.GetMembers怎么用?C# INamedTypeSymbol.GetMembers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在INamedTypeSymbol的用法示例。


在下文中一共展示了INamedTypeSymbol.GetMembers方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CheckOperators

 private void CheckOperators(
     SymbolAnalysisContext analysisContext, INamedTypeSymbol namedType,
     string memberName1, string memberName2,
     string opName1, string opName2)
 {
     var operators1 = namedType.GetMembers(memberName1);
     var operators2 = namedType.GetMembers(memberName2);
     CheckOperators(analysisContext, namedType, operators1, operators2, opName1, opName2);
     CheckOperators(analysisContext, namedType, operators2, operators1, opName2, opName1);
 }
开发者ID:Anniepoh,项目名称:roslyn-analyzers,代码行数:10,代码来源:OperatorsShouldHaveSymmetricalOverloads.cs

示例2: VisitNamedType

 public override void VisitNamedType(INamedTypeSymbol symbol)
 {
     foreach (var member in symbol.GetMembers())
     {
         member.Accept(this);
     }
 }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:7,代码来源:AbstractEntryPointFinder.cs

示例3: AnalyzeSymbol

 private void AnalyzeSymbol(INamedTypeSymbol symbol, Compilation compilation, Action<Diagnostic> addDiagnostic)
 {
     if (symbol.GetMembers().Any(member => IsDllImport(member)) && !IsTypeNamedCorrectly(symbol.Name))
     {
         addDiagnostic(symbol.CreateDiagnostic(Rule));
     }
 }
开发者ID:Anniepoh,项目名称:roslyn-analyzers,代码行数:7,代码来源:MovePInvokesToNativeMethodsClass.cs

示例4: GetAutoPropsWithPrivateSetters

        private static HashSet<ISymbol> GetAutoPropsWithPrivateSetters(INamedTypeSymbol type, CancellationToken cancellationToken)
        {
            HashSet<ISymbol> candidates = null;

            var allProperties = type.GetMembers().Where(s => s.Kind == SymbolKind.Property);
            foreach (var property in allProperties)
            {
                var propertySymbol = (IPropertySymbol)property;
                if (!propertySymbol.IsReadOnly && propertySymbol.ExplicitInterfaceImplementations.IsDefaultOrEmpty)
                {
                    var setMethod = propertySymbol.SetMethod;
                    if (setMethod != null && setMethod.DeclaredAccessibility == Accessibility.Private)
                    {
                        // Find the syntax for the setter.
                        var reference = setMethod.DeclaringSyntaxReferences.FirstOrDefault();
                        if (reference != null)
                        {
                            var declaration = reference.GetSyntax(cancellationToken) as AccessorDeclarationSyntax;
                            if (declaration != null && declaration.Body == null)
                            {
                                // An empty body indicates it's an auto-prop
                                (candidates ?? (candidates = new HashSet<ISymbol>())).Add(propertySymbol);
                            }
                        }
                    }
                }
            }

            return candidates;
        }
开发者ID:CyrusNajmabadi,项目名称:CSharpEssentials,代码行数:30,代码来源:UseGetterOnlyAutoPropertyAnalyzer.cs

示例5: AnalyzeSymbol

 private void AnalyzeSymbol(INamedTypeSymbol symbol, Compilation compilation, Action<Diagnostic> addDiagnostic)
 {
     if (symbol.GetMembers().Any(member => IsDllImport(member)) && !IsTypeNamedCorrectly(symbol.Name))
     {
         addDiagnostic(Diagnostic.Create(Rule, symbol.Locations.First(l => l.IsInSource)));
     }
 }
开发者ID:maggiemsft,项目名称:roslyn-analyzers,代码行数:7,代码来源:MovePInvokesToNativeMethodsClass.cs

示例6: AddDisposeDeclarationToDisposeMethod

 private static TypeDeclarationSyntax AddDisposeDeclarationToDisposeMethod(VariableDeclaratorSyntax variableDeclarator, TypeDeclarationSyntax type, INamedTypeSymbol typeSymbol)
 {
     var disposableMethod = typeSymbol.GetMembers("Dispose").OfType<IMethodSymbol>().FirstOrDefault(d => d.Arity == 0);
     var disposeStatement = SyntaxFactory.ParseStatement($"{variableDeclarator.Identifier.ToString()}.Dispose();");
     TypeDeclarationSyntax newType;
     if (disposableMethod == null)
     {
         var disposeMethod = SyntaxFactory.MethodDeclaration(SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.VoidKeyword)), "Dispose")
               .WithModifiers(SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.PublicKeyword)))
               .WithBody(SyntaxFactory.Block(disposeStatement))
               .WithAdditionalAnnotations(Formatter.Annotation);
         newType = ((dynamic)type).AddMembers(disposeMethod);
     }
     else
     {
         var existingDisposeMethod = (MethodDeclarationSyntax)disposableMethod.DeclaringSyntaxReferences.FirstOrDefault()?.GetSyntax();
         if (type.Members.Contains(existingDisposeMethod))
         {
             var newDisposeMethod = existingDisposeMethod.AddBodyStatements(disposeStatement)
                 .WithAdditionalAnnotations(Formatter.Annotation);
             newType = type.ReplaceNode(existingDisposeMethod, newDisposeMethod);
         }
         else
         {
             //we will simply anotate the code for now, but ideally we would change another document
             //for this to work we have to be able to fix more than one doc
             var fieldDeclaration = variableDeclarator.Parent.Parent;
             var newFieldDeclaration = fieldDeclaration.WithTrailingTrivia(SyntaxFactory.ParseTrailingTrivia($"//add {disposeStatement.ToString()} to the Dispose method on another file.").AddRange(fieldDeclaration.GetTrailingTrivia()))
                 .WithLeadingTrivia(fieldDeclaration.GetLeadingTrivia());
             newType = type.ReplaceNode(fieldDeclaration, newFieldDeclaration);
         }
     }
     return newType;
 }
开发者ID:haroldhues,项目名称:code-cracker,代码行数:34,代码来源:DisposableFieldNotDisposedCodeFixProvider.cs

示例7: AnalyzeSymbol

 public override void AnalyzeSymbol(INamedTypeSymbol symbol, Compilation compilation, Action<Diagnostic> addDiagnostic, AnalyzerOptions options, CancellationToken cancellationToken)
 {
     if (symbol.GetMembers().Any(member => IsDllImport(member)) && !IsTypeNamedCorrectly(symbol.Name))
     {
         addDiagnostic(symbol.CreateDiagnostic(Rule));
     }
 }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:7,代码来源:CA1060DiagnosticAnalyzer.cs

示例8: GetVisitMethods

		private IEnumerable<IMethodSymbol> GetVisitMethods(INamedTypeSymbol type, bool inherited = true)
		{
			foreach (var member in type.GetMembers())
			{
				var method = member as IMethodSymbol;

				if (method != null)
				{
					if ((method.IsOverride || method.IsVirtual) && method.Name.StartsWith("Visit") && method.Parameters.Length == 1)
					{
						var param = method.Parameters[0];

						yield return method;
					}
				}
			}

			if (type.BaseType != null && inherited)
			{
				foreach (var member in this.GetVisitMethods(type.BaseType))
				{
					yield return member;
				}
			}
		}
开发者ID:tumtumtum,项目名称:Shaolinq,代码行数:25,代码来源:ExpressionComparerWriter.cs

示例9: CountAccessibleProperties

 private int CountAccessibleProperties(INamedTypeSymbol namedTypeSymbol)
 {
     //Determining which properties are accessible is a difficult problem.
     //Do something simple for now.
     return namedTypeSymbol.GetMembers()
         .OfType<IPropertySymbol>()
         .Count(p => !p.IsStatic && !p.IsReadOnly && !p.IsWriteOnly && (p.DeclaredAccessibility == Accessibility.Public));
 }
开发者ID:tategriffin,项目名称:Cartographer,代码行数:8,代码来源:PropertyCountComparer.cs

示例10: ContainsNonPrivateConstructors

        public static bool ContainsNonPrivateConstructors(INamedTypeSymbol symbol)
        {
            if (IsNestedPrivateType(symbol))
                return false;

            return symbol.GetMembers()
                .Any(m => m.MetadataName == ".ctor" && m.DeclaredAccessibility != Accessibility.Private);
        }
开发者ID:Bemjamin,项目名称:code-cracker,代码行数:8,代码来源:DisposablesShouldCallSuppressFinalizeAnalyzer.cs

示例11: GetMembers

        protected override IEnumerable<ISymbol> GetMembers(INamedTypeSymbol type, string name)
        {
            var members = type.GetMembers()
                              .Where(m => m.Name == name ||
                                          m.ExplicitInterfaceImplementations()
                                           .Where(i => i.Name == name)
                                           .Any());

            return (type.Name == name) ? members.Concat(type.Constructors) : members;
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:10,代码来源:BreakpointResolver.cs

示例12: Create

            public static void Create(INamedTypeSymbol symbol, SymbolKeyWriter visitor)
            {
                Debug.Assert(symbol.IsAnonymousType);

                var properties = symbol.GetMembers().OfType<IPropertySymbol>().ToArray();
                var propertyTypes = properties.Select(p => p.Type).ToImmutableArray();
                var propertyNames = properties.Select(p => p.Name).ToImmutableArray();

                visitor.WriteSymbolKeyArray(propertyTypes);
                visitor.WriteStringArray(propertyNames);
            }
开发者ID:Rickinio,项目名称:roslyn,代码行数:11,代码来源:SymbolKey.AnonymousTypeSymbolKey.cs

示例13: Create

            public static void Create(INamedTypeSymbol symbol, SymbolKeyWriter visitor)
            {
                Debug.Assert(symbol.IsTupleType);
                visitor.WriteSymbolKey(symbol.TupleUnderlyingType);
                visitor.WriteStringArray(symbol.TupleElementNames);

                var locations = ArrayBuilder<Location>.GetInstance();
                for (var i = 0; i < symbol.TupleElementTypes.Length; i++)
                {
                    locations.Add(symbol.GetMembers("Item" + (i + 1)).FirstOrDefault()?.Locations.FirstOrDefault());
                }

                visitor.WriteLocationArray(locations.ToImmutableAndFree());
            }
开发者ID:jkotas,项目名称:roslyn,代码行数:14,代码来源:SymbolKey.TupleTypeSymbolKey.cs

示例14: BuildSourceToTargetMappingStatements

        protected List<StatementSyntax> BuildSourceToTargetMappingStatements(INamedTypeSymbol sourceSymbol, string sourceVariableName, INamedTypeSymbol targetSymbol, string targetVariableName)
        {
            //TODO: Improve the where clause selection criteria. Should only include properties which are truely accessible from the source symbol.
            var sourceProperties = sourceSymbol.GetMembers().OfType<IPropertySymbol>()
                .Where(p => !p.IsStatic && !p.IsWriteOnly && (p.DeclaredAccessibility == Accessibility.Public || p.DeclaredAccessibility == Accessibility.Internal))
                .OrderBy(p => p.Name)
                .ToList();
            var targetProperties = targetSymbol.GetMembers().OfType<IPropertySymbol>()
                .Where(p => !p.IsStatic && !p.IsReadOnly && (p.DeclaredAccessibility == Accessibility.Public || p.DeclaredAccessibility == Accessibility.Internal))
                .OrderBy(p => p.Name)
                .ToList();

            return BuildSourceToTargetMappingStatements(sourceProperties, sourceVariableName, targetProperties, targetVariableName);
        }
开发者ID:tategriffin,项目名称:Cartographer,代码行数:14,代码来源:ClassMapper.cs

示例15: ParseEvents

 internal void ParseEvents(SDType sdType, INamedTypeSymbol typeSymbol)
 {
     var events = typeSymbol.GetMembers().Where(m => m.Kind == SymbolKind.Event).Select(m => m as IEventSymbol);
     foreach (var eve in events)
     {
         if (!IsMemberExcluded(eve.GetIdentifier(), eve.DeclaredAccessibility))
         {
             var parsedEvent = GetParsedEvent(eve);
             if (sdType.Events.SingleOrDefault(f => f.Name == parsedEvent.Name) == null)
             {
                 sdType.Events.Add(parsedEvent);
             }
         }
     }
 }
开发者ID:Geaz,项目名称:sharpDox,代码行数:15,代码来源:EventParser.cs


注:本文中的INamedTypeSymbol.GetMembers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。