本文整理汇总了C#中INamedTypeSymbol.ToDisplayString方法的典型用法代码示例。如果您正苦于以下问题:C# INamedTypeSymbol.ToDisplayString方法的具体用法?C# INamedTypeSymbol.ToDisplayString怎么用?C# INamedTypeSymbol.ToDisplayString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类INamedTypeSymbol
的用法示例。
在下文中一共展示了INamedTypeSymbol.ToDisplayString方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTypeDisplayString
private static string GetTypeDisplayString(INamedTypeSymbol symbol)
{
if (symbol.SpecialType != SpecialType.None)
{
var specialType = symbol.SpecialType;
var name = Enum.GetName(typeof(SpecialType), symbol.SpecialType).Replace("_", ".");
return name;
}
if (symbol.IsGenericType)
{
symbol = symbol.ConstructUnboundGenericType();
}
if (symbol.IsUnboundGenericType)
{
// TODO: Is this the best to get the fully metadata name?
var parts = symbol.ToDisplayParts();
var filteredParts = parts.Where(x => x.Kind != SymbolDisplayPartKind.Punctuation).ToArray();
var typeName = new StringBuilder();
foreach (var part in filteredParts.Take(filteredParts.Length - 1))
{
typeName.Append(part.Symbol.Name);
typeName.Append(".");
}
typeName.Append(symbol.MetadataName);
return typeName.ToString();
}
return symbol.ToDisplayString();
}
示例2: 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);
}
示例3: 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);
}
}
示例4: ReportDiagnostic
private static void ReportDiagnostic(SymbolAnalysisContext symbolContext, INamedTypeSymbol exportedType, AttributeData problematicAttribute)
{
var metadataSyntax = problematicAttribute.ApplicationSyntaxReference;
var displayStringOfAttribute = problematicAttribute.AttributeClass.ToMinimalDisplayString(symbolContext.Compilation.GetSemanticModel(metadataSyntax.SyntaxTree),
metadataSyntax.Span.Start,
GetSymbolDisplayFormat(exportedType, minimal: true));
var displayStringOfExport = exportedType.ToDisplayString(GetSymbolDisplayFormat(exportedType, minimal: false));
symbolContext.ReportDiagnostic(Diagnostic.Create(Rule, metadataSyntax.GetSyntax().GetLocation(), displayStringOfAttribute, displayStringOfExport));
}
示例5: BuildTypeDeclaration
protected override void BuildTypeDeclaration(INamedTypeSymbol typeSymbol, _VSOBJDESCOPTIONS options)
{
BuildTypeModifiers(typeSymbol);
switch (typeSymbol.TypeKind)
{
case TypeKind.Enum:
AddText("enum ");
break;
case TypeKind.Struct:
AddText("struct ");
break;
case TypeKind.Interface:
AddText("interface ");
break;
case TypeKind.Class:
AddText("class ");
break;
default:
Debug.Fail("Invalid type kind encountered: " + typeSymbol.TypeKind.ToString());
break;
}
var typeNameFormat = new SymbolDisplayFormat(
genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters | SymbolDisplayGenericsOptions.IncludeVariance);
AddName(typeSymbol.ToDisplayString(typeNameFormat));
if (typeSymbol.TypeKind == TypeKind.Enum)
{
var underlyingType = typeSymbol.EnumUnderlyingType;
if (underlyingType != null)
{
if (underlyingType.SpecialType != SpecialType.System_Int32)
{
AddText(" : ");
AddTypeLink(underlyingType, LinkFlags.None);
}
}
}
else
{
var baseType = typeSymbol.BaseType;
if (baseType != null)
{
if (baseType.SpecialType != SpecialType.System_Object &&
baseType.SpecialType != SpecialType.System_Delegate &&
baseType.SpecialType != SpecialType.System_MulticastDelegate &&
baseType.SpecialType != SpecialType.System_Enum &&
baseType.SpecialType != SpecialType.System_ValueType)
{
AddText(" : ");
AddTypeLink(baseType, LinkFlags.None);
}
}
}
if (typeSymbol.IsGenericType)
{
BuildGenericConstraints(typeSymbol);
}
}
示例6: ChangeFaultEffectBaseType
/// <summary>
/// Changes the base type of the fault effect declaration based on its location in the fault effect list.
/// </summary>
private ClassDeclarationSyntax ChangeFaultEffectBaseType(INamedTypeSymbol classSymbol, ClassDeclarationSyntax classDeclaration)
{
var baseTypeName = classSymbol.BaseType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
var faultEffectSymbol = _typeLookup[classSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)];
var faultIndex = Array.IndexOf(_faults[_typeLookup[baseTypeName]], faultEffectSymbol);
if (faultIndex == 0)
return classDeclaration;
var baseType = Syntax.TypeExpression(_faults[_typeLookup[baseTypeName]][faultIndex - 1]).WithTrivia(classDeclaration.BaseList.Types[0]);
var baseTypes = SyntaxFactory.SingletonSeparatedList((BaseTypeSyntax)SyntaxFactory.SimpleBaseType((TypeSyntax)baseType));
var baseList = SyntaxFactory.BaseList(classDeclaration.BaseList.ColonToken, baseTypes).WithTrivia(classDeclaration.BaseList);
return classDeclaration.WithBaseList(baseList);
}
示例7: AddRuntimeTypeField
/// <summary>
/// Adds the runtime type field to the component symbol.
/// </summary>
private void AddRuntimeTypeField(INamedTypeSymbol classSymbol)
{
var className = classSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
var faults = _faults[_typeLookup[className]];
var runtimeType = faults.Length > 0 ? faults[faults.Length - 1] : classSymbol;
var typeofExpression = SyntaxFactory.TypeOfExpression((TypeSyntax)Syntax.TypeExpression((runtimeType)));
var field = Syntax.FieldDeclaration(
name: "runtimeType".ToSynthesized(),
type: SyntaxFactory.ParseTypeName(typeof(Type).GetGlobalName()),
accessibility: Accessibility.Private,
modifiers: DeclarationModifiers.Static | DeclarationModifiers.ReadOnly,
initializer: typeofExpression);
field = Syntax.MarkAsNonDebuggerBrowsable(field);
field = Syntax.AddAttribute<CompilerGeneratedAttribute>(field);
field = field.NormalizeWhitespace();
AddMembers(classSymbol, (MemberDeclarationSyntax)field);
}
示例8: ProxyGenerationOptions
public ProxyGenerationOptions(INamedTypeSymbol sourceInterfaceType)
{
SourceInterfaceType = sourceInterfaceType;
SourceInterfaceTypeName = sourceInterfaceType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
}
示例9: AnalyzeSymbol
private static void AnalyzeSymbol(INamedTypeSymbol namedType, Action<Diagnostic> addDiagnostic)
{
string symbolName = namedType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
addDiagnostic(CreateDiagnostic(SymbolNameRule, symbolName));
}
示例10: GetCleanedGenericClass
private static IEnumerable<KeyValuePair<SyntaxNode, SyntaxNode>> GetCleanedGenericClass(SyntaxNode tree, SemanticModel semanticModel, ISet<ITypeParameterSymbol> typeParameters, INamedTypeSymbol symbol)
{
foreach (var node in tree.DescendantNodes().OfType<IdentifierNameSyntax>())
{
var s = semanticModel.GetSymbolInfo(node);
if (typeParameters.Contains(s.Symbol))
{
var typeSynax = SyntaxFactory.IdentifierName(symbol.ToDisplayString())
.WithLeadingTrivia(node.GetLeadingTrivia())
.WithTrailingTrivia(node.GetTrailingTrivia());
yield return new KeyValuePair<SyntaxNode, SyntaxNode>(node, typeSynax);
}
}
}
示例11: IsObjectOrType
private static bool IsObjectOrType(INamedTypeSymbol namedType)
{
return namedType.SpecialType == SpecialType.System_Object ||
namedType.ToDisplayString() == SystemTypeName;
}
示例12: CreateSimpleTypeSyntax
private TypeSyntax CreateSimpleTypeSyntax(INamedTypeSymbol symbol)
{
switch (symbol.SpecialType)
{
case SpecialType.System_Object:
return SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.ObjectKeyword));
case SpecialType.System_Void:
return SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.VoidKeyword));
case SpecialType.System_Boolean:
return SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.BoolKeyword));
case SpecialType.System_Char:
return SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.CharKeyword));
case SpecialType.System_SByte:
return SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.SByteKeyword));
case SpecialType.System_Byte:
return SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.ByteKeyword));
case SpecialType.System_Int16:
return SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.ShortKeyword));
case SpecialType.System_UInt16:
return SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.UShortKeyword));
case SpecialType.System_Int32:
return SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.IntKeyword));
case SpecialType.System_UInt32:
return SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.UIntKeyword));
case SpecialType.System_Int64:
return SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.LongKeyword));
case SpecialType.System_UInt64:
return SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.ULongKeyword));
case SpecialType.System_Decimal:
return SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.DecimalKeyword));
case SpecialType.System_Single:
return SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.FloatKeyword));
case SpecialType.System_Double:
return SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.DoubleKeyword));
case SpecialType.System_String:
return SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.StringKeyword));
}
if ((symbol.Name == string.Empty) || symbol.IsAnonymousType)
{
return SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.ObjectKeyword));
}
if (symbol.OriginalDefinition.SpecialType == SpecialType.System_Nullable_T)
{
ITypeSymbol symbol2 = symbol.TypeArguments.First<ITypeSymbol>();
if (symbol2.TypeKind != TypeKind.PointerType)
{
// Deveation
//return this.AddInformationTo<NullableTypeSyntax>(SyntaxFactory.NullableType(CreateSimpleTypeSyntax(symbol2 as INamedTypeSymbol)), symbol);
}
}
if (symbol.TypeParameters.Length == 0)
{
if ((symbol.TypeKind == TypeKind.Error) && (symbol.Name == "var"))
{
return SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.ObjectKeyword));
}
return symbol.Name.ToIdentifierName();
}
//Deveation
IEnumerable<TypeSyntax> nodes = symbol.IsUnboundGenericType ?
((IEnumerable<TypeSyntax>)Enumerable.Repeat<OmittedTypeArgumentSyntax>(SyntaxFactory.OmittedTypeArgument(), symbol.TypeArguments.Length)) :
System.Linq.ImmutableArrayExtensions.Select<ITypeSymbol, TypeSyntax>(symbol.TypeArguments, (Func<ITypeSymbol, TypeSyntax>)(t => CreateSimpleTypeSyntax(t as INamedTypeSymbol)));
return SyntaxFactory.GenericName(symbol.ToDisplayString().ToIdentifierToken(false), SyntaxFactory.TypeArgumentList(SyntaxFactory.SeparatedList<TypeSyntax>(nodes)));
}