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


C# SymbolDisplayFormat类代码示例

本文整理汇总了C#中SymbolDisplayFormat的典型用法代码示例。如果您正苦于以下问题:C# SymbolDisplayFormat类的具体用法?C# SymbolDisplayFormat怎么用?C# SymbolDisplayFormat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: TestClassNameOnlyComplex

        public void TestClassNameOnlyComplex()
        {
            var text = @"
namespace N1 {
    namespace N2.N3 {
        class C1 {
            class C2 {} } } }
";

            Func<NamespaceSymbol, Symbol> findSymbol = global =>
                global.GetNestedNamespace("N1").
                GetNestedNamespace("N2").
                GetNestedNamespace("N3").
                GetTypeMembers("C1").Single().
                GetTypeMembers("C2").Single();

            var format = new SymbolDisplayFormat(
                typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameOnly);

            TestSymbolDescription(
                text,
                findSymbol,
                format,
                "C2",
                SymbolDisplayPartKind.ClassName);
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:26,代码来源:SymbolDisplayTests.cs

示例2: ToMinimalDisplayString

 /// <summary>
 /// Displays a symbol in the C# style, based on a <see cref="SymbolDisplayFormat"/>.
 /// Based on the context, qualify type and member names as little as possible without
 /// introducing ambiguities.
 /// </summary>
 /// <param name="symbol">The symbol to be displayed.</param>
 /// <param name="semanticModel">Semantic information about the context in which the symbol is being displayed.</param>
 /// <param name="position">A position within the <see cref="SyntaxTree"/> or <paramref name="semanticModel"/>.</param>
 /// <param name="format">The formatting options to apply.  If null is passed, <see cref="SymbolDisplayFormat.CSharpErrorMessageFormat"/> will be used.</param>
 /// <returns>A formatted string that can be displayed to the user.</returns>
 /// <remarks>
 /// The return value is not expected to be syntactically valid C#.
 /// </remarks>
 public static string ToMinimalDisplayString(
     ISymbol symbol,
     SemanticModel semanticModel,
     int position,
     SymbolDisplayFormat format = null)
 {
     return ToMinimalDisplayParts(symbol, semanticModel, position, format).ToDisplayString();
 }
开发者ID:GeneralRookie,项目名称:roslyn,代码行数:21,代码来源:SymbolDisplay.cs

示例3: SymbolDisplayVisitor

 internal SymbolDisplayVisitor(
     ArrayBuilder<SymbolDisplayPart> builder,
     SymbolDisplayFormat format,
     SemanticModel semanticModelOpt,
     int positionOpt)
     : base(builder, format, true, semanticModelOpt, positionOpt)
 {
     _escapeKeywordIdentifiers = format.MiscellaneousOptions.IncludesOption(SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers);
 }
开发者ID:jkotas,项目名称:roslyn,代码行数:9,代码来源:SymbolDisplayVisitor.cs

示例4: ToDisplayParts

 /// <summary>
 /// Convert a symbol to an array of string parts, each of which has a kind. Useful for
 /// colorizing the display string.
 /// </summary>
 /// <param name="symbol">The symbol to be displayed.</param>
 /// <param name="format">The formatting options to apply.  If null is passed, <see cref="SymbolDisplayFormat.CSharpErrorMessageFormat"/> will be used.</param>
 /// <returns>A list of display parts.</returns>
 /// <remarks>
 /// Parts are not localized until they are converted to strings.
 /// </remarks>
 public static ImmutableArray<SymbolDisplayPart> ToDisplayParts(
     ISymbol symbol,
     SymbolDisplayFormat format = null)
 {
     // null indicates the default format
     format = format ?? SymbolDisplayFormat.CSharpErrorMessageFormat;
     return ToDisplayParts(
         symbol, semanticModelOpt: null, positionOpt: -1, format: format, minimal: false);
 }
开发者ID:GeneralRookie,项目名称:roslyn,代码行数:19,代码来源:SymbolDisplay.cs

示例5: TestClassNameOnlySimple

        public void TestClassNameOnlySimple()
        {
            var text = "class A {}";

            Func<NamespaceSymbol, Symbol> findSymbol = global =>
                global.GetTypeMembers("A", 0).Single();

            var format = new SymbolDisplayFormat(
                typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameOnly);

            TestSymbolDescription(
                text,
                findSymbol,
                format,
                "A",
                SymbolDisplayPartKind.ClassName);
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:17,代码来源:SymbolDisplayTests.cs

示例6: AbstractSymbolDisplayVisitor

        protected AbstractSymbolDisplayVisitor(
            ArrayBuilder<SymbolDisplayPart> builder,
            SymbolDisplayFormat format,
            bool isFirstSymbolVisited,
            SemanticModel semanticModelOpt,
            int positionOpt)
        {
            Debug.Assert(format != null);

            this.builder = builder;
            this.format = format;
            this.isFirstSymbolVisited = isFirstSymbolVisited;

            this.semanticModelOpt = semanticModelOpt;
            this.positionOpt = positionOpt;

            // If we're not the first symbol visitor, then we will just recurse into ourselves.
            if (!isFirstSymbolVisited)
            {
                _lazyNotFirstVisitor = this;
            }
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:22,代码来源:AbstractSymbolDisplayVisitor.cs

示例7: ToMinimalDisplayParts

 public abstract ImmutableArray<SymbolDisplayPart> ToMinimalDisplayParts(SemanticModel semanticModel, int position, ISymbol symbol, SymbolDisplayFormat format);
开发者ID:Rickinio,项目名称:roslyn,代码行数:1,代码来源:AbstractSymbolDisplayService.cs

示例8: ToDisplayString

 /// <summary>
 /// Displays a symbol in the C# style, based on a <see cref="SymbolDisplayFormat"/>.
 /// </summary>
 /// <param name="symbol">The symbol to be displayed.</param>
 /// <param name="format">The formatting options to apply.  If null is passed, <see cref="SymbolDisplayFormat.CSharpErrorMessageFormat"/> will be used.</param>
 /// <returns>A formatted string that can be displayed to the user.</returns>
 /// <remarks>
 /// The return value is not expected to be syntactically valid C#.
 /// </remarks>
 public static string ToDisplayString(
     ISymbol symbol,
     SymbolDisplayFormat format = null)
 {
     return ToDisplayParts(symbol, format).ToDisplayString();
 }
开发者ID:GeneralRookie,项目名称:roslyn,代码行数:15,代码来源:SymbolDisplay.cs

示例9: TestEscapeKeywordIdentifiers

        public void TestEscapeKeywordIdentifiers()
        {
            var text = @"
class @true {
    @true @false(@true @true, bool @bool = true) { return @true; } }
";

            Func<NamespaceSymbol, Symbol> findSymbol = global =>
                global.GetTypeMembers("true", 0).Single().
                GetMembers("false").Single();

            var format = new SymbolDisplayFormat(
                memberOptions: SymbolDisplayMemberOptions.IncludeType | SymbolDisplayMemberOptions.IncludeParameters,
                parameterOptions: SymbolDisplayParameterOptions.IncludeType | SymbolDisplayParameterOptions.IncludeName | SymbolDisplayParameterOptions.IncludeDefaultValue,
                miscellaneousOptions: SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers | SymbolDisplayMiscellaneousOptions.UseSpecialTypes);

            TestSymbolDescription(
                text,
                findSymbol,
                format,
                "@true @false(@true @true, bool @bool = true)",
                SymbolDisplayPartKind.ClassName,
                SymbolDisplayPartKind.Space,
                SymbolDisplayPartKind.MethodName, //@false
                SymbolDisplayPartKind.Punctuation,
                SymbolDisplayPartKind.ClassName,
                SymbolDisplayPartKind.Space,
                SymbolDisplayPartKind.ParameterName, //@true
                SymbolDisplayPartKind.Punctuation,
                SymbolDisplayPartKind.Space,
                SymbolDisplayPartKind.Keyword,
                SymbolDisplayPartKind.Space,
                SymbolDisplayPartKind.ParameterName, //@bool
                SymbolDisplayPartKind.Space,
                SymbolDisplayPartKind.Punctuation,
                SymbolDisplayPartKind.Space,
                SymbolDisplayPartKind.Keyword,
                SymbolDisplayPartKind.Punctuation);
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:39,代码来源:SymbolDisplayTests.cs

示例10: ToDisplayParts

 public abstract ImmutableArray<SymbolDisplayPart> ToDisplayParts(ISymbol symbol, SymbolDisplayFormat format = null);
开发者ID:Rickinio,项目名称:roslyn,代码行数:1,代码来源:AbstractSymbolDisplayService.cs

示例11: TestOptionalParameters_Constrained_Struct

        public void TestOptionalParameters_Constrained_Struct()
        {
            var text = @"
using System.Runtime.InteropServices;

class C
{
    void F<T>([Optional]T arg) where T : struct { }
";

            Func<NamespaceSymbol, Symbol> findSymbol = global =>
                global.GetTypeMembers("C", 0).Single().
                GetMembers("F").Single();

            var format = new SymbolDisplayFormat(
                memberOptions: SymbolDisplayMemberOptions.IncludeType | SymbolDisplayMemberOptions.IncludeParameters,
                parameterOptions: SymbolDisplayParameterOptions.IncludeType | SymbolDisplayParameterOptions.IncludeName | SymbolDisplayParameterOptions.IncludeDefaultValue,
                miscellaneousOptions: SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers | SymbolDisplayMiscellaneousOptions.UseSpecialTypes);

            TestSymbolDescription(
                text,
                findSymbol,
                format,
                "void F(T arg)",
                SymbolDisplayPartKind.Keyword,
                SymbolDisplayPartKind.Space,
                SymbolDisplayPartKind.MethodName, // F
                SymbolDisplayPartKind.Punctuation,
                SymbolDisplayPartKind.TypeParameterName,
                SymbolDisplayPartKind.Space,
                SymbolDisplayPartKind.ParameterName, // arg
                SymbolDisplayPartKind.Punctuation);
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:33,代码来源:SymbolDisplayTests.cs

示例12: TestOptionalParameters_ArrayAndType

        public void TestOptionalParameters_ArrayAndType()
        {
            var text = @"
using System.Runtime.InteropServices;

class C
{
    void F<T>(int a, [Optional]double[] arg, int b, [Optional]System.Type t) { }
";

            Func<NamespaceSymbol, Symbol> findSymbol = global =>
                global.GetTypeMembers("C", 0).Single().
                GetMembers("F").Single();

            var format = new SymbolDisplayFormat(
                memberOptions: SymbolDisplayMemberOptions.IncludeType | SymbolDisplayMemberOptions.IncludeParameters,
                parameterOptions: SymbolDisplayParameterOptions.IncludeType | SymbolDisplayParameterOptions.IncludeName | SymbolDisplayParameterOptions.IncludeDefaultValue,
                miscellaneousOptions: SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers | SymbolDisplayMiscellaneousOptions.UseSpecialTypes);

            TestSymbolDescription(
                text,
                findSymbol,
                format,
                "void F(int a, double[] arg, int b, Type t)",
                SymbolDisplayPartKind.Keyword,
                SymbolDisplayPartKind.Space,
                SymbolDisplayPartKind.MethodName, // F
                SymbolDisplayPartKind.Punctuation,

                SymbolDisplayPartKind.Keyword, // int
                SymbolDisplayPartKind.Space,
                SymbolDisplayPartKind.ParameterName, // a
                SymbolDisplayPartKind.Punctuation,
                SymbolDisplayPartKind.Space,

                SymbolDisplayPartKind.Keyword, // double
                SymbolDisplayPartKind.Punctuation,
                SymbolDisplayPartKind.Punctuation,
                SymbolDisplayPartKind.Space,
                SymbolDisplayPartKind.ParameterName, // arg
                SymbolDisplayPartKind.Punctuation,
                SymbolDisplayPartKind.Space,

                SymbolDisplayPartKind.Keyword, // int
                SymbolDisplayPartKind.Space,
                SymbolDisplayPartKind.ParameterName, // b
                SymbolDisplayPartKind.Punctuation,
                SymbolDisplayPartKind.Space,

                SymbolDisplayPartKind.ClassName, // Type
                SymbolDisplayPartKind.Space,
                SymbolDisplayPartKind.ParameterName, // t

                SymbolDisplayPartKind.Punctuation);
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:55,代码来源:SymbolDisplayTests.cs

示例13: ToMinimalDisplayParts

 protected ImmutableArray<SymbolDisplayPart> ToMinimalDisplayParts(ISymbol symbol, SymbolDisplayFormat format = null)
 {
     format = format ?? MinimallyQualifiedFormat;
     return _displayService.ToMinimalDisplayParts(_semanticModel, _position, symbol, format);
 }
开发者ID:jkotas,项目名称:roslyn,代码行数:5,代码来源:AbstractSymbolDisplayService.AbstractSymbolDescriptionBuilder.cs

示例14: TestMethodVB

        public void TestMethodVB()
        {
            var text = @"
Class A
   Public Sub Foo(a As Integer)
   End Sub
End Class";

            var format = new SymbolDisplayFormat(
                memberOptions: SymbolDisplayMemberOptions.IncludeParameters | SymbolDisplayMemberOptions.IncludeModifiers | SymbolDisplayMemberOptions.IncludeAccessibility | SymbolDisplayMemberOptions.IncludeType,
                parameterOptions: SymbolDisplayParameterOptions.IncludeType | SymbolDisplayParameterOptions.IncludeName | SymbolDisplayParameterOptions.IncludeDefaultValue,
                miscellaneousOptions: SymbolDisplayMiscellaneousOptions.UseSpecialTypes);

            var comp = CreateVisualBasicCompilation("c", text);
            var a = (ITypeSymbol)comp.GlobalNamespace.GetMembers("A").Single();
            var foo = a.GetMembers("Foo").Single();
            var parts = Microsoft.CodeAnalysis.CSharp.SymbolDisplay.ToDisplayParts(foo, format);

            Verify(
                parts,
                "public void Foo(int a)",
                SymbolDisplayPartKind.Keyword,
                SymbolDisplayPartKind.Space,
                SymbolDisplayPartKind.Keyword,
                SymbolDisplayPartKind.Space,
                SymbolDisplayPartKind.MethodName,
                SymbolDisplayPartKind.Punctuation,
                SymbolDisplayPartKind.Keyword,
                SymbolDisplayPartKind.Space,
                SymbolDisplayPartKind.ParameterName,
                SymbolDisplayPartKind.Punctuation);
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:32,代码来源:SymbolDisplayTests.cs

示例15: ToMinimalDisplayParts

 /// <summary>
 /// Convert a symbol to an array of string parts, each of which has a kind. Useful for
 /// colorizing the display string.
 /// </summary>
 /// <param name="symbol">The symbol to be displayed.</param>
 /// <param name="semanticModel">Semantic information about the context in which the symbol is being displayed.</param>
 /// <param name="position">A position within the <see cref="SyntaxTree"/> or <paramref name="semanticModel"/>.</param>
 /// <param name="format">The formatting options to apply.  If null is passed, <see cref="SymbolDisplayFormat.CSharpErrorMessageFormat"/> will be used.</param>
 /// <returns>A list of display parts.</returns>
 /// <remarks>
 /// Parts are not localized until they are converted to strings.
 /// </remarks>
 public static ImmutableArray<SymbolDisplayPart> ToMinimalDisplayParts(
     ISymbol symbol,
     SemanticModel semanticModel,
     int position,
     SymbolDisplayFormat format = null)
 {
     format = format ?? SymbolDisplayFormat.MinimallyQualifiedFormat;
     return ToDisplayParts(symbol, semanticModel, position, format, minimal: true);
 }
开发者ID:GeneralRookie,项目名称:roslyn,代码行数:21,代码来源:SymbolDisplay.cs


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