本文整理汇总了C#中DeclarationExpressionSyntax类的典型用法代码示例。如果您正苦于以下问题:C# DeclarationExpressionSyntax类的具体用法?C# DeclarationExpressionSyntax怎么用?C# DeclarationExpressionSyntax使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DeclarationExpressionSyntax类属于命名空间,在下文中一共展示了DeclarationExpressionSyntax类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: BindDeconstructionVariables
/// <summary>
/// Prepares locals (or fields in global statement) and lvalue expressions corresponding to the variables of the declaration.
/// The locals/fields/lvalues are kept in a tree which captures the nesting of variables.
/// Each local or field is either a simple local or field access (when its type is known) or a deconstruction variable pending inference.
/// The caller is responsible for releasing the nested ArrayBuilders.
/// </summary>
private DeconstructionVariable BindDeconstructionVariables(
ExpressionSyntax node,
DiagnosticBag diagnostics,
ref DeclarationExpressionSyntax declaration,
ref ExpressionSyntax expression)
{
switch (node.Kind())
{
case SyntaxKind.DeclarationExpression:
{
var component = (DeclarationExpressionSyntax)node;
if (declaration == null)
{
declaration = component;
}
bool isVar;
bool isConst = false;
AliasSymbol alias;
TypeSymbol declType = BindVariableType(component.Designation, diagnostics, component.Type, ref isConst, out isVar, out alias);
Debug.Assert(isVar == ((object)declType == null));
if (component.Designation.Kind() == SyntaxKind.ParenthesizedVariableDesignation && !isVar)
{
// An explicit is not allowed with a parenthesized designation
Error(diagnostics, ErrorCode.ERR_DeconstructionVarFormDisallowsSpecificType, component.Designation);
}
return BindDeconstructionVariables(declType, component.Designation, diagnostics);
}
case SyntaxKind.TupleExpression:
{
var component = (TupleExpressionSyntax)node;
var builder = ArrayBuilder<DeconstructionVariable>.GetInstance(component.Arguments.Count);
foreach (var arg in component.Arguments)
{
if (arg.NameColon != null)
{
Error(diagnostics, ErrorCode.ERR_TupleElementNamesInDeconstruction, arg.NameColon);
}
builder.Add(BindDeconstructionVariables(arg.Expression, diagnostics, ref declaration, ref expression));
}
return new DeconstructionVariable(builder, node);
}
default:
var boundVariable = BindExpression(node, diagnostics, invoked: false, indexed: false);
var checkedVariable = CheckValue(boundVariable, BindValueKind.Assignment, diagnostics);
if (expression == null && checkedVariable.Kind != BoundKind.DiscardExpression)
{
expression = node;
}
return new DeconstructionVariable(checkedVariable, node);
}
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:62,代码来源:Binder_Deconstruct.cs
示例2: GetVariableDeclarator
private static VariableDeclaratorSyntax GetVariableDeclarator(DeclarationExpressionSyntax decl)
{
return decl.Declaration.Variables.Single();
}
开发者ID:Rickinio,项目名称:roslyn,代码行数:4,代码来源:OutVarTests.cs
示例3: VerifyModelForOutVar
private static void VerifyModelForOutVar(
SemanticModel model,
DeclarationExpressionSyntax decl,
bool isDelegateCreation,
bool isExecutableCode,
bool isShadowed,
bool verifyDataFlow = true,
params IdentifierNameSyntax[] references)
{
var variableDeclaratorSyntax = GetVariableDesignation(decl);
var symbol = model.GetDeclaredSymbol(variableDeclaratorSyntax);
Assert.NotNull(symbol);
Assert.Equal(decl.Identifier().ValueText, symbol.Name);
Assert.Equal(variableDeclaratorSyntax, symbol.DeclaringSyntaxReferences.Single().GetSyntax());
Assert.Equal(LocalDeclarationKind.RegularVariable, ((LocalSymbol)symbol).DeclarationKind);
Assert.Same(symbol, model.GetDeclaredSymbol((SyntaxNode)variableDeclaratorSyntax));
if (isShadowed)
{
Assert.NotEqual(symbol, model.LookupSymbols(decl.SpanStart, name: decl.Identifier().ValueText).Single());
}
else
{
Assert.Same(symbol, model.LookupSymbols(decl.SpanStart, name: decl.Identifier().ValueText).Single());
}
Assert.True(model.LookupNames(decl.SpanStart).Contains(decl.Identifier().ValueText));
var local = (SourceLocalSymbol)symbol;
var typeSyntax = decl.Type();
Assert.True(SyntaxFacts.IsInNamespaceOrTypeContext(typeSyntax));
Assert.True(SyntaxFacts.IsInTypeOnlyContext(typeSyntax));
if (typeSyntax.IsVar && local.IsVar && local.Type.IsErrorType())
{
Assert.Null(model.GetSymbolInfo(typeSyntax).Symbol);
}
else
{
Assert.Equal(local.Type, model.GetSymbolInfo(typeSyntax).Symbol);
}
Assert.Same(symbol, model.GetSymbolInfo(decl).Symbol);
Assert.Equal(local.Type, model.GetTypeInfo(decl).Type);
Assert.Null(model.GetDeclaredSymbol(decl));
foreach (var reference in references)
{
Assert.Same(symbol, model.GetSymbolInfo(reference).Symbol);
Assert.Same(symbol, model.LookupSymbols(reference.SpanStart, name: decl.Identifier().ValueText).Single());
Assert.True(model.LookupNames(reference.SpanStart).Contains(decl.Identifier().ValueText));
Assert.Equal(local.Type, model.GetTypeInfo(reference).Type);
}
if (verifyDataFlow)
{
VerifyDataFlow(model, decl, isDelegateCreation, isExecutableCode, references, symbol);
}
}
开发者ID:orthoxerox,项目名称:roslyn,代码行数:60,代码来源:OutVarTests.cs
示例4: VerifyModelForOutVarDuplicateInSameScope
private static void VerifyModelForOutVarDuplicateInSameScope(SemanticModel model, DeclarationExpressionSyntax decl)
{
var variableDesignationSyntax = GetVariableDesignation(decl);
var symbol = model.GetDeclaredSymbol(variableDesignationSyntax);
Assert.Equal(decl.Identifier().ValueText, symbol.Name);
Assert.Equal(variableDesignationSyntax, symbol.DeclaringSyntaxReferences.Single().GetSyntax());
Assert.Equal(LocalDeclarationKind.RegularVariable, ((LocalSymbol)symbol).DeclarationKind);
Assert.Same(symbol, model.GetDeclaredSymbol((SyntaxNode)variableDesignationSyntax));
Assert.NotEqual(symbol, model.LookupSymbols(decl.SpanStart, name: decl.Identifier().ValueText).Single());
Assert.True(model.LookupNames(decl.SpanStart).Contains(decl.Identifier().ValueText));
var local = (SourceLocalSymbol)symbol;
if (decl.Type().IsVar && local.IsVar && local.Type.IsErrorType())
{
Assert.Null(model.GetSymbolInfo(decl.Type()).Symbol);
}
else
{
Assert.Equal(local.Type, model.GetSymbolInfo(decl.Type()).Symbol);
}
}
开发者ID:orthoxerox,项目名称:roslyn,代码行数:22,代码来源:OutVarTests.cs
示例5: VerifyModelForOutFieldDuplicate
private static void VerifyModelForOutFieldDuplicate(
SemanticModel model,
DeclarationExpressionSyntax decl,
params IdentifierNameSyntax[] references)
{
VerifyModelForOutField(model, decl, true, references);
}
开发者ID:orthoxerox,项目名称:roslyn,代码行数:7,代码来源:OutVarTests.cs
示例6: VerifyModelForOutVarWithoutDataFlow
private static void VerifyModelForOutVarWithoutDataFlow(SemanticModel model, DeclarationExpressionSyntax decl, params IdentifierNameSyntax[] references)
{
VerifyModelForOutVar(model, decl, false, true, false, false, references);
}
开发者ID:orthoxerox,项目名称:roslyn,代码行数:4,代码来源:OutVarTests.cs
示例7: VisitDeclarationExpression
public override void VisitDeclarationExpression(DeclarationExpressionSyntax node)
{
var context = node?.Parent // ArgumentSyntax
?.Parent // ArgumentListSyntax
?.Parent; // invocation/constructor initializer
switch (context?.Kind())
{
case SyntaxKind.InvocationExpression:
case SyntaxKind.ObjectCreationExpression:
case SyntaxKind.ThisConstructorInitializer:
case SyntaxKind.BaseConstructorInitializer:
var local = SourceLocalSymbol.MakeOutVariable(_scopeBinder.ContainingMemberOrLambda, _scopeBinder, _enclosingBinderOpt, node.Type(), node.Identifier(), context);
_localsBuilder.Add(local);
break;
default:
// It looks like we are deling with a syntax tree that has a shape that could never be
// produced by the LanguageParser, including all error conditions.
// Out Variable declarations can only appear in an argument list of the syntax nodes mentioned above.
throw ExceptionUtilities.UnexpectedValue(context?.Kind());
}
}
开发者ID:tvsonar,项目名称:roslyn,代码行数:22,代码来源:ExpressionVariableFinder.cs
示例8: AssertContainedInDeclaratorArguments
private static void AssertContainedInDeclaratorArguments(DeclarationExpressionSyntax decl)
{
Assert.True(decl.Ancestors().OfType<VariableDeclaratorSyntax>().First().ArgumentList.Contains(decl));
}
开发者ID:orthoxerox,项目名称:roslyn,代码行数:4,代码来源:OutVarTests.cs
示例9: VisitDeclarationExpression
public override void VisitDeclarationExpression(DeclarationExpressionSyntax node)
{
Debug.Assert(currentScope != null);
builder.Add(new SemanticModelInfo(currentScope, node.Variable));
Visit(node.Variable.Initializer);
}
开发者ID:jerriclynsjohn,项目名称:roslyn,代码行数:6,代码来源:DeclarationExpressionsTests.cs
示例10: GetDeclaredSymbol
public override ILocalSymbol GetDeclaredSymbol(DeclarationExpressionSyntax declarationSyntax, CancellationToken cancellationToken = default(CancellationToken))
{
CheckSyntaxNode(declarationSyntax);
return GetDeclaredLocal(declarationSyntax, declarationSyntax.Identifier());
}
开发者ID:Shiney,项目名称:roslyn,代码行数:5,代码来源:MemberSemanticModel.cs
示例11: IsDeclarationExpressionType
internal static bool IsDeclarationExpressionType(SyntaxNode node, out DeclarationExpressionSyntax parent)
{
parent = node.Parent as DeclarationExpressionSyntax;
return node == parent?.Type;
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:5,代码来源:SyntaxFacts.cs
示例12: AddTypeAndName
private void AddTypeAndName(
DeclarationExpressionSyntax declaration,
ArrayBuilder<ITypeSymbol> elementTypesBuilder,
ArrayBuilder<string> elementNamesBuilder)
{
elementTypesBuilder.Add(GetTypes(declaration.Type).FirstOrDefault().InferredType);
var designation = declaration.Designation;
if (designation.IsKind(SyntaxKind.SingleVariableDesignation))
{
var singleVariable = (SingleVariableDesignationSyntax)designation;
var name = singleVariable.Identifier.ValueText;
if (name != string.Empty)
{
elementNamesBuilder.Add(name);
return;
}
}
elementNamesBuilder.Add(null);
}
开发者ID:GuilhermeSa,项目名称:roslyn,代码行数:22,代码来源:CSharpTypeInferenceService.TypeInferrer.cs
示例13: VerifyModelForOutVar
private static void VerifyModelForOutVar(SemanticModel model, DeclarationExpressionSyntax decl, bool isDelegateCreation, bool isExecutableCode, params IdentifierNameSyntax[] references)
{
var variableDeclaratorSyntax = GetVariableDeclarator(decl);
var symbol = model.GetDeclaredSymbol(variableDeclaratorSyntax);
Assert.Equal(decl.Identifier().ValueText, symbol.Name);
Assert.Equal(LocalDeclarationKind.RegularVariable, ((LocalSymbol)symbol).DeclarationKind);
Assert.Same(symbol, model.GetDeclaredSymbol((SyntaxNode)variableDeclaratorSyntax));
Assert.Same(symbol, model.LookupSymbols(decl.SpanStart, name: decl.Identifier().ValueText).Single());
Assert.True(model.LookupNames(decl.SpanStart).Contains(decl.Identifier().ValueText));
var local = (SourceLocalSymbol)symbol;
if (decl.Type().IsVar && local.IsVar && local.Type.IsErrorType())
{
Assert.Null(model.GetSymbolInfo(decl.Type()).Symbol);
}
else
{
Assert.Equal(local.Type, model.GetSymbolInfo(decl.Type()).Symbol);
}
foreach (var reference in references)
{
Assert.Same(symbol, model.GetSymbolInfo(reference).Symbol);
Assert.Same(symbol, model.LookupSymbols(reference.SpanStart, name: decl.Identifier().ValueText).Single());
Assert.True(model.LookupNames(reference.SpanStart).Contains(decl.Identifier().ValueText));
Assert.Equal(local.Type, model.GetTypeInfo(reference).Type);
}
VerifyDataFlow(model, decl, isDelegateCreation, isExecutableCode, references, symbol);
}
开发者ID:Rickinio,项目名称:roslyn,代码行数:31,代码来源:OutVarTests.cs
示例14: FlowsIn
private static bool FlowsIn(ExpressionSyntax dataFlowParent, DeclarationExpressionSyntax decl, IdentifierNameSyntax[] references)
{
foreach (var reference in references)
{
if (dataFlowParent.Span.Contains(reference.Span) && reference.SpanStart > decl.SpanStart)
{
if (IsRead(reference))
{
return true;
}
}
}
return false;
}
开发者ID:orthoxerox,项目名称:roslyn,代码行数:15,代码来源:OutVarTests.cs
示例15: IsIdentifierOfOutVariableDeclaration
internal static bool IsIdentifierOfOutVariableDeclaration(this SyntaxToken identifier, out DeclarationExpressionSyntax declarationExpression)
{
Debug.Assert(identifier.Kind() == SyntaxKind.IdentifierToken || identifier.Kind() == SyntaxKind.None);
SyntaxNode parent;
if ((parent = identifier.Parent)?.Kind() == SyntaxKind.SingleVariableDesignation &&
(parent = parent.Parent)?.Kind() == SyntaxKind.TypedVariableComponent &&
(parent = parent.Parent)?.Kind() == SyntaxKind.DeclarationExpression)
{
declarationExpression = (DeclarationExpressionSyntax)parent;
if (declarationExpression.Identifier() == identifier && declarationExpression.Parent.Kind() == SyntaxKind.Argument)
{
return true;
}
}
declarationExpression = null;
return false;
}
开发者ID:Shiney,项目名称:roslyn,代码行数:19,代码来源:SyntaxExtensions.cs
示例16: FlowsOut
private static bool FlowsOut(ExpressionSyntax dataFlowParent, DeclarationExpressionSyntax decl, IdentifierNameSyntax[] references)
{
ForStatementSyntax forStatement;
if ((forStatement = decl.Ancestors().OfType<ForStatementSyntax>().FirstOrDefault()) != null &&
forStatement.Incrementors.Span.Contains(decl.Position) &&
forStatement.Statement.DescendantNodes().OfType<ForStatementSyntax>().Any(f => f.Condition == null))
{
return false;
}
var containingStatement = decl.Ancestors().OfType<StatementSyntax>().FirstOrDefault();
var containingReturnOrThrow = containingStatement as ReturnStatementSyntax ?? (StatementSyntax)(containingStatement as ThrowStatementSyntax);
MethodDeclarationSyntax methodDeclParent;
if (containingReturnOrThrow != null && decl.Identifier().ValueText == "x1" &&
((methodDeclParent = containingReturnOrThrow.Parent.Parent as MethodDeclarationSyntax) == null ||
methodDeclParent.Body.Statements.First() != containingReturnOrThrow))
{
return false;
}
foreach (var reference in references)
{
if (!dataFlowParent.Span.Contains(reference.Span) &&
(containingReturnOrThrow == null || containingReturnOrThrow.Span.Contains(reference.SpanStart)) &&
(reference.SpanStart > decl.SpanStart ||
(containingReturnOrThrow == null &&
reference.Ancestors().OfType<DoStatementSyntax>().Join(
decl.Ancestors().OfType<DoStatementSyntax>(), d => d, d => d, (d1, d2) => true).Any())))
{
if (IsRead(reference))
{
return true;
}
}
}
return false;
}
开发者ID:orthoxerox,项目名称:roslyn,代码行数:41,代码来源:OutVarTests.cs
示例17: GetDeclaredSymbol
/// <summary>
/// Given an out variable declaration expression syntax, get the corresponding symbol.
/// </summary>
/// <param name="declarationSyntax">The syntax node that declares a variable.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>The symbol that was declared.</returns>
public override ILocalSymbol GetDeclaredSymbol(DeclarationExpressionSyntax declarationSyntax, CancellationToken cancellationToken = default(CancellationToken))
{
var memberModel = this.GetMemberModel(declarationSyntax);
return memberModel == null ? null : memberModel.GetDeclaredSymbol(declarationSyntax, cancellationToken);
}
开发者ID:xeronith,项目名称:roslyn,代码行数:11,代码来源:SyntaxTreeSemanticModel.cs
示例18: VerifyModelNotSupported
private static void VerifyModelNotSupported(
SemanticModel model,
DeclarationExpressionSyntax decl,
params IdentifierNameSyntax[] references)
{
var variableDeclaratorSyntax = GetVariableDesignation(decl);
Assert.Null(model.GetDeclaredSymbol(variableDeclaratorSyntax));
Assert.Null(model.GetDeclaredSymbol((SyntaxNode)variableDeclaratorSyntax));
var identifierText = decl.Identifier().ValueText;
Assert.False(model.LookupSymbols(decl.SpanStart, name: identifierText).Any());
Assert.False(model.LookupNames(decl.SpanStart).Contains(identifierText));
Assert.Null(model.GetSymbolInfo(decl.Type()).Symbol);
Assert.Null(model.GetSymbolInfo(decl).Symbol);
Assert.Null(model.GetTypeInfo(decl).Type);
Assert.Null(model.GetDeclaredSymbol(decl));
VerifyModelNotSupported(model, references);
}
开发者ID:orthoxerox,项目名称:roslyn,代码行数:19,代码来源:OutVarTests.cs
示例19: GetDeclaredSymbol
/// <summary>
/// Given an out variable declaration expression, get the corresponding symbol.
/// </summary>
/// <param name="declarationSyntax">The syntax node that declares a variable.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>The symbol that was declared.</returns>
public abstract ISymbol GetDeclaredSymbol(DeclarationExpressionSyntax declarationSyntax, CancellationToken cancellationToken = default(CancellationToken));
开发者ID:Rickinio,项目名称:roslyn,代码行数:7,代码来源:CSharpSemanticModel.cs
示例20: VerifyModelForOutField
private static void VerifyModelForOutField(
SemanticModel model,
DeclarationExpressionSyntax decl,
bool duplicate,
params IdentifierNameSyntax[] references)
{
var variableDesignationSyntax = GetVariableDesignation(decl);
var symbol = model.GetDeclaredSymbol(variableDesignationSyntax);
Assert.Equal(decl.Identifier().ValueText, symbol.Name);
Assert.Equal(SymbolKind.Field, symbol.Kind);
Assert.Equal(variableDesignationSyntax, symbol.DeclaringSyntaxReferences.Single().GetSyntax());
Assert.Same(symbol, model.GetDeclaredSymbol((SyntaxNode)variableDesignationSyntax));
var symbols = model.LookupSymbols(decl.SpanStart, name: decl.Identifier().ValueText);
var names = model.LookupNames(decl.SpanStart);
if (duplicate)
{
Assert.True(symbols.Count() > 1);
Assert.Contains(symbol, symbols);
}
else
{
Assert.Same(symbol, symbols.Single());
}
Assert.Contains(decl.Identifier().ValueText, names);
var local = (FieldSymbol)symbol;
var typeSyntax = decl.Type();
Assert.True(SyntaxFacts.IsInNamespaceOrTypeContext(typeSyntax));
Assert.True(SyntaxFacts.IsInTypeOnlyContext(typeSyntax));
if (typeSyntax.IsVar && local.Type.IsErrorType())
{
Assert.Null(model.GetSymbolInfo(typeSyntax).Symbol);
}
else
{
Assert.Equal(local.Type, model.GetSymbolInfo(typeSyntax).Symbol);
}
var declarator = decl.Ancestors().OfType<VariableDeclaratorSyntax>().FirstOrDefault();
var inFieldDeclaratorArgumentlist = declarator != null && declarator.Parent.Parent.Kind() != SyntaxKind.LocalDeclarationStatement &&
(declarator.ArgumentList?.Contains(decl)).GetValueOrDefault();
if (inFieldDeclaratorArgumentlist)
{
Assert.Null(model.GetSymbolInfo(decl).Symbol);
Assert.Null(model.GetSymbolInfo(decl).Symbol);
}
else
{
Assert.Same(symbol, model.GetSymbolInfo(decl).Symbol);
Assert.Same(symbol, model.GetSymbolInfo(decl).Symbol);
}
Assert.Null(model.GetDeclaredSymbol(decl));
foreach (var reference in references)
{
var referenceInfo = model.GetSymbolInfo(reference);
symbols = model.LookupSymbols(reference.SpanStart, name: decl.Identifier().ValueText);
if (duplicate)
{
Assert.Null(referenceInfo.Symbol);
Assert.Contains(symbol, referenceInfo.CandidateSymbols);
Assert.True(symbols.Count() > 1);
Assert.Contains(symbol, symbols);
}
else
{
Assert.Same(symbol, referenceInfo.Symbol);
Assert.Same(symbol, symbols.Single());
Assert.Equal(local.Type, model.GetTypeInfo(reference).Type);
}
Assert.True(model.LookupNames(reference.SpanStart).Contains(decl.Identifier().ValueText));
}
if (!inFieldDeclaratorArgumentlist)
{
var dataFlowParent = (ExpressionSyntax)decl.Parent.Parent.Parent;
if (model.IsSpeculativeSemanticModel)
{
Assert.Throws<NotSupportedException>(() => model.AnalyzeDataFlow(dataFlowParent));
}
else
{
var dataFlow = model.AnalyzeDataFlow(dataFlowParent);
if (dataFlow.Succeeded)
{
Assert.False(dataFlow.VariablesDeclared.Contains(symbol, ReferenceEqualityComparer.Instance));
Assert.False(dataFlow.AlwaysAssigned.Contains(symbol, ReferenceEqualityComparer.Instance));
Assert.False(dataFlow.WrittenInside.Contains(symbol, ReferenceEqualityComparer.Instance));
Assert.False(dataFlow.DataFlowsIn.Contains(symbol, ReferenceEqualityComparer.Instance));
Assert.False(dataFlow.ReadInside.Contains(symbol, ReferenceEqualityComparer.Instance));
//.........这里部分代码省略.........
开发者ID:orthoxerox,项目名称:roslyn,代码行数:101,代码来源:OutVarTests.cs
注:本文中的DeclarationExpressionSyntax类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论