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


C# ITypeSymbol.ToDisplayString方法代码示例

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


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

示例1: GetFullTypeName

        private static string GetFullTypeName(ITypeSymbol type)
        {
            if (type == null)
            {
                return string.Empty;
            }

            return type.ContainingAssembly == null
                ? type.ToDisplayString()
                : string.Format(CultureInfo.InvariantCulture, "{0}, {1}", type.ToDisplayString(), type.ContainingAssembly.ToDisplayString());
        }
开发者ID:Azure,项目名称:azure-webjobs-sdk-script,代码行数:11,代码来源:CSharpCompilation.cs

示例2: CastTo

        public static CastExpressionSyntax CastTo(this ExpressionSyntax expression, ITypeSymbol type)
        {
            var trivia = expression.GetLeadingTrivia();

            return SyntaxFactory.CastExpression(
                type: SyntaxFactory.ParseTypeName(type.ToDisplayString()),
                expression: expression.WithoutLeadingTrivia().ParenthesizeIfNeeded())
                .WithLeadingTrivia(trivia);
        }
开发者ID:mpielikis,项目名称:gencast,代码行数:9,代码来源:Helpers.cs

示例3: TypeInspector

        public TypeInspector(ITypeSymbol typeSymbol)
        {
            ShortName = typeSymbol.ToDisplayString();
            if (ShortName.Contains('.'))
            {
                ShortName = typeSymbol.Name;
            }

            if (typeSymbol is INamedTypeSymbol)
            {
                INamedTypeSymbol namedTypeSymbol = (INamedTypeSymbol)typeSymbol;
                if (namedTypeSymbol.IsGenericType)
                {
                    ShortName += string.Format("<{0}>",
                        string.Join(", ", namedTypeSymbol.TypeArguments.Select(symbol => new TypeInspector(symbol).ShortName)));
                }
            }
        }
开发者ID:cdsalmons,项目名称:OrleansTemplates,代码行数:18,代码来源:TypeInspector.cs

示例4: FromITypeSymbol

        public static ModelType FromITypeSymbol(ITypeSymbol typeSymbol)
        {
            if (typeSymbol == null)
            {
                throw new ArgumentNullException(nameof(typeSymbol));
            }

            // Should we check for typeSymbol.IsType before returning here?
            return new ModelType()
            {
                Name = typeSymbol.Name,
                FullName = typeSymbol.ToDisplayString(),
                Namespace = typeSymbol.ContainingNamespace.IsGlobalNamespace
                    ? string.Empty
                    : typeSymbol.ContainingNamespace.ToDisplayString(),
                TypeSymbol = typeSymbol
            };
        }
开发者ID:leloulight,项目名称:Scaffolding,代码行数:18,代码来源:ModelType.cs

