本文整理汇总了C#中INamedTypeSymbol类的典型用法代码示例。如果您正苦于以下问题:C# INamedTypeSymbol类的具体用法?C# INamedTypeSymbol怎么用?C# INamedTypeSymbol使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
INamedTypeSymbol类属于命名空间,在下文中一共展示了INamedTypeSymbol类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:sushihangover,项目名称:monodevelop,代码行数:28,代码来源:CSharpImplementAbstractClassService.cs
示例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);
}
}
开发者ID:pheede,项目名称:roslyn,代码行数:25,代码来源:CA1008DiagnosticAnalyzer.cs
示例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));
}
}
开发者ID:EkardNT,项目名称:Roslyn,代码行数:7,代码来源:CA1060DiagnosticAnalyzer.cs
示例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);
}
}
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:31,代码来源:DescriptionBuilder.cs
示例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);
}
开发者ID:duracellko,项目名称:roslyn-analyzers,代码行数:15,代码来源:IEnumerableOfIMethodSymbolExtensions.cs
示例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);
}
开发者ID:JinGuoGe,项目名称:roslyn,代码行数:31,代码来源:InvocationExpressionSignatureHelpProvider_DelegateInvoke.cs
示例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));
}
开发者ID:Anniepoh,项目名称:roslyn-analyzers,代码行数:30,代码来源:EnumStorageShouldBeInt32.cs
示例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));
}
开发者ID:RoryVL,项目名称:roslyn,代码行数:27,代码来源:ICodeDefinitionFactoryExtensions.cs
示例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";
}
开发者ID:sushihangover,项目名称:monodevelop,代码行数:7,代码来源:EventCreationCompletionData.cs
示例10: IsInitializable
protected virtual bool IsInitializable(ISymbol member, INamedTypeSymbol containingType)
{
return
!member.IsStatic &&
member.MatchesKind(SymbolKind.Field, SymbolKind.Property) &&
member.IsAccessibleWithin(containingType);
}
开发者ID:noahstein,项目名称:roslyn,代码行数:7,代码来源:AbstractObjectInitializerCompletionProvider.cs
示例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);
}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:32,代码来源:IPropertySymbolExtensions.cs
示例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);
}
开发者ID:FreeFrags,项目名称:Typewriter,代码行数:7,代码来源:RoslynClassMetadata.cs
示例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));
}
}
开发者ID:nevinclement,项目名称:roslyn,代码行数:32,代码来源:EquatableAnalyzer.cs
示例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;
}
开发者ID:haroldhues,项目名称:code-cracker,代码行数:34,代码来源:DisposableFieldNotDisposedCodeFixProvider.cs
示例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;
}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:33,代码来源:CSharpAddAsyncCodeFixProvider.cs
示例16: SuggestedHandlerCompletionData
public SuggestedHandlerCompletionData (MonoDevelop.Projects.Project project, CodeMemberMethod methodInfo, INamedTypeSymbol codeBehindClass, Location codeBehindClassLocation)
{
this.project = project;
this.methodInfo = methodInfo;
this.codeBehindClass = codeBehindClass;
this.codeBehindClassLocation = codeBehindClassLocation;
}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:7,代码来源:SuggestedHandlerCompletionData.cs
示例17: SetBaseTypeAsync
/// <summary>
/// Changes the base type of the symbol.
/// </summary>
public static async Task<ISymbol> SetBaseTypeAsync(
this SymbolEditor editor,
INamedTypeSymbol symbol,
Func<SyntaxGenerator, SyntaxNode> getNewBaseType,
CancellationToken cancellationToken = default(CancellationToken))
{
var baseType = symbol.BaseType;
if (baseType != null)
{
// find existing declaration of the base type
var typeRef = await editor.GetBaseOrInterfaceDeclarationReferenceAsync(symbol, baseType, cancellationToken).ConfigureAwait(false);
if (typeRef != null)
{
return await editor.EditOneDeclarationAsync(
symbol,
typeRef.GetLocation(),
(e, d) => e.ReplaceNode(typeRef, getNewBaseType(e.Generator)),
cancellationToken).ConfigureAwait(false);
}
}
// couldn't find the existing reference to change, so add it to one of the declarations
return await editor.EditOneDeclarationAsync(symbol, (e, decl) =>
{
var newBaseType = getNewBaseType(e.Generator);
if (newBaseType != null)
{
e.ReplaceNode(decl, (d, g) => g.AddBaseType(d, newBaseType));
}
}, cancellationToken).ConfigureAwait(false);
}
开发者ID:RoryVL,项目名称:roslyn,代码行数:35,代码来源:SymbolEditorExtensions.cs
示例18: GenerateSetAccessor
private IMethodSymbol GenerateSetAccessor(
Compilation compilation,
IPropertySymbol property,
Accessibility accessibility,
bool generateAbstractly,
bool useExplicitInterfaceSymbol,
INamedTypeSymbol[] attributesToRemove,
CancellationToken cancellationToken)
{
if (property.SetMethod == null)
{
return null;
}
var setMethod = property.SetMethod.RemoveInaccessibleAttributesAndAttributesOfTypes(
this.State.ClassOrStructType,
attributesToRemove);
return CodeGenerationSymbolFactory.CreateAccessorSymbol(
setMethod,
attributes: null,
accessibility: accessibility,
explicitInterfaceSymbol: useExplicitInterfaceSymbol ? property.SetMethod : null,
statements: GetSetAccessorStatements(compilation, property, generateAbstractly, cancellationToken));
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:25,代码来源:AbstractImplementInterfaceService.CodeAction_Property.cs
示例19: BuildNamedType
private static RQUnconstructedType BuildNamedType(INamedTypeSymbol type)
{
// Anything that is a valid RQUnconstructed types is ALWAYS safe for public APIs
if (type == null)
{
return null;
}
// Anonymous types are unsupported
if (type.IsAnonymousType)
{
return null;
}
// the following types are supported for BuildType() used in signatures, but are not supported
// for UnconstructedTypes
if (type != type.ConstructedFrom || type.SpecialType == SpecialType.System_Void)
{
return null;
}
// make an RQUnconstructedType
var namespaceNames = RQNodeBuilder.GetNameParts(@type.ContainingNamespace);
var typeInfos = new List<RQUnconstructedTypeInfo>();
for (INamedTypeSymbol currentType = type; currentType != null; currentType = currentType.ContainingType)
{
typeInfos.Insert(0, new RQUnconstructedTypeInfo(currentType.Name, currentType.TypeParameters.Length));
}
return new RQUnconstructedType(namespaceNames, typeInfos);
}
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:33,代码来源:RQNodeBuilder.cs
示例20: ImplementOperatorEquals
private async Task<Document> ImplementOperatorEquals(Document document, SyntaxNode declaration, INamedTypeSymbol typeSymbol, CancellationToken cancellationToken)
{
DocumentEditor editor = await DocumentEditor.CreateAsync(document, cancellationToken).ConfigureAwait(false);
var generator = editor.Generator;
if (!typeSymbol.IsOperatorImplemented(WellKnownMemberNames.EqualityOperatorName))
{
var equalityOperator = GenerateOperatorDeclaration(generator.TypeExpression(SpecialType.System_Boolean),
WellKnownMemberNames.EqualityOperatorName,
new[]
{
generator.ParameterDeclaration("left", generator.TypeExpression(typeSymbol)),
generator.ParameterDeclaration("right", generator.TypeExpression(typeSymbol)),
},
generator.ThrowStatement(generator.ObjectCreationExpression(generator.DottedName("System.NotImplementedException"))));
editor.AddMember(declaration, equalityOperator);
}
if (!typeSymbol.IsOperatorImplemented(WellKnownMemberNames.InequalityOperatorName))
{
var inequalityOperator = GenerateOperatorDeclaration(generator.TypeExpression(SpecialType.System_Boolean),
WellKnownMemberNames.InequalityOperatorName,
new[]
{
generator.ParameterDeclaration("left", generator.TypeExpression(typeSymbol)),
generator.ParameterDeclaration("right", generator.TypeExpression(typeSymbol)),
},
generator.ThrowStatement(generator.ObjectCreationExpression(generator.DottedName("System.NotImplementedException"))));
editor.AddMember(declaration, inequalityOperator);
}
return editor.GetChangedDocument();
}
开发者ID:GloryChou,项目名称:roslyn,代码行数:34,代码来源:OverloadOperatorEqualsOnOverridingValueTypeEquals.Fixer.cs
注:本文中的INamedTypeSymbol类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论