本文整理汇总了C#中UsingStatementSyntax类的典型用法代码示例。如果您正苦于以下问题:C# UsingStatementSyntax类的具体用法?C# UsingStatementSyntax怎么用?C# UsingStatementSyntax使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UsingStatementSyntax类属于命名空间,在下文中一共展示了UsingStatementSyntax类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddSequencePoint
internal static BoundStatement AddSequencePoint(UsingStatementSyntax usingSyntax, BoundStatement rewrittenStatement)
{
int start = usingSyntax.Span.Start;
int end = usingSyntax.CloseParenToken.Span.End;
TextSpan span = TextSpan.FromBounds(start, end);
return new BoundSequencePointWithSpan(usingSyntax, rewrittenStatement, span);
}
示例2: Start
public LockChecks Start(SyntaxNodeAnalysisContext AnalysisContext,DiagnosticDescriptor rule)
{
this.analysisContext = AnalysisContext;
this.usingStatement = (UsingStatementSyntax)analysisContext.Node;
this.rule = rule;
reportedIssue = false;
return this;
}
示例3: VisitUsingStatement
public sealed override void VisitUsingStatement(UsingStatementSyntax node)
{
if (node.Expression != null)
{
_builder.Add(node);
}
base.VisitUsingStatement(node);
}
示例4: UsingStatementTranslation
public UsingStatementTranslation(UsingStatementSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
{
Declaration = syntax.Declaration.Get<VariableDeclarationTranslation>(this);
Expression = syntax.Expression.Get<ExpressionTranslation>(this);
Statement = syntax.Statement.Get<StatementTranslation>(this);
//if(Expression != null)
//{
// throw new Exception("only support Declaration");
//}
}
示例5: VisitUsingStatement
public override void VisitUsingStatement(UsingStatementSyntax node)
{
var tokens = new List<SyntaxToken>();
if (node.Declaration != null)
{
tokens.AddRange(node.Declaration.Variables.Select(v => v.Identifier));
}
tracker.AddIdentifiers(tokens);
Visit(node.Statement);
tracker.RemoveIdentifiers(tokens);
}
示例6: UsingStatement
public static string UsingStatement(UsingStatementSyntax statement)
{
var output = SyntaxNode(statement.Declaration) + ";" + NewLine;
output += Block((BlockSyntax)statement.Statement, false);
//Swift calls deinit when you make a variable nil
output += string.Join("",
statement.Declaration.Variables.Select(variable => variable.Identifier.Text + " = nil;" + NewLine));
return output;
}
示例7: Go
public static void Go(OutputWriter writer, UsingStatementSyntax usingStatement)
{
var expression = usingStatement.Expression;
writer.WriteLine("//using block ... " + usingStatement.Declaration);
writer.OpenBrace();
//Ensure the using statement is a local variable - we can't deal with things we can't reliably repeat in the finally block
var resource = Utility.TryGetIdentifier(expression);
// if (resource == null)
// throw new Exception("Using statements must reference a local variable. " + Utility.Descriptor(usingStatement));
var variables = new SeparatedSyntaxList<VariableDeclaratorSyntax>();//.Select(o => o.Identifier.ValueText);
if (usingStatement.Declaration != null)
{
Core.Write(writer, usingStatement.Declaration);
variables = usingStatement.Declaration.Variables;
}
writer.WriteLine("try");
Core.WriteStatementAsBlock(writer, usingStatement.Statement);
writer.WriteLine("finally");
writer.OpenBrace();
foreach (var variable in variables)
{
var typeInfo = TypeProcessor.GetTypeInfo(usingStatement.Declaration.Type);
if (!typeInfo.Type.IsValueType)
writer.WriteLine("if(" + variable.Identifier.Text + " !is null)");
else if (typeInfo.Type.Name == "Nullable")
writer.WriteLine("if(" + variable.Identifier.Text + ".HasValue)");
writer.WriteLine(variable.Identifier.Text + ".Dispose(cast(IDisposable)null);");
}
if (resource != null)
{
writer.WriteLine("if(" + resource + " !is null)");
writer.WriteLine(resource + ".Dispose(cast(IDisposable)null);");
}
writer.CloseBrace();
writer.CloseBrace();
}
示例8: HandleUsingStatement
static CodeAction HandleUsingStatement(Document document, Microsoft.CodeAnalysis.Text.TextSpan span, SyntaxNode root, UsingStatementSyntax usingStatement, VariableDeclaratorSyntax variable)
{
return CodeActionFactory.Create(
span,
DiagnosticSeverity.Info,
"Iterate via 'foreach'",
ct =>
{
ForEachStatementSyntax foreachStmt = BuildForeach(SyntaxFactory.IdentifierName(variable.Identifier));
var innerBlock = usingStatement.Statement.EnsureBlock();
var newBlock = innerBlock.WithStatements(innerBlock.Statements.Insert(0, foreachStmt)).WithAdditionalAnnotations(Formatter.Annotation);
var newUsing = usingStatement.WithStatement(newBlock);
var newRoot = root.ReplaceNode(usingStatement, newUsing.WithTrailingTrivia(usingStatement.GetTrailingTrivia()));
return Task.FromResult(document.WithSyntaxRoot(newRoot));
}
);
}
示例9: Initialize
public override void Initialize(AnalysisContext context)
{
context.RegisterSyntaxNodeActionInNonGenerated(
(System.Action<SyntaxNodeAnalysisContext>) ( c =>
{
reportedIssue = false;
analysisContext = (SyntaxNodeAnalysisContext)c;
usingStatement = (UsingStatementSyntax)c.Node;
var lockChecks = new LockChecks();
lockChecks.Start(c, Rule);
if (!lockChecks.isLock())
{
return;
}
SyntaxNode block = lockChecks.GetUsingBlock(ref c);
lockChecks.LockCheckinSimpleMemberAccess(block);
/* IfStatementSyntax firstIfStatement = lockChecks.GetFirstIfStatementInUsingBlock(block);
lockChecks.CheckExpressionIsNotLockApplied(firstIfStatement);
SyntaxNode ifAppliedNode = lockChecks.CheckIfStatementNotEmpty(firstIfStatement);
lockChecks.CheckReturnOrThrow( ifAppliedNode);
if (!"false".Equals((string)((ReturnStatementSyntax)returnStatement).Expression.ToString()))
{
var diagnostic = Diagnostic.Create(Rule, returnStatement.GetLocation(), "does not return literal false");
c.ReportDiagnostic(diagnostic);
return;
}
*/
}),
SyntaxKind.UsingStatement
);
}
示例10: VisitUsingStatement
public override SyntaxNode VisitUsingStatement(UsingStatementSyntax node)
{
this.AppendCompileIssue(node, IssueType.Error, IssueId.UsingNotSupport);
return node;
}
示例11: UsingStatementBinder
public UsingStatementBinder(Binder enclosing, UsingStatementSyntax syntax)
: base(enclosing)
{
_syntax = syntax;
}
示例12: HandleUsingStatement
/// <summary>
/// Handles the given using statement.
/// </summary>
/// <param name="stmt">Statement</param>
/// <param name="successor">Successor</param>
private void HandleUsingStatement(UsingStatementSyntax stmt, ControlFlowGraphNode successor)
{
this.SyntaxNodes.Add(stmt.Declaration);
this.IsJumpNode = true;
var usingNode = new ControlFlowGraphNode(this.Summary);
this.ISuccessors.Add(usingNode);
usingNode.IPredecessors.Add(this);
if (stmt.Statement is BlockSyntax)
{
usingNode.Construct((stmt.Statement as BlockSyntax).Statements, 0, false, successor);
}
else
{
usingNode.Construct(new SyntaxList<StatementSyntax> { stmt.Statement }, 0, false, successor);
}
}
示例13: InferTypeInUsingStatement
private IEnumerable<ITypeSymbol> InferTypeInUsingStatement(UsingStatementSyntax usingStatement, SyntaxToken? previousToken = null)
{
// If we have a position, it has to be after "using("
if (previousToken.HasValue && previousToken.Value != usingStatement.OpenParenToken)
{
return SpecializedCollections.EmptyEnumerable<ITypeSymbol>();
}
return SpecializedCollections.SingletonEnumerable(this.Compilation.GetSpecialType(SpecialType.System_IDisposable));
}
示例14: VisitUsingStatement
public void VisitUsingStatement(UsingStatementSyntax node)
{
if (node == null)
throw new ArgumentNullException("node");
node.Validate();
WriteLeadingTrivia(node);
_writer.WriteIndent();
_writer.WriteKeyword(PrinterKeyword.Using);
if (_writer.Configuration.Spaces.BeforeParentheses.UsingParentheses)
_writer.WriteSpace();
_writer.WriteSyntax(Syntax.OpenParen);
if (_writer.Configuration.Spaces.WithinParentheses.UsingParentheses)
_writer.WriteSpace();
if (node.Expression != null)
node.Expression.Accept(this);
if (node.Declaration != null)
node.Declaration.Accept(this);
if (_writer.Configuration.Spaces.WithinParentheses.UsingParentheses)
_writer.WriteSpace();
_writer.WriteSyntax(Syntax.CloseParen);
if (
_writer.Configuration.Other.Other.IndentNestedUsingStatements &&
node.Statement is UsingStatementSyntax
) {
_writer.WriteLine();
node.Statement.Accept(this);
}
else
{
VisitBlockStatement(node.Statement);
}
WriteTrailingTrivia(node);
}
示例15: UsingStatementBinder
public UsingStatementBinder(MethodSymbol owner, Binder enclosing, UsingStatementSyntax syntax)
: base(owner, enclosing)
{
this.syntax = syntax;
this.expressionHandler = syntax.Expression == null ? null : new LockOrUsingStatementExpressionHandler(syntax.Expression, this);
}