本文整理汇总了C#中CSharpSyntaxNode类的典型用法代码示例。如果您正苦于以下问题:C# CSharpSyntaxNode类的具体用法?C# CSharpSyntaxNode怎么用?C# CSharpSyntaxNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CSharpSyntaxNode类属于命名空间,在下文中一共展示了CSharpSyntaxNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExpressionStatementASTWalker
/// <summary>
/// Initializes a new instance of the <see cref="ExpressionStatementASTWalker"/> class.
/// </summary>
/// <param name="node"></param>
/// <param name="statement"></param>
/// <param name="semanticModel">The semantic model.</param>
protected ExpressionStatementASTWalker(CSharpSyntaxNode node, ExpressionStatementTranslationUnit expressionStatement, SemanticModel semanticModel)
: base(node, semanticModel)
{
var returnSyntaxNode = node as ReturnStatementSyntax;
var throwSyntaxNode = node as ThrowStatementSyntax;
var expressionSyntaxNode = node as ExpressionStatementSyntax;
if (returnSyntaxNode == null && throwSyntaxNode == null && expressionSyntaxNode == null)
{
throw new ArgumentException(
string.Format("Specified node ({0}) is not one of these types: {1}, {2}, {3}!",
node.GetType().Name,
typeof(ReturnStatementSyntax).Name,
typeof(ThrowStatementSyntax).Name),
typeof(ExpressionStatementSyntax).Name);
}
if (expressionStatement == null)
{
throw new ArgumentNullException(nameof(expressionStatement));
}
// Node assigned in base, no need to assign it here
this.statement = expressionStatement;
}
示例2: RewriteConditionalOperator
private static BoundExpression RewriteConditionalOperator(
CSharpSyntaxNode syntax,
BoundExpression rewrittenCondition,
BoundExpression rewrittenConsequence,
BoundExpression rewrittenAlternative,
ConstantValue constantValueOpt,
TypeSymbol rewrittenType)
{
// NOTE: This optimization assumes that a constant has no side effects. In the future we
// might wish to represent nodes that are known to the optimizer as having constant
// values as a sequence of side effects and a constant value; in that case the result
// of this should be a sequence containing the side effect and the consequence or alternative.
ConstantValue conditionConstantValue = rewrittenCondition.ConstantValue;
if (conditionConstantValue == ConstantValue.True)
{
return rewrittenConsequence;
}
else if (conditionConstantValue == ConstantValue.False)
{
return rewrittenAlternative;
}
else
{
return new BoundConditionalOperator(
syntax,
rewrittenCondition,
rewrittenConsequence,
rewrittenAlternative,
constantValueOpt,
rewrittenType);
}
}
示例3: MakeLiteral
private BoundExpression MakeLiteral(CSharpSyntaxNode syntax, ConstantValue constantValue, TypeSymbol type, BoundLiteral oldNodeOpt = null)
{
Debug.Assert(constantValue != null);
if (constantValue.IsDecimal)
{
// Rewrite decimal literal
Debug.Assert((object)type != null);
Debug.Assert(type.SpecialType == SpecialType.System_Decimal);
return MakeDecimalLiteral(syntax, constantValue);
}
else if (constantValue.IsDateTime)
{
// C# does not support DateTime constants but VB does; we might have obtained a
// DateTime constant by calling a method with an optional parameter with a DateTime
// for its default value.
Debug.Assert((object)type != null);
Debug.Assert(type.SpecialType == SpecialType.System_DateTime);
return MakeDateTimeLiteral(syntax, constantValue);
}
else if (oldNodeOpt != null)
{
return oldNodeOpt.Update(constantValue, type);
}
else
{
return new BoundLiteral(syntax, constantValue, type, hasErrors: constantValue.IsBad);
}
}
示例4: ResetPoint
internal ResetPoint(int resetCount, LexerMode mode, int position, CSharpSyntaxNode prevTokenTrailingTrivia)
{
this.ResetCount = resetCount;
this.Mode = mode;
this.Position = position;
this.PrevTokenTrailingTrivia = prevTokenTrailingTrivia;
}
示例5: ReportDiagnostic
private static void ReportDiagnostic(
SyntaxNodeAnalysisContext context,
CSharpSyntaxNode syntaxNode,
string propertyName)
{
context.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.GetConfigurationEntryKey, syntaxNode.GetLocation(), propertyName));
}
示例6: AppendImplicitReturn
// insert the implicit "return" statement at the end of the method body
// Normally, we wouldn't bother attaching syntax trees to compiler-generated nodes, but these
// ones are going to have sequence points.
internal static BoundBlock AppendImplicitReturn(BoundStatement node, MethodSymbol method = null, CSharpSyntaxNode syntax = null)
{
if (syntax == null)
{
syntax = node.Syntax;
}
BoundStatement ret =
(object)method != null && (object)method.IteratorElementType != null
? BoundYieldBreakStatement.Synthesized(syntax) as BoundStatement
: BoundReturnStatement.Synthesized(syntax, null);
if (syntax.Kind == SyntaxKind.Block)
{
var blockSyntax = (BlockSyntax)syntax;
ret = new BoundSequencePointWithSpan(
blockSyntax,
ret,
blockSyntax.CloseBraceToken.Span)
{ WasCompilerGenerated = true };
}
switch (node.Kind)
{
case BoundKind.Block:
var block = (BoundBlock)node;
return block.Update(block.LocalsOpt, block.Statements.Add(ret));
default:
return new BoundBlock(syntax, ImmutableArray<LocalSymbol>.Empty, ImmutableArray.Create(ret, node));
}
}
示例7: Add
/// <summary>
/// Adds diagnostics from useSiteDiagnostics into diagnostics and returns True if there were any errors.
/// </summary>
internal static bool Add(
this DiagnosticBag diagnostics,
CSharpSyntaxNode node,
HashSet<DiagnosticInfo> useSiteDiagnostics)
{
return !useSiteDiagnostics.IsNullOrEmpty() && diagnostics.Add(node.Location, useSiteDiagnostics);
}
示例8: MakePropertyGetAccess
private BoundExpression MakePropertyGetAccess(
CSharpSyntaxNode syntax,
BoundExpression rewrittenReceiver,
PropertySymbol property,
ImmutableArray<BoundExpression> rewrittenArguments,
MethodSymbol getMethodOpt = null,
BoundPropertyAccess oldNodeOpt = null)
{
if (_inExpressionLambda && rewrittenArguments.IsEmpty)
{
return oldNodeOpt != null ?
oldNodeOpt.Update(rewrittenReceiver, property, LookupResultKind.Viable, property.Type) :
new BoundPropertyAccess(syntax, rewrittenReceiver, property, LookupResultKind.Viable, property.Type);
}
else
{
var getMethod = getMethodOpt ?? property.GetOwnOrInheritedGetMethod();
Debug.Assert((object)getMethod != null);
Debug.Assert(getMethod.ParameterCount == rewrittenArguments.Length);
Debug.Assert(((object)getMethodOpt == null) || ReferenceEquals(getMethod, getMethodOpt));
return BoundCall.Synthesized(
syntax,
rewrittenReceiver,
getMethod,
rewrittenArguments);
}
}
示例9: VisitNodeToBind
private void VisitNodeToBind(CSharpSyntaxNode node)
{
var previousNodeToBind = _nodeToBind;
_nodeToBind = node;
Visit(node);
_nodeToBind = previousNodeToBind;
}
示例10: ExecutableCodeBinder
internal ExecutableCodeBinder(CSharpSyntaxNode root, Symbol memberSymbol, Binder next, BinderFlags additionalFlags)
: base(next, (next.Flags | additionalFlags) & ~BinderFlags.AllClearedAtExecutableCodeBoundary)
{
this.memberSymbol = memberSymbol;
this.root = root;
this.owner = memberSymbol as MethodSymbol;
}
示例11: MethodASTWalker
/// <summary>
/// Initializes a new instance of the <see cref="MethodASTWalker"/> class.
/// </summary>
protected MethodASTWalker(CSharpSyntaxNode node)
{
var methodDeclarationSyntaxNode = node as MethodDeclarationSyntax;
if (methodDeclarationSyntaxNode == null)
{
throw new ArgumentException(
string.Format("Specified node is not of type {0}",
typeof(MethodDeclarationSyntax).Name));
}
this.node = node;
MethodDeclaration methodHelper = new MethodDeclaration(methodDeclarationSyntaxNode);
this.methodDeclaration = MethodDeclarationTranslationUnit.Create(
methodHelper.Visibility,
IdentifierTranslationUnit.Create(methodHelper.ReturnType),
IdentifierTranslationUnit.Create(methodHelper.Name));
foreach (TypedIdentifier parameter in methodHelper.Parameters)
{
this.methodDeclaration.AddArgument(ArgumentDefinitionTranslationUnit.Create(
IdentifierTranslationUnit.Create(parameter.TypeName),
IdentifierTranslationUnit.Create(parameter.IdentifierName)));
}
}
示例12: TryGet
public static bool TryGet(CSharpSyntaxNode node, SemanticModel semanticModel, out IControlFlowGraph cfg)
{
cfg = null;
try
{
if (node != null)
{
cfg = Create(node, semanticModel);
}
else
{
return false;
}
}
catch (Exception exc) when (exc is InvalidOperationException ||
exc is ArgumentException ||
exc is NotSupportedException)
{
// These are expected
}
catch (Exception exc) when (exc is NotImplementedException)
{
Debug.Fail(exc.ToString());
}
return cfg != null;
}
示例13: GetActions
private static IEnumerable<CodeAction> GetActions(Document document, SyntaxNode root, SyntaxNode node, CSharpSyntaxNode nullableType, CSharpSyntaxNode objectType)
{
var returnType = (CSharpSyntaxNode)nullableType ?? objectType;
if (returnType == null)
yield break;
var bodyStatement = node.ChildNodes().OfType<BlockSyntax>().FirstOrDefault();
if (bodyStatement == null)
yield break;
if (HasReturnContract(bodyStatement, returnType.ToString()))
yield break;
yield return CreateAction(
node.Span
,t2 => {
var newBody = bodyStatement.WithStatements(SyntaxFactory.List<StatementSyntax>(new[] { CreateContractEnsuresCall(returnType.ToString()) }.Concat(bodyStatement.Statements)));
var newRoot = (CompilationUnitSyntax)root.ReplaceNode((SyntaxNode)bodyStatement, newBody);
if (UsingStatementNotPresent(newRoot)) newRoot = AddUsingStatement(node, newRoot);
return Task.FromResult(document.WithSyntaxRoot(newRoot));
}
,"Add a Contract to specify the return value must not be null"
);
}
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:27,代码来源:ContractEnsuresNotNullReturnRefactoringProvider.cs
示例14: PlaceholderLocalBinder
internal PlaceholderLocalBinder(
CSharpSyntaxNode syntax,
ImmutableArray<Alias> aliases,
MethodSymbol containingMethod,
EETypeNameDecoder typeNameDecoder,
Binder next) :
base(next)
{
_syntax = syntax;
_containingMethod = containingMethod;
var compilation = next.Compilation;
var sourceAssembly = compilation.SourceAssembly;
var aliasesBuilder = ArrayBuilder<LocalSymbol>.GetInstance(aliases.Length);
var lowercaseBuilder = ImmutableDictionary.CreateBuilder<string, LocalSymbol>();
foreach (Alias alias in aliases)
{
var local = PlaceholderLocalSymbol.Create(
typeNameDecoder,
containingMethod,
sourceAssembly,
alias);
aliasesBuilder.Add(local);
if (alias.Kind == DkmClrAliasKind.ReturnValue)
{
lowercaseBuilder.Add(local.Name.ToLower(), local);
}
}
_lowercaseReturnValueAliases = lowercaseBuilder.ToImmutableDictionary();
_aliases = aliasesBuilder.ToImmutableAndFree();
}
示例15: RewriteLocalInternal
private static BoundExpression RewriteLocalInternal(CSharpCompilation compilation, EENamedTypeSymbol container, CSharpSyntaxNode syntax, LocalSymbol local)
{
var parameterType = compilation.GetSpecialType(SpecialType.System_String);
var getValueMethod = container.GetOrAddSynthesizedMethod(
ExpressionCompilerConstants.GetVariableValueMethodName,
(c, n, s) =>
{
var returnType = compilation.GetSpecialType(SpecialType.System_Object);
return new PlaceholderMethodSymbol(
c,
s,
n,
returnType,
m => ImmutableArray.Create<ParameterSymbol>(new SynthesizedParameterSymbol(m, parameterType, ordinal: 0, refKind: RefKind.None)));
});
var getAddressMethod = container.GetOrAddSynthesizedMethod(
ExpressionCompilerConstants.GetVariableAddressMethodName,
(c, n, s) =>
{
return new PlaceholderMethodSymbol(
c,
s,
n,
m => ImmutableArray.Create<TypeParameterSymbol>(new SimpleTypeParameterSymbol(m, 0, "<>T")),
m => m.TypeParameters[0], // return type is <>T&
m => ImmutableArray.Create<ParameterSymbol>(new SynthesizedParameterSymbol(m, parameterType, ordinal: 0, refKind: RefKind.None)),
returnValueIsByRef: true);
});
return new BoundPseudoVariable(
syntax,
local,
new ObjectIdExpressions(compilation, getValueMethod, getAddressMethod),
local.Type);
}