本文整理汇总了C#中SyntaxReference.GetSyntax方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxReference.GetSyntax方法的具体用法?C# SyntaxReference.GetSyntax怎么用?C# SyntaxReference.GetSyntax使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyntaxReference
的用法示例。
在下文中一共展示了SyntaxReference.GetSyntax方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TypeParameterBuilder
internal TypeParameterBuilder(SyntaxReference syntaxRef, SourceNamedTypeSymbol owner, Location location)
{
this.syntaxRef = syntaxRef;
Debug.Assert(syntaxRef.GetSyntax().IsKind(SyntaxKind.TypeParameter));
this.owner = owner;
this.location = location;
}
示例2: Translate
protected override SyntaxNode Translate(SyntaxReference reference, CancellationToken cancellationToken)
{
var node = (CSharpSyntaxNode)reference.GetSyntax(cancellationToken);
// If the node is a name syntax, it's something like "X" or "X.Y" in :
// namespace X.Y.Z
// We want to return the full NamespaceDeclarationSyntax.
while (node is NameSyntax)
{
node = node.Parent;
}
Debug.Assert(node is CompilationUnitSyntax || node is NamespaceDeclarationSyntax);
return node;
}
示例3: EvaluateFieldConstant
public static EvaluatedConstant EvaluateFieldConstant(this FieldSymbol symbol, SyntaxReference equalsValueNodeRef, ConstantFieldsInProgress inProgress)
{
Debug.Assert(inProgress != null);
var diagnostics = DiagnosticBag.GetInstance();
try
{
ConstantValue value;
if (inProgress.Contains(symbol))
{
var errorField = inProgress.ErrorField;
diagnostics.Add(ErrorCode.ERR_CircConstValue, errorField.Locations[0], errorField);
value = Roslyn.Compilers.ConstantValue.Bad;
}
else
{
var compilation = ((SourceAssemblySymbol)symbol.ContainingAssembly).Compilation;
var binderFactory = compilation.GetBinderFactory(equalsValueNodeRef.SyntaxTree);
var newInProgress = inProgress.Add(symbol);
var equalsValueNode = (EqualsValueClauseSyntax)equalsValueNodeRef.GetSyntax();
var binder = binderFactory.GetBinder(equalsValueNode);
var inProgressBinder = new ConstantFieldsInProgressBinder(newInProgress, binder);
// CONSIDER: Compiler.BindFieldInitializer will make this same call on this same syntax node
// to determine the bound value for itself. We expect this binding to be fairly cheap
// (since constants tend to be simple) and it should only happen twice (regardless of the
// number of references to this constant). If this becomes a performance bottleneck,
// the re-binding can be eliminated by caching the BoundNode on this SourceFieldSymbol and
// checking for a cached value before binding (here and in Compiler.BindFieldInitializer).
var boundValue = inProgressBinder.BindVariableInitializer(equalsValueNode, symbol.Type, diagnostics);
var initValueNodeLocation = inProgressBinder.Location(equalsValueNode.Value);
value = ConstantValueUtils.GetAndValidateConstantValue(boundValue, symbol, symbol.Type, initValueNodeLocation, diagnostics);
}
return new EvaluatedConstant(value, diagnostics.Seal());
}
finally
{
diagnostics.Free();
}
}
示例4: SourceComplexParameterSymbol
internal SourceComplexParameterSymbol(
Symbol owner,
int ordinal,
TypeSymbol parameterType,
RefKind refKind,
ImmutableArray<CustomModifier> customModifiers,
bool hasByRefBeforeCustomModifiers,
string name,
ImmutableArray<Location> locations,
SyntaxReference syntaxRef,
ConstantValue defaultSyntaxValue,
bool isParams,
bool isExtensionMethodThis)
: base(owner, parameterType, ordinal, refKind, name, locations)
{
Debug.Assert((syntaxRef == null) || (syntaxRef.GetSyntax().IsKind(SyntaxKind.Parameter)));
Debug.Assert(!customModifiers.IsDefault);
_lazyHasOptionalAttribute = ThreeState.Unknown;
_syntaxRef = syntaxRef;
if (isParams)
{
_parameterSyntaxKind |= ParameterSyntaxKind.ParamsParameter;
}
if (isExtensionMethodThis)
{
_parameterSyntaxKind |= ParameterSyntaxKind.ExtensionThisParameter;
}
var parameterSyntax = this.CSharpSyntaxNode;
if (parameterSyntax != null && parameterSyntax.Default != null)
{
_parameterSyntaxKind |= ParameterSyntaxKind.DefaultParameter;
}
_lazyDefaultSyntaxValue = defaultSyntaxValue;
_customModifiers = customModifiers;
_hasByRefBeforeCustomModifiers = hasByRefBeforeCustomModifiers;
}
示例5: GetBinder
internal Binder GetBinder(SyntaxReference reference)
{
return GetBinderFactory(reference.SyntaxTree).GetBinder((CSharpSyntaxNode)reference.GetSyntax());
}
示例6: GetTopmostNodeForAnalysis
private static SyntaxNode GetTopmostNodeForAnalysis(ISymbol symbol, SyntaxReference syntaxReference, Compilation compilation)
{
var model = compilation.GetSemanticModel(syntaxReference.SyntaxTree);
return model.GetTopmostNodeForDiagnosticAnalysis(symbol, syntaxReference.GetSyntax());
}