本文整理汇总了C#中CrefSyntax类的典型用法代码示例。如果您正苦于以下问题:C# CrefSyntax类的具体用法?C# CrefSyntax怎么用?C# CrefSyntax使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CrefSyntax类属于命名空间,在下文中一共展示了CrefSyntax类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BindCref
internal ImmutableArray<Symbol> BindCref(CrefSyntax syntax, out Symbol ambiguityWinner, DiagnosticBag diagnostics)
{
ImmutableArray<Symbol> symbols = BindCrefInternal(syntax, out ambiguityWinner, diagnostics);
Debug.Assert(!symbols.IsDefault, "Prefer empty to null.");
Debug.Assert((symbols.Length > 1) == ((object)ambiguityWinner != null), "ambiguityWinner should be set iff more than one symbol is returned.");
return symbols;
}
示例2: BindCrefInternal
private ImmutableArray<Symbol> BindCrefInternal(CrefSyntax syntax, out Symbol ambiguityWinner, DiagnosticBag diagnostics)
{
switch (syntax.Kind())
{
case SyntaxKind.TypeCref:
return BindTypeCref((TypeCrefSyntax)syntax, out ambiguityWinner, diagnostics);
case SyntaxKind.QualifiedCref:
return BindQualifiedCref((QualifiedCrefSyntax)syntax, out ambiguityWinner, diagnostics);
case SyntaxKind.NameMemberCref:
case SyntaxKind.IndexerMemberCref:
case SyntaxKind.OperatorMemberCref:
case SyntaxKind.ConversionOperatorMemberCref:
return BindMemberCref((MemberCrefSyntax)syntax, containerOpt: null, ambiguityWinner: out ambiguityWinner, diagnostics: diagnostics);
default:
throw ExceptionUtilities.UnexpectedValue(syntax.Kind());
}
}
示例3: BindCrefInternal
private ImmutableArray<Symbol> BindCrefInternal(CrefSyntax syntax, out Symbol ambiguityWinner, DiagnosticBag diagnostics)
{
switch (syntax.Kind)
{
case SyntaxKind.TypeCref:
return BindTypeCref((TypeCrefSyntax)syntax, out ambiguityWinner, diagnostics);
case SyntaxKind.QualifiedCref:
return BindQualifiedCref((QualifiedCrefSyntax)syntax, out ambiguityWinner, diagnostics);
case SyntaxKind.NameMemberCref:
case SyntaxKind.IndexerMemberCref:
case SyntaxKind.OperatorMemberCref:
case SyntaxKind.ConversionOperatorMemberCref:
return BindMemberCref((MemberCrefSyntax)syntax, containerOpt: null, ambiguityWinner: out ambiguityWinner, diagnostics: diagnostics);
default:
Debug.Assert(false, "Unexpected cref kind " + syntax.Kind);
ambiguityWinner = null;
return ImmutableArray<Symbol>.Empty;
}
}
示例4: CrefAttribute
public static XmlCrefAttributeSyntax CrefAttribute(CrefSyntax cref)
{
return CrefAttribute(cref, SyntaxKind.DoubleQuoteToken);
}
示例5: TryGetSpeculativeSemanticModelCore
internal override bool TryGetSpeculativeSemanticModelCore(SyntaxTreeSemanticModel parentModel, int position, CrefSyntax crefSyntax, out SemanticModel speculativeModel)
{
position = CheckAndAdjustPosition(position);
Binder binder = GetEnclosingBinder(position);
if (binder != null &&
(binder.Flags.Includes(BinderFlags.Cref) || binder.Flags.Includes(BinderFlags.CrefParameterOrReturnType)))
{
speculativeModel = SpeculativeSyntaxTreeSemanticModel.Create(parentModel, crefSyntax, binder, position);
return true;
}
speculativeModel = null;
return false;
}
示例6: TryGetSpeculativeSemanticModelCore
internal sealed override bool TryGetSpeculativeSemanticModelCore(SyntaxTreeSemanticModel parentModel, int position, CrefSyntax crefSyntax, out SemanticModel speculativeModel)
{
// crefs can never legally appear within members.
speculativeModel = null;
return false;
}
示例7: ToBadCrefString
/// <summary>
/// Given a cref syntax that cannot be resolved, get the string that will be written to
/// the documentation file in place of a documentation comment ID.
/// </summary>
private static string ToBadCrefString(CrefSyntax cref)
{
using (StringWriter tmp = new StringWriter(CultureInfo.InvariantCulture))
{
cref.WriteTo(tmp);
return "!:" + tmp.ToString().Replace("{", "<").Replace("}", ">");
}
}
示例8: GetDocumentationCommentId
/// <summary>
/// Bind a CrefSyntax and unwrap the result if it's an alias.
/// </summary>
/// <remarks>
/// Does not respect DocumentationMode, so use a temporary bag if diagnostics are not desired.
/// </remarks>
private static string GetDocumentationCommentId(CrefSyntax crefSyntax, Binder binder, DiagnosticBag diagnostics)
{
if (crefSyntax.ContainsDiagnostics)
{
return ToBadCrefString(crefSyntax);
}
Symbol ambiguityWinner;
ImmutableArray<Symbol> symbols = binder.BindCref(crefSyntax, out ambiguityWinner, diagnostics);
Symbol symbol;
switch (symbols.Length)
{
case 0:
return ToBadCrefString(crefSyntax);
case 1:
symbol = symbols[0];
break;
default:
symbol = ambiguityWinner;
Debug.Assert((object)symbol != null);
break;
}
if (symbol.Kind == SymbolKind.Alias)
{
symbol = ((AliasSymbol)symbol).GetAliasTarget(basesBeingResolved: null);
}
return symbol.OriginalDefinition.GetDocumentationCommentId();
}
示例9: GetReferencedSymbols
private static ImmutableArray<Symbol> GetReferencedSymbols(CrefSyntax crefSyntax, CSharpCompilation compilation, out Symbol ambiguityWinner, params DiagnosticDescription[] expectedDiagnostics)
{
var binderFactory = compilation.GetBinderFactory(crefSyntax.SyntaxTree);
var binder = binderFactory.GetBinder(crefSyntax);
DiagnosticBag diagnostics = DiagnosticBag.GetInstance();
var references = binder.BindCref(crefSyntax, out ambiguityWinner, diagnostics);
diagnostics.Verify(expectedDiagnostics);
diagnostics.Free();
return references;
}
示例10: GetReferencedSymbol
private static Symbol GetReferencedSymbol(CrefSyntax crefSyntax, CSharpCompilation compilation, params DiagnosticDescription[] expectedDiagnostics)
{
Symbol ambiguityWinner;
var references = GetReferencedSymbols(crefSyntax, compilation, out ambiguityWinner, expectedDiagnostics);
Assert.Null(ambiguityWinner);
Assert.InRange(references.Length, 0, 1); //Otherwise, call GetReferencedSymbols
return references.FirstOrDefault();
}
示例11: TryReduceOrSimplifyExplicitName
public static bool TryReduceOrSimplifyExplicitName(
this CrefSyntax crefSyntax,
SemanticModel semanticModel,
out CrefSyntax replacementNode,
out TextSpan issueSpan,
OptionSet optionSet,
CancellationToken cancellationToken)
{
replacementNode = null;
issueSpan = default(TextSpan);
// Currently Qualified Cref is the only CrefSyntax We are handling separately
if (crefSyntax.Kind() != SyntaxKind.QualifiedCref)
{
return false;
}
var qualifiedCrefSyntax = (QualifiedCrefSyntax)crefSyntax;
var memberCref = qualifiedCrefSyntax.Member;
// Currently we are dealing with only the NameMemberCrefs
if (optionSet.GetOption(SimplificationOptions.PreferIntrinsicPredefinedTypeKeywordInMemberAccess, LanguageNames.CSharp) &&
(memberCref.Kind() == SyntaxKind.NameMemberCref))
{
var nameMemberCref = ((NameMemberCrefSyntax)memberCref).Name;
var symbolInfo = semanticModel.GetSymbolInfo(nameMemberCref, cancellationToken);
var symbol = symbolInfo.Symbol;
if (symbol == null)
{
return false;
}
if (symbol is INamespaceOrTypeSymbol)
{
//var namespaceOrTypeSymbol = (INamespaceOrTypeSymbol)symbol;
// 1. Check for Predefined Types
if (symbol is INamedTypeSymbol)
{
var namedSymbol = (INamedTypeSymbol)symbol;
var keywordKind = ExpressionSyntaxExtensions.GetPredefinedKeywordKind(namedSymbol.SpecialType);
if (keywordKind != SyntaxKind.None)
{
replacementNode = SyntaxFactory.TypeCref(
SyntaxFactory.PredefinedType(
SyntaxFactory.Token(crefSyntax.GetLeadingTrivia(), keywordKind, crefSyntax.GetTrailingTrivia())));
replacementNode = crefSyntax.CopyAnnotationsTo(replacementNode);
// we want to show the whole name expression as unnecessary
issueSpan = crefSyntax.Span;
return true;
}
}
}
}
var oldSymbol = semanticModel.GetSymbolInfo(crefSyntax, cancellationToken).Symbol;
if (oldSymbol != null)
{
var speculativeBindingOption = SpeculativeBindingOption.BindAsExpression;
if (oldSymbol is INamespaceOrTypeSymbol)
{
speculativeBindingOption = SpeculativeBindingOption.BindAsTypeOrNamespace;
}
var newSymbol = semanticModel.GetSpeculativeSymbolInfo(crefSyntax.SpanStart, memberCref, speculativeBindingOption).Symbol;
if (newSymbol == oldSymbol)
{
// Copy Trivia and Annotations
memberCref = memberCref.WithLeadingTrivia(crefSyntax.GetLeadingTrivia());
memberCref = crefSyntax.CopyAnnotationsTo(memberCref);
issueSpan = qualifiedCrefSyntax.Container.Span;
replacementNode = memberCref;
return true;
}
}
return false;
}
示例12: WithCrefTypeParametersBinder
internal WithCrefTypeParametersBinder(CrefSyntax crefSyntax, Binder next)
: base(next)
{
_crefSyntax = crefSyntax;
}
示例13: ExceptionElement
public static XmlElementSyntax ExceptionElement(CrefSyntax cref, params XmlNodeSyntax[] content)
{
return ExceptionElement(cref, List(content));
}
示例14: CrefAttribute
public static XmlCrefAttributeSyntax CrefAttribute(CrefSyntax cref, SyntaxKind quoteKind)
{
return XmlCrefAttribute(
XmlName("cref"),
Token(quoteKind),
cref,
Token(quoteKind))
.WithLeadingTrivia(Whitespace(" "));
}
示例15: Create
public static SpeculativeSyntaxTreeSemanticModel Create(CSharpSemanticModel parentSemanticModel, CrefSyntax root, Binder rootBinder, int position)
{
return CreateCore(parentSemanticModel, root, rootBinder, position, bindingOption: SpeculativeBindingOption.BindAsTypeOrNamespace);
}