本文整理汇总了C#中INamedTypeSymbol类的典型用法代码示例。如果您正苦于以下问题:C# INamedTypeSymbol类的具体用法?C# INamedTypeSymbol怎么用?C# INamedTypeSymbol使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
INamedTypeSymbol类属于命名空间,在下文中一共展示了INamedTypeSymbol类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryInitializeState
protected override bool TryInitializeState(
Document document, SemanticModel model, SyntaxNode node, CancellationToken cancellationToken,
out INamedTypeSymbol classType, out INamedTypeSymbol abstractClassType)
{
var baseClassNode = node as TypeSyntax;
if (baseClassNode != null && baseClassNode.Parent is BaseTypeSyntax &&
baseClassNode.Parent.IsParentKind(SyntaxKind.BaseList) &&
((BaseTypeSyntax)baseClassNode.Parent).Type == baseClassNode)
{
if (baseClassNode.Parent.Parent.IsParentKind(SyntaxKind.ClassDeclaration))
{
abstractClassType = model.GetTypeInfo(baseClassNode, cancellationToken).Type as INamedTypeSymbol;
cancellationToken.ThrowIfCancellationRequested();
if (abstractClassType.IsAbstractClass())
{
var classDecl = baseClassNode.Parent.Parent.Parent as ClassDeclarationSyntax;
classType = model.GetDeclaredSymbol(classDecl, cancellationToken) as INamedTypeSymbol;
return classType != null && abstractClassType != null;
}
}
}
classType = null;
abstractClassType = null;
return false;
}
示例2: AnalyzeSymbol
public override void AnalyzeSymbol(INamedTypeSymbol symbol, Compilation compilation, Action<Diagnostic> addDiagnostic, CancellationToken cancellationToken)
{
if (symbol.TypeKind != TypeKind.Enum)
{
return;
}
var flagsAttribute = WellKnownTypes.FlagsAttribute(compilation);
if (flagsAttribute == null)
{
return;
}
var zeroValuedFields = GetZeroValuedFields(symbol).ToImmutableArray();
bool hasFlagsAttribute = symbol.GetAttributes().Any(a => a.AttributeClass == flagsAttribute);
if (hasFlagsAttribute)
{
CheckFlags(symbol, zeroValuedFields, addDiagnostic);
}
else
{
CheckNonFlags(symbol, zeroValuedFields, addDiagnostic);
}
}
示例3: 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));
}
}
示例4: BuildDelegateDeclaration
protected override void BuildDelegateDeclaration(INamedTypeSymbol typeSymbol, _VSOBJDESCOPTIONS options)
{
Debug.Assert(typeSymbol.TypeKind == TypeKind.Delegate);
BuildTypeModifiers(typeSymbol);
AddText("delegate ");
var delegateInvokeMethod = typeSymbol.DelegateInvokeMethod;
AddTypeLink(delegateInvokeMethod.ReturnType, LinkFlags.None);
AddText(" ");
var typeQualificationStyle = (options & _VSOBJDESCOPTIONS.ODO_USEFULLNAME) != 0
? SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces
: SymbolDisplayTypeQualificationStyle.NameOnly;
var typeNameFormat = new SymbolDisplayFormat(
typeQualificationStyle: typeQualificationStyle,
genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters | SymbolDisplayGenericsOptions.IncludeVariance);
AddName(typeSymbol.ToDisplayString(typeNameFormat));
AddText("(");
BuildParameterList(delegateInvokeMethod.Parameters);
AddText(")");
if (typeSymbol.IsGenericType)
{
BuildGenericConstraints(typeSymbol);
}
}
示例5: GetMethodOverloadsWithDesiredParameterAtTrailing
/// <summary>
/// Returns a list of method symbols from a given list of the method symbols, which has its parameter type as
/// expectedParameterType as its last parameter in addition to matching all the other parameter types of the
/// selectedOverload method symbol
/// </summary>
/// <param name="methods">List of <see cref="IMethodSymbol"/> to scan for possible overloads</param>
/// <param name="selectedOverload"><see cref="IMethodSymbol"/> that is currently picked by the user</param>
/// <param name="expectedTrailingParameterType"><see cref="INamedTypeSymbol"/> type of the leading parameter or the trailing parameter</param>
public static IEnumerable<IMethodSymbol> GetMethodOverloadsWithDesiredParameterAtTrailing(
this IEnumerable<IMethodSymbol> methods,
IMethodSymbol selectedOverload,
INamedTypeSymbol expectedTrailingParameterType)
{
return GetMethodOverloadsWithDesiredParameterAtLeadingOrTrailing(methods, selectedOverload, expectedTrailingParameterType, trailingOnly: true);
}
示例6: GetDelegateInvokeItems
private IEnumerable<SignatureHelpItem> GetDelegateInvokeItems(
InvocationExpressionSyntax invocationExpression, SemanticModel semanticModel, ISymbolDisplayService symbolDisplayService, IAnonymousTypeDisplayService anonymousTypeDisplayService,
IDocumentationCommentFormattingService documentationCommentFormattingService, ISymbol within, INamedTypeSymbol delegateType, CancellationToken cancellationToken)
{
var invokeMethod = delegateType.DelegateInvokeMethod;
if (invokeMethod == null)
{
return null;
}
// Events can only be invoked directly from the class they were declared in.
var expressionSymbol = semanticModel.GetSymbolInfo(invocationExpression.Expression, cancellationToken).GetAnySymbol();
if (expressionSymbol.IsKind(SymbolKind.Event) &&
!expressionSymbol.ContainingType.OriginalDefinition.Equals(within.OriginalDefinition))
{
return null;
}
var position = invocationExpression.SpanStart;
var item = CreateItem(
invokeMethod, semanticModel, position,
symbolDisplayService, anonymousTypeDisplayService,
isVariadic: invokeMethod.IsParams(),
documentation: SpecializedCollections.EmptyEnumerable<SymbolDisplayPart>(),
prefixParts: GetDelegateInvokePreambleParts(invokeMethod, semanticModel, position),
separatorParts: GetSeparatorParts(),
suffixParts: GetDelegateInvokePostambleParts(),
parameters: GetDelegateInvokeParameters(invokeMethod, semanticModel, position, documentationCommentFormattingService, cancellationToken));
return SpecializedCollections.SingletonEnumerable(item);
}
示例7: AnalyzeSymbol
private void AnalyzeSymbol(SymbolAnalysisContext context, INamedTypeSymbol flagsAttribute)
{
var symbol = (INamedTypeSymbol)context.Symbol;
if (symbol.TypeKind != TypeKind.Enum)
{
return;
}
SpecialType underlyingType = symbol.EnumUnderlyingType.SpecialType;
if (underlyingType == SpecialType.System_Int32)
{
return;
}
// If accessibility of enum is not public exit
if (symbol.GetResultantVisibility() != SymbolVisibility.Public)
{
return;
}
// If enum is Int64 and has Flags attributes then exit
bool hasFlagsAttribute = symbol.GetAttributes().Any(a => a.AttributeClass.Equals(flagsAttribute));
if (underlyingType == SpecialType.System_Int64 && hasFlagsAttribute)
{
return;
}
context.ReportDiagnostic(symbol.CreateDiagnostic(Rule, symbol.Name, symbol.EnumUnderlyingType));
}
示例8: CreateFieldDelegatingConstructor
public static IEnumerable<ISymbol> CreateFieldDelegatingConstructor(
this SyntaxGenerator factory,
string typeName,
INamedTypeSymbol containingTypeOpt,
IList<IParameterSymbol> parameters,
IDictionary<string, ISymbol> parameterToExistingFieldMap,
IDictionary<string, string> parameterToNewFieldMap,
CancellationToken cancellationToken)
{
var fields = factory.CreateFieldsForParameters(parameters, parameterToNewFieldMap);
var statements = factory.CreateAssignmentStatements(parameters, parameterToExistingFieldMap, parameterToNewFieldMap)
.Select(s => s.WithAdditionalAnnotations(Simplifier.Annotation));
foreach (var field in fields)
{
yield return field;
}
yield return CodeGenerationSymbolFactory.CreateConstructorSymbol(
attributes: null,
accessibility: Accessibility.Public,
modifiers: new DeclarationModifiers(),
typeName: typeName,
parameters: parameters,
statements: statements.ToList(),
thisConstructorArguments: GetThisConstructorArguments(containingTypeOpt, parameterToExistingFieldMap));
}
示例9: EventCreationCompletionData
public EventCreationCompletionData (ICompletionDataKeyHandler keyHandler, RoslynCodeCompletionFactory factory, ITypeSymbol delegateType, string varName, INamedTypeSymbol curType) : base (factory, keyHandler)
{
this.DisplayText = varName;
this.delegateType = delegateType;
this.factory = factory;
this.Icon = "md-newmethod";
}
示例10: IsInitializable
protected virtual bool IsInitializable(ISymbol member, INamedTypeSymbol containingType)
{
return
!member.IsStatic &&
member.MatchesKind(SymbolKind.Field, SymbolKind.Property) &&
member.IsAccessibleWithin(containingType);
}
示例11: RemoveAttributeFromParameters
public static IPropertySymbol RemoveAttributeFromParameters(
this IPropertySymbol property, INamedTypeSymbol attributeType)
{
if (attributeType == null)
{
return property;
}
var someParameterHasAttribute = property.Parameters
.Any(p => p.GetAttributes().Any(a => a.AttributeClass.Equals(attributeType)));
if (!someParameterHasAttribute)
{
return property;
}
return CodeGenerationSymbolFactory.CreatePropertySymbol(
property.ContainingType,
property.GetAttributes(),
property.DeclaredAccessibility,
property.GetSymbolModifiers(),
property.Type,
property.ExplicitInterfaceImplementations.FirstOrDefault(),
property.Name,
property.Parameters.Select(p =>
CodeGenerationSymbolFactory.CreateParameterSymbol(
p.GetAttributes().Where(a => !a.AttributeClass.Equals(attributeType)).ToList(),
p.RefKind, p.IsParams, p.Type, p.Name, p.IsOptional,
p.HasExplicitDefaultValue, p.HasExplicitDefaultValue ? p.ExplicitDefaultValue : null)).ToList(),
property.GetMethod,
property.SetMethod,
property.IsIndexer);
}
示例12: FromNamedTypeSymbol
internal static IClassMetadata FromNamedTypeSymbol(INamedTypeSymbol symbol)
{
if (symbol == null) return null;
if (symbol.DeclaredAccessibility != Accessibility.Public || symbol.ToDisplayString() == "object") return null;
return new RoslynClassMetadata(symbol);
}
示例13: AnalyzeSymbol
private void AnalyzeSymbol(SymbolAnalysisContext context, INamedTypeSymbol objectType, INamedTypeSymbol equatableType)
{
var namedType = context.Symbol as INamedTypeSymbol;
if (namedType == null || !(namedType.TypeKind == TypeKind.Struct || namedType.TypeKind == TypeKind.Class))
{
return;
}
var methodSymbol = namedType
.GetMembers("Equals")
.OfType<IMethodSymbol>()
.Where(m => IsObjectEqualsOverride(m, objectType))
.FirstOrDefault();
var overridesObjectEquals = methodSymbol != null;
var constructedEquatable = equatableType.Construct(namedType);
var implementation = namedType
.Interfaces
.Where(x => x.Equals(constructedEquatable))
.FirstOrDefault();
var implementsEquatable = implementation != null;
if (overridesObjectEquals && !implementsEquatable && namedType.TypeKind == TypeKind.Struct)
{
context.ReportDiagnostic(Diagnostic.Create(s_implementIEquatableDescriptor, methodSymbol.Locations[0], namedType));
}
if (!overridesObjectEquals && implementsEquatable)
{
context.ReportDiagnostic(Diagnostic.Create(s_overridesObjectEqualsDescriptor, namedType.Locations[0], namedType));
}
}
示例14: 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;
}
示例15: TryGetTypes
protected bool TryGetTypes(
SyntaxNode expression,
SemanticModel semanticModel,
out INamedTypeSymbol source,
out INamedTypeSymbol destination)
{
source = null;
destination = null;
var info = semanticModel.GetSymbolInfo(expression);
var methodSymbol = info.Symbol as IMethodSymbol;
if (methodSymbol == null)
{
return false;
}
var compilation = semanticModel.Compilation;
var taskType = compilation.GetTypeByMetadataName("System.Threading.Tasks.Task");
if (taskType == null)
{
return false;
}
var returnType = methodSymbol.ReturnType as INamedTypeSymbol;
if (returnType == null)
{
return false;
}
source = taskType;
destination = returnType;
return true;
}