本文整理汇总了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);
}
示例2: VisitNamedType
public override void VisitNamedType(INamedTypeSymbol symbol)
{
foreach (var member in symbol.GetMembers())
{
member.Accept(this);
}
}
示例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));
}
}
示例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;
}
示例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)));
}
}
示例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;
}
示例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));
}
}
示例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;
}
}
}
示例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));
}
示例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);
}
示例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;
}
示例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);
}
示例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());
}
示例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);
}
示例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);
}
}
}
}