本文整理汇总了C#中DeclarationExpressionSyntax.Type方法的典型用法代码示例。如果您正苦于以下问题:C# DeclarationExpressionSyntax.Type方法的具体用法?C# DeclarationExpressionSyntax.Type怎么用?C# DeclarationExpressionSyntax.Type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DeclarationExpressionSyntax
的用法示例。
在下文中一共展示了DeclarationExpressionSyntax.Type方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例2: 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);
}
}
示例3: 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));
//.........这里部分代码省略.........
示例4: 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);
}
示例5: 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());
}
}
示例6: 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);
}
示例7: VisitDeclarationExpression
public override void VisitDeclarationExpression(DeclarationExpressionSyntax node)
{
var argumentSyntax = (ArgumentSyntax)node?.Parent;
var argumentListSyntax = (BaseArgumentListSyntax)argumentSyntax?.Parent;
_localsBuilder.Add(SourceLocalSymbol.MakeLocalSymbolWithEnclosingContext(
containingSymbol: _scopeBinder.ContainingMemberOrLambda,
scopeBinder: _scopeBinder,
nodeBinder: _enclosingBinder,
typeSyntax: node.Type(),
identifierToken: node.Identifier(),
kind: LocalDeclarationKind.RegularVariable,
nodeToBind: _nodeToBind,
forbiddenZone: argumentListSyntax));
}