示例5: SetType

        public override SyntaxNode SetType(SyntaxNode node, ITypeSymbol typeSymbol)
        {
            Debug.Assert(node is MemberDeclarationSyntax ||
                         node is ParameterSyntax);

            TypeSyntax oldType;
            if (node is MemberDeclarationSyntax)
            {
                oldType = ((MemberDeclarationSyntax)node).GetMemberType();
            }
            else if (node is ParameterSyntax)
            {
                oldType = ((ParameterSyntax)node).Type;
            }
            else
            {
                throw Exceptions.ThrowEFail();
            }

            if (oldType == null)
            {
                throw Exceptions.ThrowEFail();
            }

            var typeName = typeSymbol.ToDisplayString(s_setTypeFormat);
            var newType = SyntaxFactory.ParseTypeName(typeName);

            return node.ReplaceNode(oldType, newType);
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:29,代码来源:CSharpCodeModelService.cs

示例6: GetTypeReferenceString

		public string GetTypeReferenceString (ITypeSymbol type, bool highlight = true)
		{
			if (type == null)
				throw new ArgumentNullException (nameof (type));
			if (type.TypeKind == TypeKind.Error) {
				var typeSyntax = type.GenerateTypeSyntax ();
				string generatedTypeSyntaxString;
				try {
					var oldDoc = ctx.AnalysisDocument;
					var newDoc = oldDoc.WithSyntaxRoot (SyntaxFactory.ParseCompilationUnit (typeSyntax.ToString ()).WithAdditionalAnnotations (Simplifier.Annotation));
					var reducedDoc = Simplifier.ReduceAsync (newDoc, options);
					generatedTypeSyntaxString = Ambience.EscapeText (reducedDoc.Result.GetSyntaxRootAsync ().Result.ToString ());
				} catch {
					generatedTypeSyntaxString = typeSyntax != null ? Ambience.EscapeText (typeSyntax.ToString ()) : "?";
				}
				return highlight ? HighlightSemantically (generatedTypeSyntaxString, colorStyle.UserTypes) : generatedTypeSyntaxString;
			}
			if (type.TypeKind == TypeKind.Array) {
				var arrayType = (IArrayTypeSymbol)type;
				return GetTypeReferenceString (arrayType.ElementType, highlight) + "[" + new string (',', arrayType.Rank - 1) + "]";
			}
			if (type.TypeKind == TypeKind.Pointer)
				return GetTypeReferenceString (((IPointerTypeSymbol)type).PointedAtType, highlight) + "*";
			string displayString;
			if (ctx != null) {
				SemanticModel model = SemanticModel;
				if (model == null) {
					var parsedDocument = ctx.ParsedDocument;
					if (parsedDocument != null) {
						model = parsedDocument.GetAst<SemanticModel> () ?? ctx.AnalysisDocument?.GetSemanticModelAsync ().Result;
					}
				}
				//Math.Min (model.SyntaxTree.Length, offset)) is needed in case parsedDocument.GetAst<SemanticModel> () is outdated
				//this is tradeoff between performance and consistency between editor text(offset) and model, since
				//ToMinimalDisplayString can use little outdated model this is fine
				//but in case of Sketches where user usually is at end of document when typing text this can throw exception
				//because offset can be >= Length
				displayString = model != null ? RoslynCompletionData.SafeMinimalDisplayString (type, model, Math.Min (model.SyntaxTree.Length - 1, offset), MonoDevelop.Ide.TypeSystem.Ambience.LabelFormat) : type.Name;
			} else {
				displayString = type.ToDisplayString (MonoDevelop.Ide.TypeSystem.Ambience.LabelFormat);
			}
			var text = MonoDevelop.Ide.TypeSystem.Ambience.EscapeText (displayString);
			return highlight ? HighlightSemantically (text, colorStyle.UserTypes) : text;
		}
开发者ID:kdubau,项目名称:monodevelop,代码行数:44,代码来源:SignatureMarkupCreator.cs

示例7: IsMatch

 private static bool IsMatch(ITypeSymbol typeSymbol, KnownType type)
 {
     return type.Matches(typeSymbol.SpecialType) || type.Matches(typeSymbol.ToDisplayString());
 }
开发者ID:dbolkensteyn,项目名称:sonarlint-vs,代码行数:4,代码来源:TypeHelper.cs

示例8: AddTypeLink

        protected void AddTypeLink(ITypeSymbol typeSymbol, LinkFlags flags)
        {
            if (typeSymbol.TypeKind == TypeKind.Unknown ||
                typeSymbol.TypeKind == TypeKind.Error ||
                typeSymbol.TypeKind == TypeKind.TypeParameter ||
                typeSymbol.SpecialType == SpecialType.System_Void)
            {
                AddName(typeSymbol.ToDisplayString(s_typeDisplay));
                return;
            }

            var useSpecialTypes = (flags & LinkFlags.ExpandPredefinedTypes) == 0;
            var splitLink = !useSpecialTypes & (flags & LinkFlags.SplitNamespaceAndType) != 0;

            if (splitLink && !typeSymbol.ContainingNamespace.IsGlobalNamespace)
            {
                AddNamespaceLink(typeSymbol.ContainingNamespace);
                AddText(".");
            }

            var typeQualificationStyle = splitLink
                ? SymbolDisplayTypeQualificationStyle.NameAndContainingTypes
                : SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces;

            var miscellaneousOptions = useSpecialTypes
                ? SymbolDisplayMiscellaneousOptions.UseSpecialTypes
                : SymbolDisplayMiscellaneousOptions.ExpandNullable;

            var typeDisplayFormat = new SymbolDisplayFormat(
                typeQualificationStyle: typeQualificationStyle,
                genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters | SymbolDisplayGenericsOptions.IncludeVariance,
                miscellaneousOptions: miscellaneousOptions);

            var text = typeSymbol.ToDisplayString(typeDisplayFormat);
            var navInfo = _libraryManager.GetTypeNavInfo(typeSymbol, _project, GetCompilation(), useExpandedHierarchy: false);

            _description.AddDescriptionText3(text, VSOBDESCRIPTIONSECTION.OBDS_TYPE, navInfo);
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:38,代码来源:AbstractDescriptionBuilder.cs

示例9: GetTypeSymbolFullName

 /// <summary>
 /// Tries all possible ways to retrieve the full name using the semantic model.
 /// </summary>
 /// <param name="node"></param>
 /// <returns></returns>
 internal static string GetTypeSymbolFullName(ITypeSymbol typeSymbol) =>
     typeSymbol.ToDisplayString(new SymbolDisplayFormat(
         typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces));
开发者ID:andry-tino,项目名称:Rosetta,代码行数:8,代码来源:TypeReference.cs

示例10: GetTypeReferenceString

		public string GetTypeReferenceString (ITypeSymbol type, bool highlight = true)
		{
			if (type == null)
				throw new ArgumentNullException ("type");
			if (type.TypeKind == TypeKind.Error)
				return "?";
			if (type.TypeKind == TypeKind.Array) {
				var arrayType = (IArrayTypeSymbol)type;
				return GetTypeReferenceString (arrayType.ElementType, highlight) + "[" + new string (',', arrayType.Rank - 1) + "]";
			}
			if (type.TypeKind == TypeKind.Pointer)
				return GetTypeReferenceString (((IPointerTypeSymbol)type).PointedAtType, highlight) + "*";
			string displayString;
			if (ctx != null) {
				SemanticModel model = SemanticModel;
				if (model == null) {
					var parsedDocument = ctx.ParsedDocument;
					if (parsedDocument != null) {
						model = parsedDocument.GetAst<SemanticModel> () ?? ctx.AnalysisDocument?.GetSemanticModelAsync ().Result;
					}
				}
				//Math.Min (model.SyntaxTree.Length, offset)) is needed in case parsedDocument.GetAst<SemanticModel> () is outdated
				//this is tradeoff between performance and consistency between editor text(offset) and model, since
				//ToMinimalDisplayString can use little outdated model this is fine
				//but in case of Sketches where user usually is at end of document when typing text this can throw exception
				//because offset can be >= Length
				displayString = model != null ? RoslynCompletionData.SafeMinimalDisplayString (type, model, Math.Min (model.SyntaxTree.Length - 1, offset), MonoDevelop.Ide.TypeSystem.Ambience.LabelFormat) : type.Name;
			} else {
				displayString = type.ToDisplayString (MonoDevelop.Ide.TypeSystem.Ambience.LabelFormat);
			}
			var text = MonoDevelop.Ide.TypeSystem.Ambience.EscapeText (displayString);
			return highlight ? HighlightSemantically (text, colorStyle.UserTypes) : text;
		}
开发者ID:vvarshne,项目名称:monodevelop,代码行数:33,代码来源:SignatureMarkupCreator.cs

示例11: TryRewrite

        private ExpressionSyntax TryRewrite(string aggregationMethod, ExpressionSyntax collection, ITypeSymbol semanticReturnType, List<LinqStep> chain, InvocationExpressionSyntax node)
        {
            var returnType = SyntaxFactory.ParseTypeName(semanticReturnType.ToDisplayString());

            if (RootMethodsThatRequireYieldReturn.Contains(aggregationMethod))
            {
                return RewriteAsLoop(
                    returnType,
                    Enumerable.Empty<StatementSyntax>(),
                    Enumerable.Empty<StatementSyntax>(),
                    collection,
                    chain,
                    (inv, arguments, param) =>
                    {
                        return SyntaxFactory.YieldStatement(SyntaxKind.YieldReturnStatement, SyntaxFactory.IdentifierName(param.Identifier.ValueText));
                    },
                    true
                );
            }

            if (aggregationMethod.Contains(".Sum"))
            {
                var elementType = ((returnType as NullableTypeSyntax)?.ElementType ?? returnType);
                return RewriteAsLoop(
                    returnType,
                    new[] { CreateLocalVariableDeclaration("sum_", SyntaxFactory.CastExpression(elementType, SyntaxFactory.LiteralExpression(SyntaxKind.NumericLiteralExpression, SyntaxFactory.Literal(0)))) },
                    new[] { SyntaxFactory.ReturnStatement(SyntaxFactory.IdentifierName("sum_")) },
                    collection,
                    MaybeAddSelect(chain, node.ArgumentList.Arguments.Count != 0),
                    (inv, arguments, param) =>
                    {
                        var currentValue = SyntaxFactory.IdentifierName(param.Identifier.ValueText);
                        return IfNullableIsNotNull(elementType != returnType, currentValue, x =>
                        {
                            return SyntaxFactory.CheckedStatement(SyntaxKind.CheckedStatement, SyntaxFactory.Block(SyntaxFactory.ExpressionStatement(SyntaxFactory.AssignmentExpression(SyntaxKind.AddAssignmentExpression, SyntaxFactory.IdentifierName("sum_"), x))));
                        });
                    }
                );
            }

            if (aggregationMethod.Contains(".Max") || aggregationMethod.Contains(".Min"))
            {
                var minmax = aggregationMethod.Contains(".Max") ? "max_" : "min_";
                var elementType = ((returnType as NullableTypeSyntax)?.ElementType ?? returnType);
                return RewriteAsLoop(
                    returnType,
                    new[] {
                        CreateLocalVariableDeclaration("found_", SyntaxFactory.LiteralExpression(SyntaxKind.FalseLiteralExpression)),
                        CreateLocalVariableDeclaration(minmax, SyntaxFactory.CastExpression(elementType, SyntaxFactory.LiteralExpression(SyntaxKind.NumericLiteralExpression, SyntaxFactory.Literal(0))))
                    },
                    new[] {
                        SyntaxFactory.Block(
                        SyntaxFactory.IfStatement(SyntaxFactory.PrefixUnaryExpression(SyntaxKind.LogicalNotExpression, SyntaxFactory.IdentifierName("found_")),
                            returnType == elementType ? (StatementSyntax)CreateThrowException("System.InvalidOperationException", "The sequence did not contain any elements.") :
                            SyntaxFactory.ReturnStatement(SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression))
                        ),
                         SyntaxFactory.ReturnStatement(SyntaxFactory.IdentifierName(minmax))
                        )
                    },
                    collection,
                    MaybeAddSelect(chain, node.ArgumentList.Arguments.Count != 0),
                    (inv, arguments, param) =>
                    {
                        var identifierNameSyntax = SyntaxFactory.IdentifierName(param.Identifier.ValueText);
                        return IfNullableIsNotNull(elementType != returnType, identifierNameSyntax, x =>
                        {
                            var assignmentExpressionSyntax = SyntaxFactory.AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, SyntaxFactory.IdentifierName(minmax), x);
                            var condition = SyntaxFactory.BinaryExpression(aggregationMethod.Contains(".Max") ? SyntaxKind.GreaterThanExpression : SyntaxKind.LessThanExpression, x, SyntaxFactory.IdentifierName(minmax));
                            var kind = (elementType as PredefinedTypeSyntax).Keyword.Kind();
                            if (kind == SyntaxKind.DoubleKeyword || kind == SyntaxKind.FloatKeyword)
                            {
                                condition = SyntaxFactory.BinaryExpression(SyntaxKind.LogicalOrExpression, condition, SyntaxFactory.InvocationExpression(SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, elementType, SyntaxFactory.IdentifierName("IsNaN")), CreateArguments(x)));
                            }
                            return SyntaxFactory.IfStatement(SyntaxFactory.IdentifierName("found_"),
                               SyntaxFactory.Block(SyntaxFactory.IfStatement(condition, SyntaxFactory.ExpressionStatement(assignmentExpressionSyntax))),
                               SyntaxFactory.ElseClause(SyntaxFactory.Block(SyntaxFactory.ExpressionStatement(SyntaxFactory.AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, SyntaxFactory.IdentifierName("found_"), SyntaxFactory.LiteralExpression(SyntaxKind.TrueLiteralExpression))), SyntaxFactory.ExpressionStatement(assignmentExpressionSyntax))));
                        });
                    });
            }


            if (aggregationMethod.Contains(".Average"))
            {
                var elementType = ((returnType as NullableTypeSyntax)?.ElementType ?? returnType);
                var primitive = ((PredefinedTypeSyntax)elementType).Keyword.Kind();

                ExpressionSyntax sumIdentifier = SyntaxFactory.IdentifierName("sum_");
                ExpressionSyntax countIdentifier = SyntaxFactory.IdentifierName("count_");

                if (primitive != SyntaxKind.DecimalKeyword)
                {
                    sumIdentifier = SyntaxFactory.CastExpression(CreatePrimitiveType(SyntaxKind.DoubleKeyword), sumIdentifier);
                    countIdentifier = SyntaxFactory.CastExpression(CreatePrimitiveType(SyntaxKind.DoubleKeyword), countIdentifier);
                }
                ExpressionSyntax division = SyntaxFactory.BinaryExpression(SyntaxKind.DivideExpression, sumIdentifier, countIdentifier);
                if (primitive != SyntaxKind.DoubleKeyword && primitive != SyntaxKind.DecimalKeyword)
                {
                    division = SyntaxFactory.CastExpression(elementType, SyntaxFactory.ParenthesizedExpression(division));
                }

//.........这里部分代码省略.........
开发者ID:antiufo,项目名称:RoslynLinqRewrite,代码行数:101,代码来源:LinqRewriter.Rules.cs

示例12: Cast

        private static ExpressionSyntax Cast(ExpressionSyntax expression, ITypeSymbol targetType)
        {
            if (targetType == null)
            {
                return expression;
            }

            var type = ParseTypeName(targetType.ToDisplayString());

            return CastExpression(type, Parenthesize(expression))
                .WithAdditionalAnnotations(Simplifier.Annotation);
        }
开发者ID:Killerameise,项目名称:CSharpEssentials,代码行数:12,代码来源:ConvertToInterpolatedStringRefactoring.cs

示例13: CreateTypeCoupling

		private static TypeCoupling CreateTypeCoupling(ITypeSymbol typeSymbol, IEnumerable<string> usedMethods, IEnumerable<string> usedProperties, IEnumerable<string> events)
		{
			var name = typeSymbol.IsAnonymousType ? typeSymbol.ToDisplayString() : typeSymbol.Name;

			var namespaceName = string.Join(".", GetFullNamespace(typeSymbol.ContainingNamespace));
			if (string.IsNullOrWhiteSpace(namespaceName))
			{
				namespaceName = "global";
			}

			var assemblyName = "Unknown";
			if (typeSymbol.ContainingAssembly != null)
			{
				assemblyName = typeSymbol.ContainingAssembly.Name;
			}

			return new TypeCoupling(name, namespaceName, assemblyName, usedMethods, usedProperties, events);
		}
开发者ID:henrylle,项目名称:ArchiMetrics,代码行数:18,代码来源:ClassCouplingAnalyzerBase.cs

示例14: ConvertType

		internal static TypeSyntax ConvertType (ITypeSymbol symbol)
		{
			// TODO: There needs to be a better way doing that.
			return SyntaxFactory.ParseTypeName (symbol.ToDisplayString (SymbolDisplayFormat.CSharpErrorMessageFormat));
		}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:5,代码来源:CreateConstructorGenerator.cs

示例15: GetClassName

 private string GetClassName(ITypeSymbol typeSymbol)
 {
     return typeSymbol != null
         ? typeSymbol.ToDisplayString(LibraryService.TypeDisplayFormat)
         : string.Empty;
 }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:6,代码来源:NavInfoFactory.cs


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